Switching Namespaces Using the kubectl Command
Kubernetes namespace provides the isolation for the different types of resources within the cluster you can use the following command to switch the namespace in the Kubernetes cluster,
kubectl config set-context ācurrent ānamespace=<desired-namespace>
- kubectl: Kubectl is a command-line interface (CLI) tool for interacting with Kubernetes clusters.
- config: This is a subcommand of kubectl used for managing kubeconfig files. Kubernetes uses a kubeconfig file to store information about clusters, users, and contexts.
- set-context: This is another subcommand of the kubectl config used to modify the current context in the kubeconfig file.
- ācurrent: This flag specifies that you want to modify the current context in the kubeconfig file. The current context is the set of cluster, user, and namespace information that kubectl uses by default for executing commands.
- ānamespace=<desired-namespace>: This flag sets the namespace to the specified <desired-namespace>. Replace <desired-namespace> with the name of the namespace you want to switch to.
Steps To Switch Namespace
Step 1: List all the namespaces in Kubernetes.
kubectl get namespaces
Step 2: Select the namespace that you want to switch to and want to set it as a default and use the command shown in below. Here I am using ākube-publicā.
Step 3: Know get the current namespace you are in using the given command below.
kubectl config view | grep namespace:
How to Change Namespace in Kubernetes ?
Kubernetes namespaces offer an indispensable instrument for resource organization and isolation in the ever-changing realm of container orchestration. Like distinct districts in a busy metropolis, each namespace in your Kubernetes cluster serves as a dedicated place where you may organize related storage, services, and applications into logical units.
Contact Us