How do I delete clusters and contexts from kubectl config?

前端 未结 4 1051
生来不讨喜
生来不讨喜 2021-01-30 00:49

kubectl config view shows contexts and clusters corresponding to clusters that I have deleted.

How can I remove those entries?

The command



        
相关标签:
4条回答
  • 2021-01-30 01:02

    Unrelated to question, but maybe a useful resource.

    Have a look at kubectx + kubens: Power tools for kubectl.

    They make it easy to switch contexts and namespace + have the option to delete

    e.g.,

    kubectx -d my-context
    
    0 讨论(0)
  • 2021-01-30 01:10

    For clusters and contexts you can also do

    kubectl config delete-cluster my-cluster
    
    kubectl config delete-context my-cluster-context
    

    There's nothing specific for users though, so you still have to do

    kubectl config unset users.my-cluster-admin
    
    0 讨论(0)
  • 2021-01-30 01:14

    kubectl config unset takes a dot-delimited path. You can delete cluster/context/user entries by name. E.g.

    kubectl config unset users.gke_project_zone_name
    
    kubectl config unset contexts.aws_cluster1-kubernetes
    
    kubectl config unset clusters.foobar-baz
    

    Side note, if you teardown your cluster using cluster/kube-down.sh (or gcloud if you use Container Engine), it will delete the associated kubeconfig entries. There is also a planned kubectl config rework for a future release to make the commands more intuitive/usable/consistent.

    0 讨论(0)
  • 2021-01-30 01:19

    Run command below to get all contexts you have:

    $ kubectl config get-contexts
    
    CURRENT   NAME             CLUSTER     AUTHINFO                                NAMESPACE
    
    *         Cluster_Name_1   Cluster_1   clusterUser_resource-group_Cluster_1
    

    Delete context:

     $ kubectl config delete-context Cluster_Name_1
    
    0 讨论(0)
提交回复
热议问题