PersistentVolume marked as bound but invisible in containers

8/5/2018

I'm starting with GKE (and kubernetes in general) and I want to mount a persistent volume on a pod using a gcePersistentDisk.

I first created a Persistent Disk (project-data) in Compute Engine, then created a PersistentVolume and a PersistentVolumeClaim like so:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: project-data
spec:
  storageClassName: standard
  capacity:
    storage: 20G
  accessModes:
    - ReadWriteOnce
  gcePersistentDisk:
    pdName: project-data
    fsType: ext4
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: project-data-claim
spec:
  storageClassName: standard
  volumeName: project-data
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 20G
  selector:
    matchLabels:
      app: myapp

After applying this config, I see in GKE/Storage that my PVC is "Bound", but I can't find a way to access my volume in myapp.

I tried to edit the deployment yaml in the console by adding:

volumeMounts:
- mountPath: /data
  name: project-data

...but this modification is refused by the console (it seems that this kind of edit is forbidden).

How can I finally see my PersistentVolume as a filesystem in my app?

-- SuperPython
google-cloud-platform
google-kubernetes-engine
kubernetes
persistent-volume-claims
persistent-volumes

1 Answer

8/6/2018

First of all, PVC should be defined in the volumes section:

volumes:
- name: project-data
  persistentVolumeClaim: 
    claimName: project-data-claim

And if it's refuesed to edit the pod directly, you can edit the yaml file, then apply it:

$ kubectl apply -f your.yaml

Also, since you have the selector defined in your pvc configuration, I think you should have label defined in your pv configuration.

-- Kun Li
Source: StackOverflow