Faster Kubernetes Commands

John Jung
2 min readOct 22, 2018

--

Sometimes you’re working with your kubernetes cluster and you want quick and easy ways to do things, here are some of my favorite commands I’ve aliased.

Quick Kubernetes Cluster Switches

figlet DEVELOPMENT KUBERNETES; kub config use-context kubernetes-context; title 'DEV KUBERNETES';export KUBECONFIG=~/.kube/dev-kubeconfig

Broken down:

figlet allows you to make pretty ascii art

kub is my shorthand for kubectl

title this lets you change the title of your terminal window

export lets you set this for that terminal window the kubeconfig you want

brew install figlet

Then use figlet kubernetes name

kubernetes name

I use figlet soI know for sure I’m on the right cluster. Especially when you’re managing more than one cluster or if you have a dev cluster.

I usually store my kubeconfig files in ~/.kube to keep it nice and organized and alias that command so I can quickly switch between clusters and get stuff done!

Clean your evicted pods

Before:

So many Evicted pods
kubectl get pods | grep Evicted | awk '{print $1}' | xargs kubectl delete pod
kub-clean

After

Ahhh no more evicted pods crowding up your space

I usually alias this to something like kub-clean

Quick Debugging Pod

kubectl run debug --image=ubuntu: -- bash -c "sleep 1000000;"

This pod keeps your pod running and you can go in and do some networking tests to hit your services, maybe db’s, etc…

kubectl exec -it podname bash

Then you’re essentially ssh’d in and you can do whatever you want here

So these are some of our tricks that we use to quickly help us navigate around Kubernetes, hope it helped!

--

--