kubectl Displaying Taints

One of the questions in my CKA exam was how to display taints with kubectl. While you can use kubectl describe, it creates a lot of other information too.

Then I found out about jsonpath and it’s similarity to jq

You can display the taints with something like

for a in $(kubectl get nodes --no-headers | awk '{print $1}')
do
echo $a -- $(kubectl get nodes/$a -o jsonpath='{.spec.taints[*].key}{":"}{.spec.taints[*].effect}')
done

Sample output

ip-10-10-10-147.eu-west-2.compute.internal -- node-role.kubernetes.io/master:NoSchedule
ip-10-10-10-159.eu-west-2.compute.internal -- :

So the first one has a taint (it’s the master node) and the second one doesn’t.
(maybe I need to hack this a bit more when I have multiple taints but I’ll do that when I have some multi-tainted nodes to play with)

 

%d bloggers like this: