Not able to prevent kubectl pod from recreating

2/8/2021

I would like to delete a pod that was created while editing and testing deployment.

I am extracting the pod configuration with

kubectl get po jenkins-774896bc77-tc8cg -n infrastructure -o yaml --export=true > a.yaml

Then I am editing the a.yaml file and replacing restartPolicy to Never.

Then I tried to run kubectl replace -f ./a.yaml -n infrastructure and kubectl apply -f ./a.yaml -n infrastructure

But in both cases I am getting:

error: error when replacing "./a.yaml": resource name may not be empty

Any advice how to fix this?

-- Bob
kubernetes

1 Answer

2/8/2021

You have to do this for deployment as deployment manages pods.

kubectl get deployment <your_deployment_name> -o yaml > a.yaml

and then do the rest part as you did kubectl replace -f ./a.yaml -n infrastructure

-- Dashrath Mundkar
Source: StackOverflow