skip to Main Content

I want do some device initiation by using Daemonset(K8s resource).

Actually the deivce has been formated(inside container) and mounted(inside container) successfully to a container path /hostmnt/lvpmem/ which is mapped of /mnt/ which is a host path.

mountpoint works fine in container

[root@driver-hm4ll /]
#mountpoint /hostmnt/lvpmem/
/hostmnt/lvpmem/ is a mountpoint

but mountpoint works wrong in host env

[root@host ~]# mountpoint  /mnt/lvpmem/
/mnt/lvpmem/ is not a mountpoint

Also the data I write in container under /hostmnt/lvpmem/ can’t been seen under /mnt/lvpmem/ in host env.

How can I mount the device so that both host and container can see it ?
Also, if container is destroyed does the mount relation also be destroyed ? I have no idea about umounting the device in host env if mount relation can’t be seen.
Some opensource project use nsenter in container to run such format/mount command does it help ?

2

Answers


  1. Chosen as BEST ANSWER

    Mount point seen in container is just the snapshot when container start. My solution:

    1. Enable hostPID for pod and use nsenter to mount on host
    2. Restart container itself by using exit then the mount point can be seen in new container

    • add /mnt as a volume to pod on directory /hostmnt. So that whatever being written under /hostmnt directory (insisde the container) will be seen on host under directory /mnt .
    Example of a pod with hostpath :
    
    apiVersion: v1
    kind: Pod
    metadata:
      name: test-pd
    spec:
      containers:
      - image: k8s.gcr.io/test-webserver
        name: test-container
        volumeMounts:
        - mountPath: /hostmnt
          name: test-volume
      volumes:
      - name: test-volume
        hostPath:
          # directory location on host
          path: /mnt
          # this field is optional
          type: Directory
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search