首页 > 解决方案 > Mysql Kubernetes Deployment helm chart 失败,准备就绪,liveness probe failed

问题描述

我是 stackoverflow 的新手,所以如果我没有遵循提出这个问题的所有规则,请原谅。

所以,我正在使用这个 helm 图表:https ://github.com/helm/charts/tree/master/stable/mysql为我们的生产环境部署 mysql。事实上,我们在生产中运行了这个设置,但它只创建了 1 个 mysql pod,而我需要运行 3 个 pod。我尝试在 helm 图表的 values.yaml 文件中设置 replicas=3 并重新部署该图表,但它不断失败并出现一些错误,错误是:

Events:
    Type     Reason            Age                    From                  Message
    ----     ------            ----                   ----                  -------
    Warning  FailedScheduling  4m58s                  default-scheduler     pod has unbound immediate PersistentVolumeClaims (repeated 4 times)
    Normal   Scheduled         4m58s                  default-scheduler     Successfully assigned test-helm/cluster-mysql-5bcdf87779-vdb2s to innolx12896
    Normal   Pulled            4m57s                  kubelet, innolx12896  Container image "busybox:1.29.3" already present on machine
    Normal   Created           4m56s                  kubelet, innolx12896  Created container
    Normal   Started           4m56s                  kubelet, innolx12896  Started container
    Warning  BackOff           4m32s (x2 over 4m37s)  kubelet, innolx12896  Back-off restarting failed container
    Normal   Pulled            2m52s (x4 over 4m55s)  kubelet, innolx12896  Container image "mysql:5.7.14" already present on machine
    Normal   Created           2m52s (x4 over 4m55s)  kubelet, innolx12896  Created container
    Warning  Unhealthy         2m52s (x3 over 3m12s)  kubelet, innolx12896  Readiness probe failed: mysqladmin: [Warning] Using a password on the command line interface can be insecure.
                                                                            mysqladmin: connect to server at 'localhost' failed
                                                                            error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
                                                                            Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!
    Normal   Killing           2m52s                  kubelet, innolx12896  Killing container with id docker://cluster-mysql:Container failed liveness probe.. Container will be killed and recreated.
    Normal   Started           2m51s (x4 over 4m54s)  kubelet, innolx12896  Started container
    Warning  Unhealthy         2m12s (x4 over 3m42s)  kubelet, innolx12896  Liveness probe failed: mysqladmin: [Warning] Using a password on the command line interface can be insecure.
                                                                            mysqladmin: connect to server at 'localhost' failed
                                                                            error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
                                                                            Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

此外,当我尝试查看mysqld袜子时,它也不见了。但我不明白为什么。由于单个 pod 部署工作正常,但 3 pod 部署会产生此错误。

也可能有一些方法可以通过明确定义袜子的路径来解决这个问题,其他 StackOverflow 答案建议像这个答案1 或这个答案2。但需要注意的是,我们通过 Jenkins 自动化了整个生产图表部署,并且没有为每个生产版本显式运行这些命令的范围。

所以,我需要知道如何解决这个问题,或者知道是什么导致了这个问题,以便我可以更改或更改我在开头提到的 helm chart 中的一些参数。还要告诉我是否无法扩展此部署,这意味着此 helm 图表不支持或不适用于多个 mysql pod。

提前致谢。

标签: mysqlkuberneteskubernetes-helmreadinessprobelivenessprobe

解决方案


在您的情况下,Readiness 探测失败和 Liveness 探测失败。对于 mysql,请尝试以下操作(在 templates/deployment.yaml 中用于 Readiness & Liveness:

ports:
            - name: mysql
              containerPort: {{ .Values.service.port }}
              protocol: TCP
          livenessProbe:
            exec:
              command: ["mysqladmin", "ping"]
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
          readinessProbe:
            exec:
             # Check we can execute queries over TCP (skip-networking is off).
              command: ["mysql", "-h", "127.0.0.1", "-e", "SELECT 1"]
            initialDelaySeconds: 5
            periodSeconds: 2
            timeoutSeconds: 1

推荐阅读