4. Setup MySQL Replication
- 1 Common
Common
These instructions apply to Beijing and newer releases.
Setup Steps
We are using MySQL Master-Master replication strategy to set up replication across two kubernetes clusters (aka sites). The setup is done through below manual steps.
1. Verify MySQL server-id is different in both sites.
#Login to master db pod on site 1 and site 2
ubuntu@k8s-s1-master:~$ kubectl exec -it sdnc-dbhost-0 -n onap bash
Defaulting container name to sdnc-db-container.
Use 'kubectl describe pod/sdnc-dbhost-0' to see all of the containers in this pod.
root@sdnc-dbhost-0:/#
#Verify server-id on site 1
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=100
#Verify server-id on site 2
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=200
2. If MySQL site-id for site 1 and site 2, resulting from step 1, are not different, proceed with the below step to make them unique.
You can skip this step if the server-ids are verified to be unique in step #1. This step is only to be followed on site 2 (i.e. secondary site).
#Set server-id to a different number (e.g. 200) in the secondary site.
#Assuming the current value for server-id on site 2 is 100, we aim to change it to 200. Login to master DB pod on the Secondary site and change it.
ubuntu@k8s-s2-master:~$ kubectl exec -it sdnc-dbhost-0 -n onap bash
root@sdnc-dbhost-0:/# sed -i 's/100/200/g' /etc/mysql/conf.d/server-id.cnf
root@sdnc-dbhost-0:/etc/mysql/conf.d# service mysql restart
[info] Stopping MySQL Community Server 5.7.21.
...........command terminated with exit code 137
ubuntu@k8s-s1-master:~$
#verify
root@sdnc-dbhost-0:/# cd /etc/mysql/conf.d
root@sdnc-dbhost-0:/etc/mysql/conf.d# cat server-id.cnf
[mysqld]
server-id=200
3. Verify NodePort Service Port Number on each site.
#verify nodeport service exists
ubuntu@k8s-s1-master:~$ kubectl get svc -n onap | grep mysql
mysql-nodeport NodePort 10.107.197.242 <none> 3306:30231/TCP,3307:30232/TCP 29s
ubuntu@k8s-s1-master:~$
#verify the endpoints are assigned for the service
#make a note of Node Port Number to use in step#5
ubuntu@k8s-s1-master:~$ kubectl describe svc mysql-nodeport -n onap
Name: mysql-nodeport
Namespace: onap
Labels: statefulset.kubernetes.io/pod-name=sdnc-dbhost-0
Annotations: <none>
Selector: statefulset.kubernetes.io/pod-name=sdnc-dbhost-0
Type: NodePort
IP: 10.107.197.242
Port: sdnc-dbhost-0-port-3306 3306/TCP
TargetPort: 3306/TCP
NodePort: sdnc-dbhost-0-port-3306 30231/TCP
Endpoints: 10.44.0.3:3306
Port: sdnc-dbhost-0-port-3307 3307/TCP
TargetPort: 3307/TCP
NodePort: sdnc-dbhost-0-port-3307 30232/TCP
Endpoints: 10.44.0.3:3307
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
ubuntu@k8s-s1-master:~$
4. Setup Master-Master Replication.
On site 2 (Secondary site):
On site 1 (Primary site):
Verify replication status on both sites.
It should look like below: