To use the
-
Install
kubectl : If you haven’t already, installkubectl on your machine. You can find installation instructions for your operating system on the Kubernetes documentation website. -
View the current context: To see the current context, which represents the cluster, user, and namespace that
kubectl is currently configured to use, run the following command:kubectl config current-context
-
View the available contexts: To see a list of available contexts, which represent different Kubernetes clusters, users, and namespaces that
kubectl can be configured to use, run the following command:kubectl config get-contexts
-
Switch the active context: To switch to a different context, use the
use-context subcommand followed by the name of the context. For example, if you have a context named “my-cluster”, run the following command to switch to that context:kubectl config use-context my-cluster
-
Set the default namespace: If you want to set a default namespace for
kubectl to use, you can use theset-context subcommand. For example, to set the default namespace to “my-namespace”, run the following command:kubectl config set-context --current --namespace=my-namespace
-
View and edit configuration files: The
kubectl config command also allows you to view and edit the configuration files used bykubectl . The configuration files are typically located in the~/.kube directory. You can view the current configuration file by running:kubectl config view
To edit the configuration file, you can use a text editor to modify the file directly.
That’s it! You have now used the