kubernetes – How to keep the .kube/config tidy after deleting a cluster?

In Microsoft Windows, I’m finding that as I create and delete AKS clusters that my .kube/config file is accumulating context entries for things that I’ve deleted.

I’ve tried using the following commands, but afterwards I still find entries for the context in the .kube/config file despite the fact that kubectl does NOT list the context anymore.

kubectl config delete-context someContextNameHere
kubectl config unset contexts.someContextNameHere

Afterwards, using the kubectl config get-contexts command does show that they are gone, but entries for the deleted context are left behind in the .kube/config file.

Currently, my only solution is to delete everything using kubectl and then delete the config file or be brave and try to slice out the entries by hand.

Is there a way of using kubectl to keep this file free of unwanted context entries?

Read more here: Source link