Search code examples
deploymentkubernetes

How to delete and recreate pods using yaml file in kubernetes


I have a yaml file which I can use to create pods. I am using the dashboard so I can simply select yaml file and it will create pods. Pod will start the container and container will run the docker image. So now lets say I have done some changes in the docker image and want to deploy it again. For this, I will delete the already running pod and will upload the yaml file.

Instead of deleting and uploading yaml file again, is there any keyword available which will delete the already running pod/deployment and will recreate it.

Thanks


Solution

  • I can't remember the StackOverflow question where I first saw this method, but here it is again:

    kubectl --namespace thenamespace get pod thepod -o yaml | kubectl replace --save-config -f -

    You can do that with all k8s resources.