Skip to content

Instantly share code, notes, and snippets.

@ssro
Last active May 31, 2025 13:30
Show Gist options
  • Select an option

  • Save ssro/2f47d1189bd3b391897c11e445cee93a to your computer and use it in GitHub Desktop.

Select an option

Save ssro/2f47d1189bd3b391897c11e445cee93a to your computer and use it in GitHub Desktop.

Remove clusters, contexts and users from kubeconfig

Assuming your config file is at $KUBECONFIG (default ~/.kube/config) follow these steps to remove clusters/contexts/users from it:

  • get clusters and contexts in the config
$ kubectl config get-contexts

CURRENT   NAME                  CLUSTER                                                               AUTHINFO                                                              NAMESPACE
*         development-cluster   arn:aws:eks:sp-antarctica-1:012345678901:cluster/development-cluster  arn:aws:eks:sp-antarctica-1:012345678901:cluster/development-cluster  default
          production-cluster    arn:aws:eks:sp-antarctica-1:098765432109:cluster/production-cluster   arn:aws:eks:sp-antarctica-1:098765432109:cluster/production-cluster   default

Under NAME is the context name, under CLUSTER is the cluster name, very straightforward

  • remove a cluster/context/user
$ kubectl config delete-cluster arn:aws:eks:sp-antarctica-1:012345678901:cluster/development-cluster
$ kubectl config delete-context development-cluster
$ kubectl config unset users.arn:aws:eks:sp-antarctica-1:012345678901:cluster/development-cluster
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment