How do I undo a kubectl create deploy?

6/21/2020

I was setting up a nginx cluster on google cloud, and I entered a wrong image name; instead of entering:

kubectl create deploy nginx --image=nginx:1.17.10

I entered:

kubectl create deploy nginx --image=1.17.10

and eventually after running kubectl get pods, It showed ImagePullBackOff as the status for the pod.

When I tried running the correct create deploy command above, It said "nginx" already exists.

When I tried doing kubernetes delete --all pods, the pod was recreated with a new ID but still had the same status, and still couldn't allow me to run the right 'kubectl create deploy' command above. Now I'm stuck.

How can I undo it?

-- pintert3
google-cloud-platform
google-kubernetes-engine
kubernetes

3 Answers

6/21/2020

You need to delete the deployment:

kubectl delete deploy nginx

Otherwise Kubernetes will recreate the pod on every shutdown.

You can see all your deployments with

kubectl get deploy 
-- Chris
Source: StackOverflow

6/21/2020

Edit the deployment via kubectl edit deployment DEPLOYMENT_NAME and change the image name.

Or

Edit the manifest file and append the file with a correct image mane and do a kubectl apply -f YAML file

-- sunnyb
Source: StackOverflow

1/13/2021

First of all, your k8s cluster is trying to pull image 1.17.10 from public docker registry. But as there are no image exists with this name that's why it's get error. And when you have tried to delete your pods it will again try to create with same image name as your deployment is exists. For this reason you need to delete deployment rather then pods. Otherwise, deployment will automatically try to create deleted pod again.

you can actually check what was the error in your deployment with this command:

kubectl describe deploy nginx

For you the command will bekubectl delete deploy -n <Namespace_name> <deployment_name>. As you have created your deployment in default namespace you don't need to mention the namespace automatically it will be the default namespace. you can delete deployment with this command:

kubectl delete deploy nginx
-- Emon46
Source: StackOverflow