A context in Kubernetes is basically a combination of an information about clusters and users, stored in a kubeconfig file.
Every time you execute the kubectl command, you reference a context inside kubeconfig.
The kubectl config command is used to manage Kubernetes configurations, primarily by editing the kubeconfig file.
In this short note I will show how to delete a Kubernetes context, cluster or user from kubeconfig using the kubectl config command.
Cool Tip: Delete all Pods in a specific Namespace using kubectl! Read more →
Kubectl: Delete Context | Cluster | User
Kubectl Delete Context
Display contexts from the kubeconfig file:
$ kubectl config get-contexts
To delete the specified context from the kubeconfig, execute:
$ kubectl config delete-context <contextName>
Kubectl Delete Cluster
Display clusters from the kubeconfig file:
$ kubectl config get-clusters
To delete the specified cluster from the kubeconfig, execute:
$ kubectl config delete-cluster <clusterName>
Kubectl Delete User
Display users from the kubeconfig file:
$ kubectl config get-users
To delete the specified user from the kubeconfig, execute:
$ kubectl config delete-user <userName>
Cool Tip: Forcefully delete K8s resources (Pods, Deployments, Services, etc.) stuck in a “Terminating” or “Unknown” state using kubectl! Read more →