Search code examples
dockerkubernetesrancheroctoprint

How do bind/map a device to Rancher?


When I run the command on my SBC:

docker run --volume $(pwd):/home/octoprint --device /dev/ttyUSB0:/dev/ttyACM0 -p 5000:5000 --name octoprint octoprint/octoprint:1.4.0-python3

Everything works normally; I can open the octoprint screen and my 3D printer is recognized without any problems.

However, when I try to run the equivalent --device /dev/ttyUSB0:/dev/ttyACM0 to be mapped as any type of volume as possible, I am unable to make an equivalent configuration.

Please, how do I get Rancher to recognize a --device?


Solution

  • Assuming you are talking about Kubernetes Rancher. The common way is to use privileged in the SecurityContext of your Pod or Container.

    For example:

      containers:
      - name: sbc
        securityContext:
          privileged: true
        volumeMounts:
        - mountPath: /dev/ttyUSB0
          name: ttyacm
      volumes:
      - name: ttyacm
        hostPath:
          path: /dev/ttyACM0
    

    A more advanced way of supporting host devices is Device Plugins. But I believe of standard USB the above should work. You might also want to use NodeAffinity to make sure that your Pod lands where your device is.

    ✌️