we use Cloud Provider Storage to provide Volume to k8s
create PersistentVolume,PersistentVolumeClaim,Pod(to use PVC)
demo:
1.Create PV and PVC.
define the Volume path and kind in PersistentVolume
define the request of Volume (kind and size) in PersistVolumeClaim
2.Deploy MySQL.
define Service
define Deployment which includes mysql version,volumeMounts which local directory use Volume,volumes which calls PVC (The PVC mysql-pv of PVC mysql-pvc Bound will be mounted to the MySQL data directory var/lib/mysql.)
3.Add data to MySQL.
use mysql
create * table
insert *
select *
4.The simulated node crashes and Kubernetes automatically migrates
shutdown one node
5.MySQL to other nodes.
kubectl get pod -o wide shows that pod is migrated to another node
6.Verify data consistency.
use mysql
select * to check the data is consistent.
We demonstrated how to implement data persistence using PersistentVolume in MySQL.
PV and PVC separate the responsibilities of administrators and general users, making them more suitable for production environments.