Multiple Volume mounts with Kubernetes: one works, one doesn't
The Kubernetes documentation states:
Volumes can not mount onto other volumes or have hard links to other volumes
I had the same issue and in my case the problem was that both volume mounts had overlapping mountPaths, i.e. both started with /var/.
They mounted without issues after fixing that.
I do not see any direct problem for which such behavior as explained above has occurred! But what I can rather ask you to try is to use a "Deployment" instead of a "Pod" as suggested by many here, especially when using PVs and PVCs. Deployment takes care of many things to maintain the "Desired State". I have attached my code below for your reference which works and both the volumes are persistent even after deleting/terminating/restarting as this is managed by the Deployment's desired state.
Two difference which you would find in my code from yours are:
- I have a deployment object instead of pod
- I am using GlusterFs for my volume.
Deployment yml.
apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: nginx namespace: platform labels: component: nginxspec: replicas: 2 strategy: type: RollingUpdate rollingUpdate: maxSurge: 1 maxUnavailable: 1 template: metadata: labels: component: nginx spec: nodeSelector: role: app-1 containers: - name: nginx image: vip-intOAM:5001/nginx:1.15.3 imagePullPolicy: IfNotPresent volumeMounts: - mountPath: "/etc/nginx/conf.d/" name: nginx-confd - mountPath: "/var/www/" name: nginx-web-content volumes: - name: nginx-confd persistentVolumeClaim: claimName: glusterfsvol-nginx-confd-pvc - name: nginx-web-content persistentVolumeClaim: claimName: glusterfsvol-nginx-web-content-pvc
One of my PV
apiVersion: v1kind: PersistentVolumemetadata: name: glusterfsvol-nginx-confd-pvspec: capacity: storage: 1Gi accessModes: - ReadWriteOnce glusterfs: endpoints: gluster-cluster path: nginx-confd readOnly: false persistentVolumeReclaimPolicy: Retain claimRef: name: glusterfsvol-nginx-confd-pvc namespace: platform
PVC for the above
kind: PersistentVolumeClaimapiVersion: v1metadata: name: glusterfsvol-nginx-confd-pvc namespace: platformspec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi