K8s mysql NFS 持久化
跳到导航
跳到搜索
k8s mysql5.7 NFS 持久化
=NFS
root@debian11:~# mkdir -p /data/k8s/mysql57 root@debian11:~# chmod -R 0777 /data/k8s/mysql57 root@debian11:~# ls /data/k8s/mysql57
k8s yaml
root@k8s-master:~/mysql5.7# ls pvc.yaml pv.yaml svc.yaml cat pv.yaml apiVersion: v1 kind: PersistentVolume metadata: name: mysql57-pv-evan spec: accessModes: - ReadWriteOnce #指定访问模式 capacity: storage: 1Gi #存储容量 1G persistentVolumeReclaimPolicy: Retain #回收策略 Retain 管理员手工回收 Recycle #清除 PV 的数据 Delete 删除Storage Provider上的对应存储资源 storageClassName: nfs #指定PV 的class为nfs nfs: path: /data/k8s/mysql57 #PV在 NFS服务器上对应的目录 server: 192.168.88.122 cat pvc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mysql57-pvc-evan spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: nfs cat svc.yaml kind: PersistentVolumeClaim apiVersion: v1 metadata: name: mysql-pvc-evan spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: nfs apiVersion: v1 kind: Service metadata: name: mysql spec: type: NodePort ports: - protocol: TCP nodePort: 30306 port: 3306 targetPort: 3306 selector: app: mysql --- apiVersion: apps/v1 kind: Deployment metadata: name: mysql spec: selector: matchLabels: app: mysql template: metadata: labels: app: mysql spec: containers: - image: mysql:5.7 name: mysql env: - name: MYSQL_ROOT_PASSWORD value: password ports: - containerPort: 3306 name: mysql volumeMounts: - name: mysql-persistent-storage mountPath: /var/lib/mysql #挂载目录 volumes: - name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql57-pvc-evan 依次执行 kubectl apply -f pv.yaml kubectl get pv kubectl apply -f pvc.yaml kubectl get pv,pvc kubectl apply -f svc.yaml kubectl get pod kubectl exec -it mysql-58ddb8d7f6-bhps5 bash root@k8s-master:~/mysql5.7# kubectl get pv,pvc NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE persistentvolume/mysql-nfs-pv 2Gi RWO Retain Terminating default/mysql-nfs-pvc nfs 2d1h persistentvolume/mysql-nfs-pv1 3Gi RWO Retain Bound default/mysql-nfs-pvc1 nfs 33h persistentvolume/mysql-pv 4Gi RWX Retain Bound default/mysql-claim nfs 36h persistentvolume/mysql57-pv-evan 1Gi RWO Retain Bound default/mysql57-pvc-evan nfs 18s persistentvolume/web-pv 2Gi RWX Retain Bound default/web-claim nfs 35h NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE persistentvolumeclaim/mysql-claim Bound mysql-pv 4Gi RWX nfs 36h persistentvolumeclaim/mysql-nfs-pvc Terminating mysql-nfs-pv 2Gi RWO nfs 2d1h persistentvolumeclaim/mysql-nfs-pvc1 Bound mysql-nfs-pv1 3Gi RWO nfs 33h persistentvolumeclaim/mysql57-pvc-evan Bound mysql57-pv-evan 1Gi RWO nfs 6s persistentvolumeclaim/web-claim Bound web-pv 2Gi RWX nfs 35h root@k8s-master:~/mysql5.7# node1ip 192.168.88.51 root@k8s-master:~/mysql5.7# kubectl get svc NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE mysql NodePort 10.96.61.100 <none> 3306:30306/TCP 2d1h mysql -uroot -h192.168.88.51 -P30306 -p 或者 kubectl exec -it mysql-58ddb8d7f6-bhps5 bash mysql -uroot -ppassword create database evanmysq57; 回来 nfs 看一下 root@debian11:~# ls /data/k8s/mysql57/evanmysq57/ db.opt
5.6
和上次一样改了下 pv pvc image 名就行了