问题
there,
According to the doc:
ReadWriteOnce – the volume can be mounted as read-write by a single node
I created a PV based on nfs:
apiVersion: v1
kind: PersistentVolume
metadata:
name: tspv01
spec:
capacity:
storage: 15Gi
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Recycle
nfs:
path: /gpfs/fs01/shared/prod/democluster01/dashdb/gamestop/spv01
server: 169.55.11.79
a PVC for this PV:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: sclaim
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 15Gi
After create the PVC bind to the PV:
root@hydra-cdsdev-dal09-0001:~/testscript# kubectl get pvc
NAME STATUS VOLUME CAPACITY ACCESSMODES AGE
sclaim Bound tspv01 15Gi RWO 4m
Then I created 2 PODs using the same PVC:
POD1:
kind: Pod
apiVersion: v1
metadata:
name: mypodshared1
labels:
name: frontendhttp
spec:
containers:
- name: myfrontend
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: sclaim
POD2:
kind: Pod
apiVersion: v1
metadata:
name: mypodshared2
labels:
name: frontendhttp
spec:
containers:
- name: myfrontend
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: mypd
volumes:
- name: mypd
persistentVolumeClaim:
claimName: sclaim
After I create the 2 PODs, they are assigned to 2 different nodes. And I can exec into the container, and can read&write in the nfs mounted folder.
root@hydra-cdsdev-dal09-0001:~/testscript# kubectl get pod -o wide
NAME READY STATUS RESTARTS AGE IP NODE
mypodshared1 1/1 Running 0 18s 172.17.52.7 169.45.189.108
mypodshared2 1/1 Running 0 36s 172.17.83.9 169.45.189.116
Anybody know why this happened?
回答1:
The accessModes are dependent upon the storage provider. For NFS they don't really do anything different, but a HostPath should use the modes correctly.
See the following table for all the various options: http://kubernetes.io/docs/user-guide/persistent-volumes/#access-modes
来源:https://stackoverflow.com/questions/40524103/kubernetes-persistent-volume-readwriteonlyrwo-does-not-work-for-nfs