Skip to content

sysnet4admin/ctx-cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ctx-cleaner: Easy to clean up garbage on contexts

version Proudly written in Bash License

ctx-cleaner DEMO

ctx-cleaner-demo GIF


Environment

kubectl >= 1.20.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.20, an error occurs because the kubectl config get-users command cannot be found among the execution contents.

Purpose

When k8s Contexts are not matched to Clusters or Users like below:
(i.e. if you remove contexts, clusters & users cannot remove automatically)

k8s Contexts

$ 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

k8s Clusters

$ 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

Usage

$ 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

Installation

Add other method later

One time runner

curl https://raw.githubusercontent.com/sysnet4admin/ctx-cleaner/main/ctx-cleaner | bash

Installation (macOS and Linux)

curl https://raw.githubusercontent.com/sysnet4admin/ctx-cleaner/main/ctx-cleaner/install | bash 

Uninstall ctx-cleaner

curl https://raw.githubusercontent.com/sysnet4admin/ctx-cleaner/main/ctx-cleaner/uninstall | bash 

About

Quick clean up garbage k8s cluster & user information.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages