Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use PV and PVC

Shulou Source: shulou.com Published: 2022-06-01 03:51:02 10月17日 Update

This article is to share with you about how to use PV and PVC. The editor thinks it is very practical, so I share it with you. I hope you can get something after reading this article.

Here is a demonstration of how to provide persistent storage for a MySQL database by:

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 PV and PVC with the following configuration:

Mysql-pv.yml

Mysql-pvc.yml

Next, deploy MySQL with the following configuration file:

MySQL is deployed to k8s-node2, and the client accesses Service mysql as follows:

Kubectl run-it-rm-image=mysql:5.6-restart=Never mysql-client-mysql- h mysql- ppassword

Update the database:

① switches to database mysql.

② creates the database table my_id.

③ inserts a piece of data.

④ confirms that the data has been written.

Shut down k8s-node2 to simulate node downtime.

Verify the consistency of the data:

The MySQL service is restored and the data is intact.

We discussed how Kubernetes manages storage resources.

Volume of emptyDir and hostPath types is convenient, but not durable, and Kubernetes supports Volume for a variety of external storage systems.

PV and PVC separate the responsibilities of administrators and ordinary users and are more suitable for production environments. We also learned how to achieve more efficient dynamic provisioning through StorageClass.

Finally, we demonstrated how to use PersistentVolume to achieve data persistence in MySQL.

The above is how to use PV and PVC. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

Tags: Data database node storage consistency consistency persistence failure more knowledge articles learning demonstration management configuration verification intact practical ordinary next Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker OPPO Reno Shulou Technology Shulou Tech Info