JSONPath to list all nodes in ready state except the ones which are tainted?

11/4/2019

I want to list all nodes which are in ready state except the ones which have any kind of taint on them. How can I achieve this using jsonpath ?

I tried below statement taken from k8s doc but it doesn't print what I want. I am looking for output such as -- node01 node02. There is no master node in the output as it has a taint on it. What kind of taint is not really significant here.

JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}' \
 && kubectl get nodes -o jsonpath="$JSONPATH" | grep "Ready=True"
-- Naxi
kubernetes

1 Answer

11/5/2019

I have successfully listed my nodes that are ready and not tainted using jq.

Here you have all the nodes:

$ kubectl get nodes

gke-standard-cluster-1-default-pool-9c101360-9lvw   Ready    <none>   31s   v1.13.11-gke.9
gke-standard-cluster-1-default-pool-9c101360-fdhr   Ready    <none>   30s   v1.13.11-gke.9
gke-standard-cluster-1-default-pool-9c101360-gq9c   Ready    <none>   31s   v1.13.11-gke.

Here I have tainted one node:

$ kubectl taint node gke-standard-cluster-1-default-pool-9c101360-9lvw key=value:NoSchedule

node/gke-standard-cluster-1-default-pool-9c101360-9lvw tainted

And finally a command that list the not tainted and ready nodes:

$ kubectl get nodes -o json | jq -r '.items[] | select(.spec.taints|not) | select(.status.conditions[].reason=="KubeletReady" and .status.conditions[].status=="True") | .metadata.name'

gke-standard-cluster-1-default-pool-9c101360-fdhr
gke-standard-cluster-1-default-pool-9c101360-gq9c
-- acid_fuji
Source: StackOverflow