<p>Headless VirtualBox successfully runs inside Docker container</p>

<pre><code>docker run --device=/dev/vboxdrv:/dev/vboxdrv my-vb
</code></pre>

<p>I need to run this image on Kubernetes and I get:</p>

<pre><code>VBoxHeadless: Error -1909 in suplibOsInit!
VBoxHeadless: Kernel driver not accessible
</code></pre>

<p>Kubernetes object:</p>

<pre><code>metadata:
  name: vbox
  labels:
    app: vbox
spec:
  selector:
    matchLabels:
      app: vbox
  template:
    metadata:
      labels:
        app: vbox
    spec:
      securityContext:
        runAsUser: 0
      containers:
      - name: vbox-vm
        image: my-vb
        imagePullPolicy: 'Always'
        ports:
        - containerPort: 6666

        volumeMounts:
        - mountPath: /root/img.vdi
          name: img-vdi

        - mountPath: /dev/vboxdrv
          name: vboxdrv

      volumes:
      - name: img-vdi
        hostPath:
          path: /root/img.vdi
          type: File

      - name: vboxdrv
        hostPath:
          path: /dev/vboxdrv
          type: CharDevice
</code></pre>

<p>This image runs in Docker so must be the problem in Kubernetes configuration.</p>

<p>Slight modification is required in the configuration for this work:</p>

<pre><code>metadata:
  name: vbox
  labels:
    app: vbox
spec:
  selector:
    matchLabels:
      app: vbox
  template:
    metadata:
      labels:
        app: vbox
    spec:
      securityContext:
        runAsUser: 0
      containers:
      - name: vbox-vm
        image: my-vb
        imagePullPolicy: 'Always'
        securityContext:  # &lt;&lt; added
          privileged: true

        ports:
        - containerPort: 6666

        volumeMounts:
        - mountPath: /root/img.vdi
          name: img-vdi

        - mountPath: /dev/vboxdrv
          name: vboxdrv

      volumes:
      - name: img-vdi
        hostPath:
          path: /root/img.vdi
          type: File

      - name: vboxdrv
        hostPath:
          path: /dev/vboxdrv
          type: CharDevice
</code></pre>

<p>To be able to run privileged containers you'll need to have:</p>

<ul>
<li>kube-apiserver running with --allow-privileged</li>
<li>kubelet (all hosts that might have this container) running with --allow-privileged=true</li>
</ul>

<p>See more at <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod/#privileged-mode-for-pod-containers" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/pods/pod/#privileged-mode-for-pod-containers</a></p>

<p>Once it works do it properly via <a href="https://kubernetes.io/docs/concepts/policy/pod-security-policy/" rel="nofollow noreferrer">PodSecurityPolicy</a></p>
