21zoo Labs - Assorted Stuff

How to set a default namespace for "kubectl"

Posted — Apr 20, 2018

Kubernetes uses namespaces. If you don’t specify any, it will use the default namespace. You can use a “Context” if you want all your kubectl commands to use the same namespace.

$ kubectl config set-context kube-cluster-ctx --namespace=my-namespace
Context "kube-cluster-ctx" created.

You have to also start using the context once it’s created like so:

$ kubectl config use-context kube-cluster-ctx
Switched to context "kube-cluster-ctx".

All subsequent kubectl commands will run in my-namespace.