Kubernetes MySQL replication - Master service host inquiry

6/8/2017

I currently have a working MySQL master and slave with asynchronous replication set up on a Kubernetes cluster.

I'm trying to plan for a contingency if the master goes down, the slave will pick up the slack and what not. I figured the first step would be to review the Dockerfiles and scripts that define the ENTRYPOINT within the Dockerfiles.

When I kubectl get svc, this is the information I get about the services. enter image description here

This tells me on the cluster, the master has an IP 10.0.156.209.

Now when I flicked through the helper script docker-entrypoint.sh for the MySQL slave Docker image, I noticed this line which helps set up the master-slave scenario (I trimmed the line just to highlight this)

enter image description here

and when I boot into the slave pod on Kubernetes, the environment variable $MYSQL_MASTER_SERVICE_HOST is set to 10.0.156.209

enter image description here

My question: How did the MySQL slave pod know to use the master's cluster IP as the value for $MYSQL_MASTER_SERVICE_HOST? Is this a Kubernetes thing or a SQL thing?

Thank you :)

-- MikamiHero
containers
docker
kubernetes
mysql
sql

1 Answer

6/8/2017

These environment variables are created automatically by Kubernetes for each Service. See: https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#environment-variables

When a Pod is run on a Node, the kubelet adds a set of environment variables for each active Service.

On another note, mysql on Kubernetes is a complex topic. You probably don't want to roll your own solution. Have you looked at Vitess?

-- Janos Lenart
Source: StackOverflow