Kubernetes 101 : Switching namespaces, the default namespace and contexts

Kubernetes namespaces:

Kubernetes uses namespaces to separate objects. For example different departments will have different applications running in different namespaces.

If we don't specify a namespace while issuing a command like "kubectl get pods
for example, the command executes in the default namespaceand it will only display the blue pods.

If we want our commands to run in a different namespace, we have to explicitly mention it as below for example:

Kubernetes contexts:

If we want to change the default namespace, we would need to use another kubernetes object called "context".

The information for the context lives in the following directory "$HOME/.kube/config".
"$HOME" is the home directory.

We could change the default namespace using the below command:

Then we would need to use the below command to apply our changes using the below command:

Setting the namespace:

You can permanently set the namespace for all subsequent "kubectl" commands using the below command:

Kubernetes objects and namespaces:

Some Kubernetes resources live in namespaceslike for example - pods, services, ...
Other resource like the kubernetes cluster nodes for example are cluster-wide resources.

To display the "namespaced" resources, we use the below command: 

To display the "non-namespaced" resources, we use the below command:


Leave as a comment: