Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set a default namespace in Kubernetes?

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.

like image 504
mac Avatar asked Feb 27 '19 09:02

mac


People also ask

What is default namespace in Kubernetes?

Kubernetes starts with four initial namespaces: default The default namespace for objects with no other namespace. kube-system The namespace for objects created by the Kubernetes system. kube-public This namespace is created automatically and is readable by all users (including those not authenticated).

How many namespace is created by Kubernetes by default?

The “default” Namespace In most Kubernetes distributions, the cluster comes out of the box with a Namespace called “default.” In fact, there are actually three namespaces that Kubernetes ships with: default, kube-system (used for Kubernetes components), and kube-public (used for public resources).

What is the default namespace?

A default namespace is a namespace that does not include a prefix. The default prefix is applied to all the elements that do not include a prefix and is unique for different XMLports. For example, the following string specifies a namespace: urn:microsoft-dynamics-nav/xmlports/x100 , where 100 is the ID of the XMLport.


2 Answers

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.

like image 149
Michael Hausenblas Avatar answered Oct 13 '22 06:10

Michael Hausenblas


You can also use a temporary linux alias:

alias k='kubectl -n kube-system '

Then use it like

k get pods

That's it ;)

like image 15
Rafael Duarte Avatar answered Oct 13 '22 06:10

Rafael Duarte