3

Kubectl: Set Default Namespace – Kubernetes

 2 years ago
source link: https://www.shellhacks.com/kubectl-set-default-namespace-kubernetes/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Kubectl: Set Default Namespace – Kubernetes

Out of the box, there is a Namespace called ‘default‘ in a Kubernetes cluster.

By default, the kubectl command interacts with this ‘default‘ Namespace, but it can be changed to any other Namespace.

In this note i will show how to set the default Namespace in Kubernetes.

Cool Tip: List & Change Namespaces in Kubernetes! Read more →

Set Default Namespace in Kubernetes

To get the list of all Namespaces in a Kubernetes cluster, run one of the commands below:

$ kubectl get namespaces
- or -
$ kubectl get ns
- sample output -
NAME              STATUS   AGE
default           Active   1d
kube-node-lease   Active   1d
kube-public       Active   1d
kube-system       Active   1d

To find out the current Namespace name:

$ kubectl config view --minify --output 'jsonpath={..namespace}'; echo
- sample output -
default

To change the Namespace (set the default namespace for the current context):

$ kubectl config set-context --current --namespace=<NAME>

The command above sets the default Namespace for the current context, so all the kubectl commands in this context, by default, will be executed in the defined Namespace.

Cool Tip: List Pods in Kubernetes cluster! Read more →


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK