Minikube’s default namespace is default, but you can change it for your current context using kubectl config set-context.
Let’s see it in action. First, check your current context’s namespace:
kubectl config view --minify | grep namespace
You’ll likely see something like:
namespace: default
Now, let’s switch the default namespace for your current context to kube-system. This is useful if you want to run commands that target system-level components without explicitly specifying the namespace each time.
kubectl config set-context --current --namespace=kube-system
Run the previous command again to verify the change:
kubectl config view --minify | grep namespace
This time, you should see:
namespace: kube-system
Now, any kubectl command you run without a --namespace flag will operate within the kube-system namespace. For example, listing pods:
kubectl get pods
This will show you pods only in kube-system, not in default or any other namespace.
To switch back to the default namespace:
kubectl config set-context --current --namespace=default
And verify:
kubectl config view --minify | grep namespace
Output:
namespace: default
The key to understanding this is that kubectl config set-context modifies your ~/.kube/config file. It doesn’t create new namespaces or change anything within the Kubernetes cluster itself; it only alters how your kubectl client interacts with the cluster by default. The --current flag ensures you’re modifying the context you’re actively using.
You can also set a namespace for a specific context without making it the current one:
kubectl config set-context my-minikube-context --namespace=my-custom-namespace
This is handy if you manage multiple clusters or contexts and want to pre-configure namespaces for each.
The --minify flag with kubectl config view is a shortcut to show only the current context’s configuration, making it easier to spot the namespace setting without parsing the entire config file.
If you ever forget which namespace your current context is set to, kubectl config view --minify | grep namespace is your go-to command.
While setting the default namespace for your context is convenient, remember that for production-level Kubernetes operations, explicitly specifying namespaces in your commands or using separate configuration files for different environments is often a more robust practice to avoid accidental modifications of critical system namespaces.
The next concept to explore is how to create and manage your own custom namespaces within Minikube.