This section shows how to provide persistent storage for a MySQL database in the following steps:
Create PV and PVC.
Deploy MySQL.
Add data to MySQL.
Simulating node downtime, Kubernetes automatically migrates MySQL to other nodes.
Verify data consistency.
First create the PV and PVC, configured as follows:
Mysql-pv.yml
Mysql-pvc.yml
create MYSQL-PV
and mysql-pvc
:
Next, deploy MySQL with the following configuration files:
PVCmysql-pvc
Bound's PVmysql-pv
The data directory that will be mount to MySQLvar/lib/mysql
.
mysql is deployed to Code style= "Box-sizing:inherit; Font-family:consolas, "liberation Mono", Courier, monospace; font-size:16.32px; Padding:0.2rem; Border:none; Background-color:rgb (244, 244, 244); Font-weight:inherit; border-radius:3px; Overflow:scroll; " >k8s-node2 mysql
:
Kubectl run-it--rm--image=mysql:5.6--restart=never mysql-client--Mysql-h Mysql-ppassword
Update Database:
① switch to MySQL database.
② CREATE database table my_id.
③ inserts a piece of data.
④ confirms that the data has been written.
close k8s-node2
k8s-node1
Verify the consistency of the data:
The MySQL service is restored and the data is intact.
Summary
In this chapter we discuss how Kubernetes manages storage resources.
The Emptydir and Hostpath types of Volume are convenient, but are not durable and Kubernetes support a variety of external storage systems Volume.
PV and PVC separate the responsibilities of administrators and ordinary users, making them more suitable for production environments. We also learned how to achieve more efficient dynamic supply through storageclass.
Finally, we demonstrated how to use Persistentvolume in MySQL to achieve data persistence.
Books:
1. 5 minutes a day kubernetes "
https://item.jd.com/26225745440.html
2.5 minutes a day to play Docker container technology
https:// item.jd.com/16936307278.html
3.5 minutes of play with OpenStack per day
Https://item.jd.com/12086376.html
How does MySQL use PV and PVC? -5 minutes a day to play Docker container technology (154)