Kubernetes Podspec for Privileged Container and volume mounts of /mnt and /dev of container

Viewed 32

I am able to run following plain docker command and volumes are created and mapped.This is privileged container.

docker run -d --network host --name test_container --volume test_volume:/mnt --privileged -v /dev:/dev $IMAGE_NAME

This container should be deployed as POD in kubernetes.

I tried creating podspec for this and its failing with below error :

Message: OCI runtime create failed: container_linux.go:344: starting container process caused "exec: "/mnt/somescript.sh": stat /mnt/somescript.sh: no such file or directory"

Below is the podspec snapshot:

spec:
  automountServiceAccountToken: false
  containers:
    image: test_container:latest
    imagePullPolicy: IfNotPresent
    name: test-container
    resources: {}
    securityContext:
      privileged: true
    volumeMounts:
    - mountPath: "/mnt"
      name: testvolume
    - mountPath: "/dev"
      name: devdata
  hostNetwork: true
  hostname: test
  imagePullSecrets:
  - name: acr-pull
  nodeName: xxxxxx
  restartPolicy: Always
  volumes:
  - hostPath:
      path: /mnt
      type: Directory
    name: testvolume
  - hostPath:
      path: /dev
      type: Directory
    name:  devdata

Also volumes not getting created for /mnt and /dev dir of containers.

1 Answers

If your directory not exist you can give it try with DirectoryOrCreate

volumes:
- hostPath:
    path: /mnt
    type: DirectoryOrCreate
  name: testvolume

if it's not present it will create the path.

if your file in not getting mounted you can also give it try with subpath

somescript.sh
Related