Kubernetes pod: "Operation not permitted" while trying to access a mounted volume

843 views Asked by At

I am running Docker Desktop 4.10 on Windows 10, with K8s enabled. I have the following k8s resources deployed through a helm chart, using Helm 3.12:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: fab-rabbitmq
  labels:
    type: mydata
spec:
  capacity:
    storage: 2Gi
  accessModes:
    - ReadWriteOnce
  storageClassName: hostpath
  hostPath:
    path: /c/data
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pvc1
spec:
  accessModes:
    - ReadWriteOnce
  volumeMode: Filesystem
  resources:
    requests:
      storage: 2Gi
  storageClassName: hostpath
  selector:
    matchLabels:
      type: "mydata"
---
apiVersion: v1
kind: Pod
metadata:
  name: pod1
spec:
  containers:
    - name: myfrontend
      image: nginx
      volumeMounts:
      - mountPath: "/mydata"
        name: vol1
  volumes:
    - name: vol1
      persistentVolumeClaim:
        claimName: pvc1

After deploying the chart, the pod runs correctly, the PVC is bound to the PV. I also set Windows security permissions to Everyone-full control on C:\data.

However, when I access the pod and try to list the files in the folder, I get the following error:

kubectl exec -it pod1 bash
# ls -la mydata
ls: reading directory 'mydata': Operation not permitted

I can't seem to find a way to really have access to the mounted folder.

When I try to run a simple container using docker run -v /c/data:/mydata nginx and access /mydata, it works.

Any ideas what I am doing wrong?

1

There are 1 answers

0
Sagi Mann On

I found the explanation here and here. When running in Minikube, the "host path" is not actually the path on the physical host but rather a path inside the Minikube node. That's because Minikube IS actually the host of all pods (hence their node). So basically, the steps to do this correctly are:

  1. Ensure the physical path is mounted inside Minikube by running minimuke start --mount --mount-string=C:\myfolder:/folder/in/minikube
  2. When setting up the PV, specify: hostPath.path: /folder/in/minikube:/folder/in/pod