简体   繁体   English

Kubernetes MySQL复制-主服务主机查询

[英]Kubernetes MySQL replication - Master service host inquiry

I currently have a working MySQL master and slave with asynchronous replication set up on a Kubernetes cluster. 我目前在Kubernetes集群上设置了具有异步复制功能的可工作的MySQL主服务器和从服务器。

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. 我认为第一步是检查Dockerfile和在Dockerfile中定义ENTRYPOINT的脚本。

When I kubectl get svc , this is the information I get about the services. 当我kubectl get svc ,这就是我获得的有关服务的信息。 在此处输入图片说明

This tells me on the cluster, the master has an IP 10.0.156.209 . 这告诉我在群集上,主服务器具有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) 现在,当我docker-entrypoint.sh MySQL 奴隶 Docker映像的帮助脚本docker-entrypoint.sh ,我注意到这一行有助于设置主从场景(我将其剪裁以突出显示这一点)

在此处输入图片说明

and when I boot into the slave pod on Kubernetes, the environment variable $MYSQL_MASTER_SERVICE_HOST is set to 10.0.156.209 当我启动到Kubernetes上的slave pod时,环境变量$MYSQL_MASTER_SERVICE_HOST设置为10.0.156.209

在此处输入图片说明

My question: How did the MySQL slave pod know to use the master's cluster IP as the value for $MYSQL_MASTER_SERVICE_HOST ? 我的问题: MySQL从属容器如何知道使用主服务器的群集IP作为$MYSQL_MASTER_SERVICE_HOST的值? Is this a Kubernetes thing or a SQL thing? 这是Kubernetes还是SQL?

Thank you :) 谢谢 :)

These environment variables are created automatically by Kubernetes for each Service. 这些环境变量由Kubernetes为每个服务自动创建。 See: https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#environment-variables 请参阅: 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. 当Pod在节点上运行时,kubelet为每个活动的Service添加一组环境变量。

On another note, mysql on Kubernetes is a complex topic. 另外,Kubernetes上的mysql是一个复杂的话题。 You probably don't want to roll your own solution. 您可能不想推出自己的解决方案。 Have you looked at Vitess ? 您看过Vitess吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM