How To Change The Default Namespace In Kubernetes

This blog post will show you how to change the default Kubernetes namespace using kubectl command line.

By default, When you set up an AKS or local Kubernetes cluster, the default namespace is set to the default namespace. This can be a pain if all your workloads are not in the default namespace.

Change Context

To set a default namespace on my cluster, I will use the following commands. In the below example, I am first listing all the contexts that are under my cluster using.

kubectl config get-contexts

My current context is called AKS, and I will set the namespace web as the default namespace with the following command.

kubectl config set-context AKS --namespace=web

If you need to delete a Kubernetes context you can use the following command.

kubectl config delete-context aks