Can I set a default namespace in Kubernetes?

2/27/2019

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.

-- mac
kubectl
kubernetes

2 Answers

2/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.

-- Michael Hausenblas
Source: StackOverflow

4/15/2019

You can also use a temporary linux alias:

alias k='kubectl -n kube-system '

Then use it like

k get pods

That's it ;)

-- Rafael Duarte
Source: StackOverflow