k8s存储 pv pvc ,storageclass
1. pv pvc
现在测试 glusterfs nfs 可读可写, 多个pod绑定到同一个pvc上,可读可写。
2. storageclass 分成两种
(1) 建立pvc, 相当于多个pod绑定在一个pvc上。
pvc的yaml
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: managed-nfs-storage-pvc annotations: volume.beta.kubernetes.io/storage-class: managed-nfs-storage spec: accessModes: - ReadWriteOnce #必须写ReadWriteOnce,否则报错。 resources: requests: storage: 5Gi
deployment文件
apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nfs-pvc-test spec: replicas: 3 template: metadata: labels: app: nfs-pvc-test spec: containers: - name: nginx image: docker.cinyi.com:443/nginx:alpine ports: - containerPort: 80 volumeMounts: - name: www mountPath: /usr/share/nginx/html volumes: - name: www persistentVolumeClaim: claimName: managed-nfs-storage-pvc --- apiVersion: v1 kind: Service metadata: name: nfs-pvc-test labels: app: nfs-pvc-test spec: type: NodePort ports: - port: 80 selector: app: nfs-pvc-test
(2) 直接引用 storageclass
相当于每个pod都单独创建pvc,pv
新建statefulset
apiVersion: apps/v1beta1 kind: StatefulSet metadata: name: web spec: serviceName: "nginx1" replicas: 4 volumeClaimTemplates: - metadata: name: test annotations: volume.beta.kubernetes.io/storage-class: "managed-nfs-storage" #此处引用classname spec: accessModes: ["ReadWriteOnce"] resources: requests: storage: 2Gi template: metadata: labels: app: nginx1 spec: containers: - name: nginx1 image: docker.cinyi.com:443/senyint/nginx:v.10 volumeMounts: - mountPath: "/mnt" name: test
当使用ceph 块存储时, 使用storageclass pvc 时, deployment 副本数写成多个,会报错。