![](/img/trans.png)
[英]How to find logs for command terminated with exit code 137 error after kubectl exec command is triggered at pod
[英]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
。1
或2
,则记录从1-5
改组 integer 的结果因此,在您的情况下,洗牌的退出代码是1
,而 log 的洗牌结果是2
。 应用程序的退出代码1
被视为 Kubernetes 的Error
原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.