1

I have a pod that I can see on GKE. But if I try to delete them, I got the error:

kubectl delete pod my-pod --namespace=kube-system --context=cluster-1 

Error from server (NotFound): pods "my-pod" not found

However, if I try to patch it, the operation was completed successfully:

kubectl patch deployment my-pod --namespace kube-system -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"secrets-update\":\"`date +'%s'`\"}}}}}" --context=cluster-1

deployment.apps/my-pod patched

Same namespace, same context, same pod. Why kubectl fails to delete the pod?

Rodrigo
  • 135
  • 4
  • 45
  • 107

1 Answers1

3
kubectl patch deployment my-pod --namespace kube-system -p "{\"spec\":{\"template\":{\"metadata\":{\"annotations\":{\"secrets-update\":\"`date +'%s'`\"}}}}}" --context=cluster-1

You are patching the deployment here, not the pod.

Additionally, your pod will not be called "my-pod" but would be called the name of your deployment plus a hash (random set of letters and numbers), something like "my-pod-ace3g"

To see the pods in the namespace use

kubectl get pods -n {namespace}

Since you've put the deployment in the "kube-system" namespace, you would use

kubectl get pods -n kube-system

Side note: Generally don't use the kube-system namespace unless your deployment is related to the cluster functionality. There's a namespace called default you can use to test things

Blender Fox
  • 4,442
  • 2
  • 17
  • 30
  • If I update the secrets and run kubectl patch deployment my-pod, the pod will reload the config? – Rodrigo Apr 05 '22 at 17:19
  • 1
    Yes, the patch you're using is a common trick to "rolling restart" pods of a deployment. The patch will cause the pods to terminate and new ones spawn in their place, and during this time, the secrets will be remounted into the pod. – Blender Fox Apr 05 '22 at 17:43