I have a bunch of Kubernetes configurations on my machine. When I need to clean them up, I always forget the steps. This is just a note to myself, to remember how to clean up my kubectl config files.
juice :~ $ kubectx
arm64
build
clusterhat00
k3d-juice
korifi
luiki
mgmt
nucs
juice :~ $ kubectx luiki
Switched to context "luiki".
juice :~ $ kubectl get nodes -o wide
E0308 15:11:03.839634 89098 memcache.go:265] couldn't get current server API group list: Get "https://100.67.74.147:6443/api?timeout=32s": dial tcp 100.67.74.147:6443: i/o timeout
Starting with a context that doesn’t work.
Delete the cluster from the config file.
juice :~ $ kubectl config delete-cluster luiki
deleted cluster luiki from /Users/dashaun/.kube/config
juice :~ $ kubectx
arm64
build
clusterhat00
k3d-juice
korifi
luiki
mgmt
nucs
juice :~ $
I don’t think the order matters, but I start by deleting the cluster.
After deleting the cluster, the context still shows up in the list. So let’s delete the context.
juice :~ $ kubectl config delete-context luiki
deleted context luiki from /Users/dashaun/.kube/config
juice :~ $ kubectx
arm64
build
clusterhat00
k3d-juice
korifi
mgmt
nucs
juice :~ $
The context is gone.
If I tried to create a new context named luiki
I would get an error, because the user still exists.
So let’s delete the user from the config file.
juice :~ $ kubectl config delete-user luiki
deleted user luiki from /Users/dashaun/.kube/config
juice :~ $
The user is gone.
All done, I can create a new context named luiki
now.
If I want to simplify things for myself I might do something like this going forward:
K3SUP_NAME=luiki
kubectl config delete-cluster $K3SUP_NAME
kubectl config delete-context $K3SUP_NAME
kubectl config delete-user $K3SUP_NAME
This would be a good way to clean up after using
k3sup
to install a cluster.