In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. Planning
Let's proceed with the schema planning of the previous document to do the following.
IP role 192.168.1.200k8s-master192.168.1.201k8s-node01192.168.1.202k8s-node02192.168.1.203k8s-store
We demonstrate how to provide persistent storage for a MySQL database, which is divided into 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. 2. Deployment 1. Create PV and PVC
The configuration file mysql-pv.yaml of our PV is as follows:
ApiVersion: v1kind: PersistentVolumemetadata: name: mysql-pvspec: capacity: storage: 1Gi accessModes:-ReadWriteOnce nfs: path: / data/volumes/mysql-pv server: 192.168.1.203
Create a PV.
[root@master ~] # kubectl apply-f mysql-pv.yaml persistentvolume/mysql-pv created [root@master ~] # kubectl get pvNAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGEmysql-pv 1Gi RWO Retain Available 7s
The configuration file mysql-pvc.yaml for PVC is as follows:
ApiVersion: v1kind: PersistentVolumeClaimmetadata: name: mysql-pvcspec: accessModes:-ReadWriteOnce resources: requests: storage: 1Gi
Create a PVC.
[root@master ~] # kubectl apply-f mysql-pvc.yaml persistentvolumeclaim/mysql-pvc created [root@master ~] # kubectl get pvcNAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGEmysql-pvc Bound mysql-pv 1Gi RWO 7s2, deployment MySQL
The configuration file mysql.yaml for MySQL is as follows:
ApiVersion: v1kind: Servicemetadata: name: mysqlspec: ports:-port: 3306 selector: app: mysql---apiVersion: extensions/v1beta1kind: Deploymentmetadata: name: mysqlspec: selector: matchLabels: app: mysql template: metadata: labels: app: mysqlspec: containers:-name: mysql image: mysql:5.6 env:-name: MYSQL_ROOT_PASSWORD value : password ports:-name: mysql containerPort: 3306 volumeMounts:-name: mysql-persistent-storage mountPath: / var/lib/mysql volumes:-name: mysql-persistent-storage persistentVolumeClaim: claimName: mysql-pvc
The PV mysql-pv of PVC mysql-pvc Bound will be mount to the data directory of MySQL / var/lib/mysql.
[root@master ~] # kubectl apply-f mysql.yaml service/mysql createddeployment.extensions/mysql created [root@master ~] # kubectl get pod-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESmysql-7686899cf9-d4m42 1 Running 062s 10.244.2.17 node02 3, update MySQL data
MySQL is deployed to k8s-node02, and the client accesses Service mysql as follows:
[root@master] # kubectl run-it-- rm-- image=mysql:5.6-- restart=Never mysql-client-- mysql- h mysql- ppasswordIf you don't see a command prompt, try pressing enter.mysql >
We create a table myid in the mysql library and then add a few pieces of data to the table.
Mysql > use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changedmysql > create table myid (id int (4)); Query OK, 0 rows affected (0.04 sec) mysql > insert myid values (111); Query OK, 1 row affected (0.00 sec) mysql > select * from myid;+-+ | id | +-+ | 111 | +-+ 1 row in set (0.00 sec) 4, failover
We are now shutting down the node02 machine to simulate node downtime.
After a while, Kubernetes migrates MySQL to k8s-node01.
[root@master] # kubectl get pod-o wideNAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATESmysql-7686899cf9-8z6tc 1 Running 0 21s 10.244.1.19 node01 mysql-7686899cf9-d4m42 1 Terminating 0 23m 10.244.2.17 node02
Verify the consistency of the data.
[root@master] # kubectl run-it-- rm-- image=mysql:5.6-- restart=Never mysql-client-- mysql- h mysql- ppasswordIf you don't see a command prompt, try pressing enter.mysql > use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with-ADatabase changedmysql > select * from myid;+-+ | id | +-+ | 111 | +-+ 1 row in set (0.00 sec)
The MySQL service is restored and the data is intact, so we can look at the generated database file on the storage node.
[root@datanode03 mysql-pv] # ll Total usage 110604 ib_logfile0-rw-rw---- RW root@datanode03 mysql-pv-1 systemd-bus-proxy ssh_keys 56 December 14 09:53 auto.cnf-rw-rw---- 1 systemd-bus-proxy ssh_keys 12582912 December 14 10:15 ibdata1-rw-rw---- 1 systemd-bus-proxy ssh_keys 50331648 December 14 10:15 ib_logfile0-rw-rw---- 1 systemd-bus-proxy ssh_keys 50331648 December 14 09:53 Ib_logfile1drwx- 2 systemd-bus-proxy ssh_keys 4096 December 14 10:05 mysqldrwx- 2 systemd-bus-proxy ssh_keys 4096 December 14 09:53 performance_schema
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.