k8s之mysql(pv,pvc)
一、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 labels: app: 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 # nfs 存储 # storageClassName: nfs # nfs: # path: /nfsdata/mysql # server: 192.168.5.200
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: xbd-mysql-pvc spec: accessModes: ["ReadWriteOnce"] storageClassName: "local-storage" resources: requests: storage: 2Gi selector: matchLabels: app: xbd-mysql-pv
四、实际中的使用,比如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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架