K8S Tips and Scripts #2

I’m a big believer in “wrapper scripts”.

Wrapper Scripts

If available commands don’t do exactly what you want, don’t reinvent another wheel, bend what you have available to do what you want. Let the available tools do the “heavy lifting” while you just adjust to taste.

A great example of this is looking at node labels.

The kubectl command has a way to show the node labels, but too verbosely and not useful by itself in my opinion. But the information is there, so bend the output to something more useful!

When I want to see the node labels, I normally looking for specific labels, like the node group or node pool. Perhaps we want to confine pods to a certain group of nodes.

I created a script which will show only the labels you want to see, formatted in such a way that can be used by grep or even other scripts (which I’ll show in later articles).

This example shows a label I’m interested in.

$ nodelabels node-pool 
NAME           STATUS  ROLES  AGE  VERSION
10.255.255.109 Ready   node   11d  v1.23.5  node-pool=infra_1 
10.255.255.148 Ready   node   11d  v1.23.5  node-pool=websv_1 
10.255.255.158 Ready   node   11d  v1.23.5  node-pool=runtm_3 
10.255.255.169 Ready   node   11d  v1.23.5  node-pool=infra_1 
10.255.255.175 Ready   node   11d  v1.23.5  node-pool=runtm_7 
10.255.255.192 Ready   node   11d  v1.23.5  node-pool=poolx_1 
10.255.255.230 Ready   node   11d  v1.23.5  node-pool=runtm_5 
10.255.255.239 Ready   node   11d  v1.23.5  node-pool=infra_1 
10.255.255.243 Ready   node   11d  v1.23.5  node-pool=runtm_1 
10.255.255.250 Ready   node   11d  v1.23.5  node-pool=runtm_5 
..

The script is available here..

https://github.com/billduncan/nodelabels