【问题标题】:k8s readiness probe - command with http getk8s 就绪探针 - 带有 http get 的命令
【发布时间】:2020-03-21 17:04:39
【问题描述】:

这个问题是关于 k8s 就绪探测的。 我正在尝试将就绪探针 curl 中的命令添加到正在创建的新 pod。

我的意思是我想在旧的 Pod 终止之前检查创建的新 Pod 是否准备好接受流量。 我已经有一个在 readines 探针中执行的命令,所以我无法以这种方式添加 httpGet:

readinessProbe:
  httpGet:
    path: /health

因为我看到有一个issue 无法添加将要执行的httpGet & 命令。

因此,我必须在每次创建新 pod 之前将这个 curl 添加到正在运行的脚本中。

status=$( curl -s -o -k /dev/null -w %{http_code} /health); echo "statusCode: $status" if [ "$status" -ne "200" ]; exit 1 fi

我的问题是它不工作,使用kubectl describe po XXXXX 我看到了这个输出:

 Readiness probe failed: statusCode: 000000 if [ 000000 -ne 200 ]

所以,我不知道如何向新 pod 发出请求,因为我对这个级别的新 pod 的唯一了解是它包含一个名为 health 的 api。

我提出的请求正确吗?

【问题讨论】:

    标签: kubernetes


    【解决方案1】:

    您缺少一些冒号和一个 then。

    你有:

    status=$( curl -s -o -k /dev/null -w %{http_code} /health); echo "statusCode: $status" if [ "$status" -ne "200" ]; exit 1 fi
    

    而不是

    status=$( curl -s -o -k /dev/null -w %{http_code} /health); echo "statusCode: $status"; if [ "$status" -ne "200" ]; then exit 1; fi
    

    【讨论】:

    • 谢谢,这是我第一次使用 shell 脚本。现在唯一的错误是“Readiness probe failed: statusCode: 000000”,这是我知道如何向新 pod 发送请求最重要的,你知道吗?
    • 目前还不清楚是谁销毁/创建了 pod,或者您是否需要比准备探测更多的东西。当就绪探测将返回“Succeed”(当您的状态为 200 时)时,kubernetes 将使用 start 向该 pod 发送请求(例如,如果您配置了服务)。如果您对此有更多疑问,请接受此答案并开始一个新问题(描述完整场景 - 谁创建/销毁/多少服务/等)。这个问题是关于您的就绪探测不起作用的问题,我认为我们解决了这个问题。
    • 您可以尝试使用此命令(更改-k-o 的顺序),因为-o 选项应该直接跟在您的情况下为/dev/null status=$( curl -s -k -o /dev/null -w %{http_code} localhost/health); echo "statusCode: $status"; if [ "$status" -ne "200" ]; then exit 1; fi 的文件路径后面.如果您使用的端口不是 80,则还要在路径中指定它以及 localhost
    • 谢谢,添加完整路径并解决了 localhost 并添加命令的完整路径为我解决了问题。 status=$(/usr/bin/curl --noproxy "*" -s -o /dev/null -w %{http_code} http://localhost:1880/ping); /bin/echo "new pod http request status code: $status"; if [ "$status" -ne "200" ]; then exit 1; fi
    猜你喜欢
    • 2020-09-13
    • 1970-01-01
    • 2019-07-22
    • 2020-12-19
    • 2021-05-24
    • 2020-08-18
    • 1970-01-01
    • 2020-05-11
    • 1970-01-01
    相关资源
    最近更新 更多