簡體   English   中英

Kubernetes 就緒探測失敗

[英]Kubernetes readiness probe fails

我使用 bash 腳本為我的 pod 編寫了一個 readiness_probe。 就緒探測失敗,原因是:不健康,但是當我手動進入 pod 並運行此命令時/bin/bash -c health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping); if [[ $health -ne 401 ]]; then exit 1; fi /bin/bash -c health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping); if [[ $health -ne 401 ]]; then exit 1; fi /bin/bash -c health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping); if [[ $health -ne 401 ]]; then exit 1; fi bash 腳本以代碼 0 退出。可能是什么原因? 我附上代碼和下面的錯誤。

編輯:發現健康變量設置為 000,這意味着 bash 腳本超時。

readinessProbe:
  exec:
    command:
    - /bin/bash
    - '-c'
    - |-
      health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping);
      if [[ $health -ne 401 ]]; then exit 1; fi

“kubectl 描述 pod {pod_name}”結果:

Name:         rustici-engine-54cbc97c88-5tg8s
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Tue, 12 Jul 2022 18:39:08 +0200
Labels:       app.kubernetes.io/name=rustici-engine
              pod-template-hash=54cbc97c88
Annotations:  <none>
Status:       Running
IP:           172.17.0.5
IPs:
  IP:           172.17.0.5
Controlled By:  ReplicaSet/rustici-engine-54cbc97c88
Containers:
  rustici-engine:
    Container ID:   docker://f7efffe6fc167e52f913ec117a4d78e62b326d8f5b24bfabc1916b5f20ed887c
    Image:          batupaksoy/rustici-engine:singletenant
    Image ID:       docker-pullable://batupaksoy/rustici-engine@sha256:d3cf985c400c0351f5b5b10c4d294d48fedfd2bb2ddc7c06a20c1a85d5d1ae11
    Port:           8080/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Tue, 12 Jul 2022 18:39:12 +0200
    Ready:          False
    Restart Count:  0
    Limits:
      memory:  350Mi
    Requests:
      memory:  350Mi
    Liveness:  exec [/bin/bash -c health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping);
if [[ $health -ne 401 ]]; then exit 1; else exit 0; echo $health; fi] delay=10s timeout=5s period=10s #success=1 #failure=20
    Readiness:  exec [/bin/bash -c health=$(curl -s -o /dev/null --write-out "%{http_code}" http://localhost:8080/api/v2/ping);
if [[ $health -ne 401 ]]; then exit 1; else exit 0; echo $health; fi] delay=10s timeout=5s period=10s #success=1 #failure=10
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-whb8d (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-whb8d:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   Burstable
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age   From               Message
  ----     ------     ----  ----               -------
  Normal   Scheduled  24s   default-scheduler  Successfully assigned default/rustici-engine-54cbc97c88-5tg8s to minikube
  Normal   Pulling    23s   kubelet            Pulling image "batupaksoy/rustici-engine:singletenant"
  Normal   Pulled     21s   kubelet            Successfully pulled image "batupaksoy/rustici-engine:singletenant" in 1.775919851s
  Normal   Created    21s   kubelet            Created container rustici-engine
  Normal   Started    20s   kubelet            Started container rustici-engine
  Warning  Unhealthy  4s    kubelet            Readiness probe failed:
  Warning  Unhealthy  4s    kubelet            Liveness probe failed:

if [[ $health -ne 401 ]]; then exit 1; fi

問題不在於 bash 腳本。 如果 http 代碼 ($health) 不等於未授權錯誤並且退出 1 將導致就緒檢查失敗。

探針可能會失敗,因為它面臨性能問題或啟動緩慢。 要解決此問題,您需要檢查在應用程序啟動並在您的 pod 中運行之前不會啟動探測。 也許您需要增加Timeout of the Readiness ProbeTimeout of the Liveness Probe的 Timeout,如下例所示:

readinessProbe:
          initialDelaySeconds: 10
          periodSeconds: 2
          timeoutSeconds: 10

您可以在此鏈接中找到有關如何配置 Readlines Probe 和 Liveness Probe 的更多詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM