kubernetes — PV和PVC详解
参考:
pod: https://www.cnblogs.com/along21/p/10342788.html
statefulset: https://blog.csdn.net/An1090239782/article/details/110927486
创建PV:
apiVersion: v1 kind: PersistentVolume metadata: name: pv001 labels: name: pv001 spec: nfs: path: /data/volumes/v1 server: 10.3.65.14 accessModes: ["ReadWriteMany","ReadWriteOnce"] capacity: storage: 2Gi --- apiVersion: v1 kind: PersistentVolume metadata: name: pv002 labels: name: pv002 spec: nfs: path: /data/volumes/v2 server: 10.3.65.14 accessModes: ["ReadWriteOnce"] capacity: storage: 5Gi --- apiVersion: v1 kind: PersistentVolume metadata: name: pv003 labels: name: pv003 spec: nfs: path: /data/volumes/v3 server: 10.3.65.14 accessModes: ["ReadWriteMany","ReadWriteOnce"] capacity: storage: 20Gi --- apiVersion: v1 kind: PersistentVolume metadata: name: pv004 labels: name: pv004 spec: nfs: path: /data/volumes/v4 server: 10.3.65.14 accessModes: ["ReadWriteMany","ReadWriteOnce"] capacity: storage: 10Gi --- apiVersion: v1 kind: PersistentVolume metadata: name: pv005 labels: name: pv005 spec: nfs: path: /data/volumes/v5 server: 10.3.65.14 accessModes: ["ReadWriteMany","ReadWriteOnce"] capacity: storage: 15Gi
创建PVC和pod进行绑定
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mypvc namespace: default spec: accessModes: ["ReadWriteMany"] resources: requests: storage: 6Gi --- apiVersion: v1 kind: Pod metadata: name: vol-pvc namespace: default spec: volumes: - name: html persistentVolumeClaim: claimName: mypvc containers: - name: myapp image: ikubernetes/myapp:v1 volumeMounts: - name: html mountPath: /usr/share/nginx/html/
kubectl get pv
kubectl get pvc
kubectl get pod -o wide
删除pod、pvc、pv
重新做StatefulSet 的
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs1 spec: capacity: storage: 1Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: nfs nfs: path: /data/nfs1 server: 10.3.65.14 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs2 spec: capacity: storage: 3Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: nfs nfs: path: /data/nfs2 server: 10.3.65.14 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs3 spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: slow nfs: path: /data/nfs3 server: 10.3.65.14 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs4 spec: capacity: storage: 10Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: nfs nfs: path: /data/nfs4 server: 10.3.65.14 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs5 spec: capacity: storage: 5Gi accessModes: - ReadWriteMany persistentVolumeReclaimPolicy: Recycle storageClassName: nfs nfs: path: /data/nfs5 server: 10.3.65.14 --- apiVersion: v1 kind: PersistentVolume metadata: name: pv-nfs6 spec: capacity: storage: 5Gi accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Recycle storageClassName: nfs nfs: path: /data/nfs6 server: 10.3.65.14
statefulset
apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - port: 80 name: web clusterIP: None selector: app: nginx --- apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx # has to match .spec.template.metadata.labels serviceName: "nginx" replicas: 3 # by default is 1 template: metadata: labels: app: nginx # has to match .spec.selector.matchLabels spec: terminationGracePeriodSeconds: 100 containers: - name: nginx image: registry.cn-beijing.aliyuncs.com/google_registry/nginx:1.17 ports: - containerPort: 80 name: web volumeMounts: - name: www mountPath: /usr/share/nginx/html volumeClaimTemplates: - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] storageClassName: "nfs" resources: requests: storage: 3Gi
结果:
kubectl describe pod/web-1
查看web-1为何不行
nfs对应目录没有建,建好了就OK了
写个文件试试吧
可以的,有3个,当时一个阻塞了,没看到第三个,测试都OK。