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.
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).
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).
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.
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.
You can also use a temporary linux alias:
alias k='kubectl -n kube-system '
Then use it like
k get pods
That's it ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With