kubectl >= 1.5.x
kubectl version --client
Client Version: version.Info{Major:"1", Minor:"23", GitVersion:"v1.23.1", GitCommit:"86ec240af8cbd1b60bcc4c03c20da9b98005b92e", GitTreeState:"clean", BuildDate:"2021-12-16T11:33:37Z", GoVersion:"go1.17.5", Compiler:"gc", Platform:"darwin/amd64"}
In versions of kubectl less than 1.5, an error occurs because the kubectl config get-users
command cannot be found among the execution contents.
When k8s Contexts are not matched to Clusters or Users like below:
(i.e. if you remove contexts, clusters & users cannot remove automatically)
$ kubectl config get-contexts
CURRENT NAME CLUSTER AUTHINFO NAMESPACE
aks aks clusterUser_res_aks default
eks arn:aws:eks:us-east-2:443308097684:cluster/eks arn:aws:eks:us-east-2:443308097684:cluster/eks
gke gke_hj-int-20200908_us-central1-c_gke gke_hj-int-20200908_us-central1-c_gke
nks kubernetes kubernetes-admin
$ kubectl config get-clusters
NAME
aks
arn:aws:eks:us-east-2:443308097684:cluster/eks
gke_20200512_us-central1-c_beer
gke_20200512_us-central1-c_bread
gke_20200512_us-central1-c_coffee
gke_hj-int-20200908_us-central1-c_gke
kubernetes
$ ctx-cleaner
deleted cluster gke_20200512_us-central1-c_beer from /Users/mz01-hj/.kube/config
deleted cluster gke_20200512_us-central1-c_bread from /Users/mz01-hj/.kube/config
deleted cluster gke_20200512_us-central1-c_coffee from /Users/mz01-hj/.kube/config
deleted user gke_20200512_us-central1-c_beer from /Users/mz01-hj/.kube/config
deleted user gke_20200512_us-central1-c_bread from /Users/mz01-hj/.kube/config
deleted user gke_20200512_us-central1-c_coffee from /Users/mz01-hj/.kube/config
$ curl https://raw.githubusercontent.com/sysnet4admin/kubefin/main/kubefin <namespace's name>| bash
Since ctx-cleaner is written in Bash, you should be able to install them to any POSIX environment that has Bash installed
- Download the
ctx-cleaner
scripts. - Either:
- save them all to somewhere in your
PATH
, - or save them to a directory, then create symlinks to
ctx-cleaner
from somewhere in yourPATH
, like/usr/local/bin
- save them all to somewhere in your
- Make
ctx-cleaner
executable (chmod +x ...
)
Example installation steps:
$ sudo git clone https://github.com/sysnet4admin/ctx-cleaner.git /opt/ctx-cleaner
$ sudo ln -s /opt/ctx-cleaner /usr/local/bin/ctx-cleaner
OR
$ curl https://raw.githubusercontent.com/sysnet4admin/kubefin/main/kubefin -o /usr/local/bin/ctx-cleaner
$ chmod +x /usr/local/bin/ctx-cleaner
$ rm -rf /opt/ctx-cleaner
$ rm -f /usr/local/bin/ctx-cleaner