Keeping track of clusters

Tyler Williams
1 min readSep 25, 2020

One thing I struggled with initially while using Kubernetes (k8s from here on out, — lazy fingers) was knowing… what was running where? Because I wasn’t really proficient with the kubectl tool yet I was constantly poking around the GKE UI looking for my workload and pod and then logs, which was a really slow way to do things!

One of the first things that helped me was this little bash snippet to see and switch between all my GKE clusters. The “correct” way to do this is by using kubectl’s context functionality and configuring multiple clusters, but this is what I did before I knew about that :)

To use this snippet, just drop it in your .bashrc file and set the GKE_PROJECT variable correctly. Using it is as simple as typing “useCluster” at your command line: without arguments it will print all clusters, and if a cluster name is provided it will switch to that cluster. For example:

--

--