How to unmount partition in kubernetes

4/17/2019

I have one pod and one partion in it

kubectl exec pod-t -- lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0 298.1G  0 disk 
`-sda10   8:10        28G  0 part /etc/hosts
sr0      11:0    1  1024M  0 rom  
rbd5    252:80   0    15G  0 disk /usr/share/nginx/html

When i want umount it i see

must be superuser to unmount

#kubectl exec pod-t -- umount /dev/rbd5
umount: /usr/share/nginx/html: must be superuser to unmount
command terminated with exit code 32

The pod was created by this template:

apiVersion: v1
kind: Pod
metadata:
  name: pod-t
  namespace: default
  labels:
spec:
  containers:
  - name: nginxqw
    image: nginx:latest
    ports:
    - containerPort: 80
    volumeMounts:
    - name: content-data
      mountPath: /usr/share/nginx/html
  volumes:
  - name: content-data
    persistentVolumeClaim:
     claimName: pvc-t

I think the pod does not have root priviledge. How can i solve it?

-- yasin lachini
kubernetes

1 Answer

4/17/2019

There is a privileged flag on the SecurityContext of the container spec.

I use this template

apiVersion: v1
kind: Pod
metadata:
  name: hello-world
spec:
  containers:
    - name: hello-world-container
      # The container definition
      # ...
      securityContext:
        privileged: true 
-- yasin lachini
Source: StackOverflow