Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use --device /dev/video0 with kubernetes?

I have a docker container used to convert the flux of my webcam into rtsp (docker image: ullaakut/rtspatt). It work well when I use --device /dev/video0:/dev/video0.

But I did not found anything helping me to do the same using Kubernetes. I just want a way to access the webcam from the container... Anyone can help me ?

like image 789
Borhink Avatar asked Dec 11 '19 17:12

Borhink


1 Answers

Currently there is no configuration option which would enable to use --device in Kubernetes.

See these discussions for more details: https://github.com/kubernetes/kubernetes/issues/5607 https://github.com/kubernetes/kubernetes/issues/60748

However, you might be able to use host devices if you enable the privileged mode for the pod.

https://kubernetes.io/docs/concepts/policy/pod-security-policy/#privileged

This allows the container nearly all the same access as processes running on the host. This is useful for containers that want to use linux capabilities like manipulating the network stack and accessing devices.

containers:
- name: foo
  volumeMounts:
  - mountPath: /dev/video0
    name: dev-video0
  securityContext:
    privileged: true
volumes:
- name: dev-video0
  hostPath:
    path: /dev/video0

Not sure though if you really need the volumeMounts and volumes. Just try and see if it works without them.

Using privileged: true is not really ideal from a security point of view.

You should also set the nodeName property on the pod, so it'll always run on one specific node (this node will have the camera attached).


An alternative solution might be to use plugins: https://github.com/bluebeach/k8s-hostdev-plugin.

like image 159
Dávid Molnár Avatar answered Sep 22 '22 00:09

Dávid Molnár