Home

Awesome

kubetrim 📏

Trim 📏 your KUBECONFIG automatically.

Sponsor Alex build License: MIT Downloads

kubetrim tidies up old and broken cluster and context entries from your kubeconfig file.

It works like this:

  1. Loads the config specified by KUBECONFIG
  2. Tries to connect to each
  3. Writes a new file with only the ones that it could access

Q&A:

Usage

$ kubectx

default
do-lon1-openfaas-cluster
kind-2
kind-ingress

$ kubetrim

kubetrim (dev) by Alex Ellis 

Loaded: /home/alex/.kube/config. Checking..
  - kind-2: ✅
  - kind-ingress: ❌ - (failed to connect to cluster: Get "https://127.0.0.1:40349/api/v1/nodes": dial tcp 127.0.0.1:40349: connect: connection refused)
  - default: ✅
  - do-lon1-openfaas-cluster: ❌ - (failed to connect to cluster: Get "https://da39a3ee5e6b4b0d3255bfef95601890afd80709.k8s.ondigitalocean.co.uk/api/v1/nodes": dial tcp: lookup da39a3ee5e6b4b0d3255bfef95601890afd80709.k8s.ondigitalocean.co.uk on 127.0.0.53:53: no such host)
Updated: /home/alex/.kube/config (in 364ms).

$ kubectx

default
kind-2

Try out kubetrim without writing changes to the kubeconfig file:

$ kubetrim --write=false

Use a different kubeconfig file:

$ KUBECONFIG=$HOME/.kube/config.bak kubetrim

What if the Internet is unavailable, and all clusters report as unavailable?

# Take down WiFi/Ethernet

$ kubetrim

No contexts are working, the Internet may be down, use --force to delete all contexts anyway.

# Force the deletion, even if all clusters are unavailable.

$ kubetrim --force

Installation

Getting kubetrim with arkade:

curl -sfLS https://get.arkade.dev | sh

arkade get kubetrim

Or download it manually via the Releases page

License

MIT license