VirtualBox里面的kubernetes容器

问题描述 投票:1回答:1

无头VirtualBox在Docker容器内成功运行

docker run --device=/dev/vboxdrv:/dev/vboxdrv my-vb

我需要在Kubernetes上运行此图像,我得到:

VBoxHeadless: Error -1909 in suplibOsInit!
VBoxHeadless: Kernel driver not accessible

Kubernetes对象:

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

此映像在Docker中运行,因此必须是Kubernetes配置中的问题。

kubernetes virtualbox
1个回答
3
投票

在此工作的配置中需要进行轻微修改:

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:  # << 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

为了能够运行特权容器,您需要:

  • 使用--allow-privileged运行的kube-apiserver
  • 使用--allow-privileged = true运行的kubelet(可能具有此容器的所有主机)

https://kubernetes.io/docs/concepts/workloads/pods/pod/#privileged-mode-for-pod-containers查看更多信息

一旦它的工作正常通过PodSecurityPolicy

© www.soinside.com 2019 - 2024. All rights reserved.