How change pod restart policy

9/7/2019

How to change the restart policy of a running pod from Always to Never. I've kubectl edit but it does not allow to change it.

-- pditommaso
kubernetes

3 Answers

9/10/2019

If kubectl edit is not allowing you to change the restartPolicy

Do this, kubectl delete deployment <deployment_name>

Edit yaml file with new changes. Then create deployment again. kubectl create -f deployment.yaml

Or

Edit yaml file with new changes. and apply changes to deployment using. kubectl apply -f deployment.yaml

This will delete old pod and will create new pod with new changes.

-- Sachin Arote
Source: StackOverflow

9/9/2019

If you have pods associated with deployemnt edit it setting up proper restartPolicy for your pod.

$ kubectl edit your_deployment_name

Save changes, delete old pod, new one will come with proper resartPolicy.

To see the rollout status, run:

$ kubectl rollout status your_deployment_name

Read more here: pods-restart-policy, deployments.

Deleting pod doesn't change anything if you don't change manifest of deployment and add proper restartPolicy.

You can also delete whole deployment, change configuration file and create it from scratch.

-- MaggieO
Source: StackOverflow

9/7/2019

Once you created the pod, kubernetes makes some properties immutable. These are mostly the options which can change pods stability, for example this.

You can get the manifest using kubectl get pod $PODNAME -o yaml --export. Then edit this manifest and change the restartPolicy field to Never and redeploy it.

-- Akın Özer
Source: StackOverflow