Stop restarting kubernetes pod

5/19/2020

Is there any way to stop restarting pod again and again when inside container fails.

simple way to check this is to pass [ "exit", "1" ] to pod as-

enter code here
apiVersion: v1
kind: Pod
metadata:
  name: myapp-pod
  labels:
    app: myapp
spec:
  containers:
  - name: myapp-container
    image: alpine:latest
    command: ['sh','-c','exit','1']

Note -
RestartPolicy : Never this option is unsupported.

-- Yogesh Jilhawar
kubernetes
kubernetes-pod
restart

1 Answer

5/19/2020

You will need to change the restart policy of the pod:

A PodSpec has a restartPolicy field with possible values Always, OnFailure, and Never. The default value is Always. restartPolicy applies to all Containers in the Pod. restartPolicy only refers to restarts of the Containers by the kubelet on the same node. Exited Containers that are restarted by the kubelet are restarted with an exponential back-off delay (10s, 20s, 40s …) capped at five minutes, and is reset after ten minutes of successful execution. As discussed in the Pods document, once bound to a node, a Pod will never be rebound to another node.

See more details here and here.

-- omricoco
Source: StackOverflow