How does MySQL use PV and PVC? -5 minutes a day to play Docker container technology (154)

Source: Internet
Author: User
Tags k8s

This section shows how to provide persistent storage for a MySQL database in the following steps:

  1. Create PV and PVC.

  2. Deploy MySQL.

  3. Add data to MySQL.

  4. Simulating node downtime, Kubernetes automatically migrates MySQL to other nodes.

  5. 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-pvcBound's PVmysql-pvThe 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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.