How to extract the list of nodes which are tainted

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version:1.15
Cloud being used: (put bare-metal if not on a public cloud)
Installation method: kubeadm
Host OS: linux
CNI and version:
CRI and version:

How to extract the list of nodes which are tainted. Unable to find node name when using jsonpath as “effect:NoSchedule” or viceversa in the Kubernetes command line

May be try this,

kubectl get nodes -o go-template=’{{range $item := .items}}{{with nodename := item.metadata.name}}{{range $taint := $item.spec.taints}}{{if and (eq $taint.key “node-role.kubernetes.io/master”) (eq $taint.effect “NoSchedule”)}}{{printf “%s\n” $nodename}}{{end}}{{end}}{{end}}{{end}}’

kubectl get nodes -o go-template=’{{range $item := .items}}{{with nodename := item.metadata.name}}{{range $taint := $item.spec.taints}}{{if and (ne $taint.key “node-role.kubernetes.io/master”) (ne $taint.effect “NoSchedule”)}}{{printf “%s\n” $nodename}}{{end}}{{end}}{{end}}{{end}}’

kubectl get nodes -o go-template=’{{range $item := .items}}{{with $nodename := $item.metadata.name}}{{range $taint := $item.spec.taints}}{{if and (eq $taint.key “node-role.kubernetes.io/master”) (eq $taint.effect “NoSchedule”)}}{{printf “%s\n” $nodename}}{{end}}{{end}}{{end}}{{end}}’

Corrected one

3 Likes

To get list of taint nodes

kubectl get nodes -o go-template=’{{range $item := .items}}{{with $nodename := $item.metadata.name}}{{range $taint := $item.spec.taints}}{{if (eq $taint.effect “NoSchedule”)}}{{printf “%s\n” $nodename}}{{end}}{{end}}{{end}}{{end}}’

replace ’ with ’ in command line

I am not understand what it meaning {replace ’ with ’ in command line} in the previous comment @Klearner

Best answer I got is this using jsonpath though

kubectl get nodes -o jsonpath=’{.items[].spec.taints[?(@.effect==“NoSchedule”)].effect}{"\t"}{.items[].metadata.name}’ | cut -f 2,3

This is my answer:

kubectl get nodes -o jsonpath=’{range .items[]}{.metadata.name}{"\t"}{.spec.taints[].effect}{"\n"}{end}’

Hello, mason1762
Are you sure it will work for all nodes?

you can use this one

kubectl get nodes -o jsonpath="{range .items[*]}{.metadata.name} {.spec.taints[?(@.effect=='NoSchedule')].effect}{\"\n\"}{end}"