Can I set a default namespace in Kubernetes?

mac picture mac · Feb 27, 2019 · Viewed 8.4k times · Source

Can I set the default namespace? That is:

$ kubectl get pods -n NAMESPACE

It saves me having to type it in each time especially when I'm on the one namespace for most of the day.

Answer

Michael Hausenblas picture Michael Hausenblas · Feb 27, 2019

Yes, you can set the namespace as per the docs like so:

$ kubectl config set-context --current --namespace=NAMESPACE

Alternatively, you can use kubectx for this.