kchns my-namespace
Once executed, any command like kubectl get pods will automatically look into the namespace you just set. Using Kubens for Faster Switching kubectl change namespace
kubectl get namespaces
In Kubernetes, namespaces are used to isolate resources within a single cluster. By default, most commands target the default namespace. If you are working on a specific project, such as a development or production environment, manually typing --namespace for every command is inefficient. Changing your active namespace streamlines your workflow and reduces the risk of deploying resources to the wrong environment. Using Native Kubectl Commands kchns my-namespace Once executed, any command like kubectl
Suppose you have two namespaces: dev and prod . You want to list all pods in the dev namespace: If you are working on a specific project,
This approach is safer for one-off tasks because it doesn't alter your persistent configuration. If you find yourself using this flag repeatedly, it is time to use the set-context method described above. Verifying Your Current Namespace