簡體   English   中英

Pod 因錯誤和退出代碼原因終止:1

[英]Pod terminated with reason Error and Exit Code: 1

我對使用圖像的 pod 終止有疑問:kodekloud/throw-dice

吊艙定義.yml

apiVersion: v1
kind: Pod
metadata:
  name: throw-dice-pod
spec:
  containers:
  -  image: kodekloud/throw-dice
     name: throw-dice
  restartPolicy: Never

我已經檢查了DockerFile中的步驟。 它運行throw-dice.sh ,它隨機返回 1 - 6 之間的數字。

讓我們考慮第一次容器返回 3,那么下面的 pod 是如何終止的? 如果腳本返回編號為.6,它假設終止的 pod 級別中定義的條件在哪里。

執行以下步驟以執行 pod-definition.yml

master $ kubectl create -f /root/throw-dice-pod.yaml
pod/throw-dice-pod created
master $ kubectl get pods
NAME             READY   STATUS              RESTARTS   AGE
throw-dice-pod   0/1     ContainerCreating   0          9s
master $ kubectl get pods
NAME             READY   STATUS   RESTARTS   AGE
throw-dice-pod   0/1     Error    0          12s
master $ kubectl describe pod throw-dice-pod
Name:         throw-dice-pod
Namespace:    default
Priority:     0
Node:         node01/172.17.0.83
Start Time:   Sat, 16 May 2020 11:20:01 +0000
Labels:       <none>
Annotations:  <none>
Status:       Failed
IP:           10.88.0.4
IPs:
  IP:  10.88.0.4
Containers:
  throw-dice:
    Container ID:   docker://4560c794b58cf8f3e3fad691b2292e37db4e84e20c9286321f026d1735272b5f
    Image:          kodekloud/throw-dice
    Image ID:       docker-pullable://kodekloud/throw-dice@sha256:9c70a0f907b99293885a9591b6162e9ec89e127937626a97ca7f9f6be2d98b01
    Port:           <none>
    Host Port:      <none>
    State:          Terminated
      Reason:       Error
      Exit Code:    1
      Started:      Sat, 16 May 2020 11:20:10 +0000
      Finished:     Sat, 16 May 2020 11:20:10 +0000
    Ready:          False
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-nr5kl (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             False
  ContainersReady   False
  PodScheduled      True
Volumes:
  default-token-nr5kl:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-nr5kl
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  <none>
Tolerations:     node.kubernetes.io/not-ready:NoExecute for 300s
                 node.kubernetes.io/unreachable:NoExecute for 300s
Events:
  Type    Reason     Age        From               Message
  ----    ------     ----       ----               -------
  Normal  Scheduled  <unknown>  default-scheduler  Successfully assigned default/throw-dice-pod to node01
  Normal  Pulling    21s        kubelet, node01    Pulling image "kodekloud/throw-dice"
  Normal  Pulled     19s        kubelet, node01    Successfully pulled image "kodekloud/throw-dice"
  Normal  Created    19s        kubelet, node01    Created container throw-dice
  Normal  Started    18s        kubelet, node01    Started container throw-dice


 master $ kubectl logs throw-dice-pod
      2

dockerfile 有ENTRYPOINT sh throw-dice.sh表示執行腳本,然后容器自動終止。 如果您希望容器繼續運行,您需要啟動一個長時間運行的進程,例如 java 進程ENTRYPOINT ["java", "-jar", "/whatever/your.jar"]

此處的退出代碼1由應用程序設置。

看看throw-dice.sh 我們看到應用程序在0,1,2之間改組退出代碼。

  • 退出代碼總是等於上面的洗牌結果。
  • 如果退出代碼為0 ,則記錄6
  • 如果退出代碼是12 ,則記錄從1-5改組 integer 的結果

因此,在您的情況下,洗牌的退出代碼是1 ,而 log 的洗牌結果是2 應用程序的退出代碼1被視為 Kubernetes 的Error原因。

暫無
暫無

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

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