I applied the following configuration with
- one RWO PV
- one RWO PVC
- two pods both using the above PVC.
apiVersion: v1
kind: PersistentVolume
metadata:
name: vol1
labels:
type: local
spec:
storageClassName: manual
capacity:
storage: 10Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/mnt/data"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: claim1
spec:
storageClassName: manual
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Mi
---
apiVersion: v1
kind: Pod
metadata:
name: pod1
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: data
resources:
limits:
cpu: "1"
memory: "200Mi"
volumes:
- name: data
persistentVolumeClaim:
claimName: claim1
---
apiVersion: v1
kind: Pod
metadata:
name: pod2
spec:
containers:
- name: myfrontend
image: nginx
volumeMounts:
- mountPath: "/var/www/html"
name: data
resources:
limits:
cpu: "1"
memory: "200Mi"
volumes:
- name: data
persistentVolumeClaim:
claimName: claim1
The pods got scheduled onto two different nodes and, according to GitHub issues #103305 and #26567, I was expecting one of the two pods to fail (i.e. not reaching Running
state) because of the RWO
constraint.
However, both pods reached Running
state and I found that the pods were even able to write to the PVC
.
After having deleted all resources, I checked the two nodes and I found the data written by the pods. Actually, it seems that two different RWO PV were created and used.
Naturally, Kubernetes was showing just the PV and the PVC that were defined in the configuration.
How did Kubernetes managed this situation?
I've also tried not to define the PV
and let the cluster provision it. I made two experiments:
I defined the
PVC
andpod1
, applied the configuration, and then createdpod2
. The results didn't change: both pods were able to run and use thePVC
.I defined and applied
PVC
and both pods in one configuration. In this case, both pods (scheduled on different nodes) stuck atContainerCreating
while volume attachment was failing in loop.
Even though the second experiment outcome seems correct, I cannot find out why the first experiment went differently, since I just delayed the definition of pod2
.