gpt4 book ai didi

centos - 如何添加kubernetes liveness probe

转载 作者:行者123 更新时间:2023-12-04 19:43:13 26 4
gpt4 key购买 nike

我正在编写一个简单的 YAML 文件以使用 Centos.6 上的 TCP 端口应用 active 探测

  • 我从公共(public)存储库中提取了一个 centos:6 图像
  • 使用图像启动了一个容器。
  • 安装mysql,并启动它来验证一个打开的端口(3306)
  • 以“mysql-test:v0.1”
  • 提交到本地存储库

    并如下应用一个 pods
    apiVersion: v1
    kind: Pod
    metadata:
    labels:
    test: mysql-test
    name: mysql-test-exec
    spec:
    containers:
    - name: mysql-test
    args:
    - /sbin/service
    - mysqld
    - start
    image: mysql-test:v0.1
    livenessProbe:
    tcpSocket:
    port: 3306
    initialDelaySeconds: 15
    periodSeconds: 20

    但是,pod 的状态是 CrashLoopBackOff ,而work02上的容器状态为 退出 .

    1) 主节点
    root@kubeadm-master01:~# kubectl get pods 
    NAME READY STATUS RESTARTS AGE
    mysql-test-exec 0/1 CrashLoopBackOff 6 8m

    root@kubeadm-master01:~# kubectl describe pod mysql-test-exec
    .
    .
    .
    Events:
    FirstSeen LastSeen Count From SubObjectPath Type Reason Message
    --------- -------- ----- ---- ------------- -------- ------ -------
    1m 1m 1 default-scheduler Normal Scheduled Successfully assigned mysql-test-exec to kubeadm-work02
    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Created Created container with id abbad6585021151cd86fdfb3a9f733245f603686c90f533f23
    44397c97c36918
    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Started Started container with id abbad6585021151cd86fdfb3a9f733245f603686c90f533f23
    44397c97c36918
    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Started Started container with id a1062083089eed109fe8f41344136631bb9d4c08a2c6454dc7
    7f677f01a48666
    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Created Created container with id a1062083089eed109fe8f41344136631bb9d4c08a2c6454dc7
    7f677f01a48666
    1m 1m 3 kubelet, kubeadm-work02 Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" wit
    h CrashLoopBackOff: "Back-off 10s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Created Created container with id 79512aeaf8a6b4692e11b344adb24763343bb2a06c9003222097962822d42202
    1m 1m 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Started Started container with id 79512aeaf8a6b4692e11b344adb24763343bb2a06c9003222097962822d42202
    1m 43s 3 kubelet, kubeadm-work02 Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" with CrashLoopBackOff: "Bac
    k-off 20s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

    29s 29s 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Started Started container with id 4427a3b8e5320b284ac764c1152def4ba749e4f656b3c464a472514bccf2e30e
    1m 29s 4 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Pulled Container image "centos-mysql:v0.1" already present on machine
    29s 29s 1 kubelet, kubeadm-work02 spec.containers{mysql-test} Normal Created Created container with id 4427a3b8e5320b284ac764c1152def4ba749e4f656b3c464a472514bccf2e30e
    1m 10s 9 kubelet, kubeadm-work02 spec.containers{mysql-test} Warning BackOff Back-off restarting failed container
    27s 10s 3 kubelet, kubeadm-work02 Warning FailedSync Error syncing pod, skipping: failed to "StartContainer" for "mysql-test" with CrashLoopBackOff: "Bac
    k-off 40s restarting failed container=mysql-test pod=mysql-test-exec_default(810c37bd-7a8c-11e7-9224-525400603584)"

    2)工作节点
    root@kubeadm-work02:~# docker logs f64e20bf33a8
    Starting mysqld: [ OK ]

    最佳答案

    我必须删除 args 才能使用 docker 镜像。下面的部署对我有用。

    apiVersion: v1
    kind: Pod
    metadata:
    labels:
    test: mysql-test
    name: mysql-test-exec
    spec:
    containers:
    - name: mysql-test
    image: mysql:5.6
    env:
    - name: MYSQL_ROOT_PASSWORD
    value: mysql456
    livenessProbe:
    tcpSocket:
    port: 3306
    initialDelaySeconds: 15
    periodSeconds: 20

    关于centos - 如何添加kubernetes liveness probe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45531039/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com