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
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
4 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}"
2 Likes
kubectl get nodes -o jsonpath=’{.items.spec.taints[*].effect}’
kubectl get node -o custom-columns=NAME:.metadata.name,TAINT:.spec.taints[*].effect
Please try this one:
for kube_node in $(kubectl get nodes | awk '{ print $1 }' | tail -n +2); do
echo ${kube_node} $(kubectl describe node ${kube_node} | grep Taint);
done
2 Likes
Here’s a simple kubectl command to list all nodes that have taints in place.
k get nodes -o jsonpath='{$.items[?(@.spec.taints)].metadata.name}{"\n"}'
and the below command to lsit all nodes that doesn’t have taints in place. You need to have jq
command line utility installed for this to work.
k get nodes -o json | jq '.items[] | select(.spec.taints | not) | .metadata.name'