Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pod terminated with reason Error and Exit Code: 1

I have Question on pod termination on using image: kodekloud/throw-dice

pod-defintion.yml

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

I have checked the steps in DockerFile . It runs throw-dice.sh which randomly returns number in between 1 - 6.

let's consider first time container return 3, so how below pod is terminated ? where is the condition defined in the pod level it suppose to terminate if script return number is !6.

Below steps were performed to execute 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
like image 854
Uday Kiran Avatar asked Oct 29 '25 08:10

Uday Kiran


1 Answers

The dockerfile has ENTRYPOINT sh throw-dice.sh which means execute the script and then the container terminates automatically. If you want the container to keep running you need to start a long running process for example a java process ENTRYPOINT ["java", "-jar", "/whatever/your.jar"]

like image 66
Arghya Sadhu Avatar answered Oct 31 '25 01:10

Arghya Sadhu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!