How to switch k8s object from one namespace to another one?

6/23/2020

Let's suppose I've got following manifests like deployment, services and ingress. All it works fine in default namespace. Although I want to throw resources to another namespace created with manifest.yaml. I thought if I wrote kubectl appy -f $DIR it would work as expected: objects would be moved to another namespace. But nothing changed.

To sum up, how can force moving objects to another namespace?

-- Igor Samarskiy
kubernetes

1 Answer

6/23/2020

You can either edit all the deployment yamls to add namespace or you can run kubectl apply -f $DIR -n namespacename. This command will deploy all the yamls to namespace namespacename

Edit:

The thing to understand here is you can not move resources from one namespace to another namespace just by changing the namespace in the yaml. If you do that It will just create another copy of the same resource in another namespace. Delete from previous namespace and recreate in new namespace is the right approach.

-- Arghya Sadhu
Source: StackOverflow