一、PersistentVolume (PV):简短一点就是管理员创建的一种存储资源
二、PersistentVolumeClaim (PVC):就一种声明,说我要使用pv了。
三、PV和PVC的配置
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: local-storage provisioner: kubernetes.io/no-provisioner volumeBindingMode: WaitForFirstConsumer
apiVersion: v1 kind: PersistentVolume metadata: name: xbd-mysql-pv spec: capacity: storage: 2Gi volumeMode: Filesystem accessModes: - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: local-storage local: path: /var/lib/mysql nodeAffinity: required: nodeSelectorTerms: - matchExpressions: - key: kubernetes.io/hostname operator: In values: - node2
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: xbd-mysql-pvc spec: accessModes: ["ReadWriteOnce"] storageClassName: "local-storage" resources: requests: storage: 2Gi
四、实际中的使用,比如mysql
apiVersion: apps/v1 kind: StatefulSet metadata: name: xbd-mysql spec: serviceName: xbd-mysql replicas: 1 selector: matchLabels: app: xbd-mysql template: metadata: labels: app: xbd-mysql spec: containers: - name: xbd-mysql image: registry.cn-chengdu.aliyuncs.com/xbd/xbd-mysql:1.0 imagePullPolicy: IfNotPresent args: - --lower_case_table_names=1 - --character-set-server=utf8 - --collation-server=utf8_general_ci env: - name: MYSQL_ROOT_PASSWORD value: root volumeMounts: - mountPath: /var/lib/mysql name: xbd-mysql-storage imagePullSecrets: - name: aliyun-secret volumes: - name: xbd-mysql-storage persistentVolumeClaim: claimName: xbd-mysql-pvc
apiVersion: v1 kind: Service metadata: name: xbd-mysql spec: clusterIP: None ports: - port: 3306 protocol: TCP targetPort: 3306 selector: app: xbd-mysql type: ClusterIP
标签:kind,pv,name,storage,pvc,mysql,xbd,k8s,metadata From: https://www.cnblogs.com/ll409546297/p/16735235.html