Adding a New MySQL Pod (mysql-4 Pod)
For details about how to add a new physical machine to a K8s cluster, see Kubernetes 1.18.20 Deployment Guide (CentOS & openEuler).
- Open the mysql_deployment.yaml configuration file on the physical machine of the primary node.
vim mysql_deployment.yaml
- Press i to enter the insert mode and add the new pod deployment. Modify the content as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
...... --- apiVersion: v1 kind: Pod metadata: name: mysql-1 ...... hostAliases: ...... - ip: "10.99.0.18" hostnames: - "mysql-4" ...... --- apiVersion: v1 kind: Pod metadata: name: mysql-2 ...... hostAliases: ...... - ip: "10.99.0.18" hostnames: - "mysql-4" ...... --- apiVersion: v1 kind: Pod metadata: name: mysql-3 ...... hostAliases: ...... - ip: "10.99.0.18" hostnames: - "mysql-4" ...... --- apiVersion: v1 kind: Pod metadata: labels: app: mysql-4 name: mysql-4 namespace: ns-mysql-test annotations: ovn.kubernetes.io/ip_address: 10.99.0.18 ovn.kubernetes.io/mac_address: 00:00:00:53:6B:B9 spec: nodeSelector: test: "mysql-test-4" hostAliases: - ip: "10.99.0.15" hostnames: - "mysql-1" - ip: "10.99.0.16" hostnames: - "mysql-2" - ip: "10.99.0.17" hostnames: - "mysql-3" - ip: "10.99.0.18" hostnames: - "mysql-4" containers: - name: mysql-4 image: mymysql/centos8-mysql-arm:8.0.19 resources: limits: cpu: 16 memory: 64Gi ports: - name: mysql-port containerPort: 3306 - name: copy-port containerPort: 33061 env: - name: MYSQL_ROOT_PASSWORD value: test123 - name: MYSQL_ROOT_HOST value: "%" volumeMounts: - name: mysql-data mountPath: "/data/mysql/data" - name: mysql-log mountPath: "/data/mysql/log" - name: mysql-run mountPath: "/data/mysql/run" - name: mysql-tmp mountPath: "/data/mysql/tmp" - name: mysql-cnf mountPath: "/etc/my.cnf" volumes: - name: mysql-data hostPath: path: "/data/mysql/mysql_4/data" type: DirectoryOrCreate - name: mysql-log hostPath: path: "/data/mysql/mysql_4/log" type: DirectoryOrCreate - name: mysql-run hostPath: path: "/data/mysql/mysql_4/run" type: DirectoryOrCreate - name: mysql-tmp hostPath: path: "/data/mysql/mysql_4/tmp" type: DirectoryOrCreate - name: mysql-cnf hostPath: path: "/data/mysql/mysql_4/mysql_arm.cnf" type: FileOrCreate ...... --- apiVersion: v1 kind: Service metadata: name: mysql-4-service namespace: ns-mysql-test spec: type: NodePort selector: app: mysql-4 ports: - name: dbport protocol: TCP port: 3306 targetPort: 3306 nodePort: 30004 - name: cpport protocol: TCP port: 33061 targetPort: 33061 nodePort: 30064
- Press Esc, type :wq!, and press Enter to save the file and exit.
The preceding YAML file is modified as follows:
- The host name resolution rule of mysql-4 is added to the hostAliases of other MySQL pods. (This rule is used when the MGR group is created.)
- The pod deployment configuration of mysql-4 is added to the file. The namespace of the pod must be the same as that of other MySQL pods. The IP address, MAC address, and host path to which the data directory is mounted cannot conflict with those of other pods.
- The service deployment of mysql-4-service is added to the file. The deployment type is NodePort. Map ports 3306 and 33061 of mysql-4 to ports 30004 and 33064 of the physical machine, respectively.
- The other configurations of mysql-4 are similar to those of mysql-1, mysql-2, and mysql-3.
- The procedures for labeling the physical machine node with nodeSelector and preparing the configuration file for mysql-4 are similar to those for mysql-1, mysql-2, and mysql-3. For details, see Preparing the YAML File for Deploying MySQL Pods in the K8s Cluster and Preparing the MySQL Configuration File.
- After the modification of the configuration file is complete, run the kubectl apply -f ./mysql_deployment.yaml command on the K8s primary node to make the modification take effect. For details, see Modifying the Deployment.
Parent topic: K8s MGR Maintenance