How do you move a pod between namespaces in Kubernetes?

Experience Level: Senior
Tags: Kubernetes

Answer

You cannot move a resource to another namespace. You need to delete the existing pod and recreate it in the other namespace.

Run the following commands:

kubectl get pod pod1 -o json -n oldnamespace | jq '.metadata.namespace="newnamespace"' | kubectl apply -f -
kubectl delete pod pod1 -n oldnamespace

Comments

No Comments Yet.
Be the first to tell us what you think.
Kubernetes Certified Application Developer (CKAD) preparation
Kubernetes Certified Application Developer (CKAD) preparation

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself
Kubernetes
Kubernetes

Are you learning Kubernetes ? Try our test we designed to help you progress faster.

Test yourself