Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list the taints on Kubernetes nodes?

Tags:

kubernetes

The docs are great about explaining how to set a taint on a node, or remove one. And I can use kubectl describe node to get a verbose description of one node, including its taints. But what if I've forgotten the name of the taint I created, or which nodes I set it on? Can I list all of my nodes, with any taints that exist on them?

like image 599
Chris Jones Avatar asked Apr 12 '17 20:04

Chris Jones


People also ask

What is taints in Kubernetes?

Node affinity is a property of Pods that attracts them to a set of nodes (either as a preference or a hard requirement). Taints are the opposite -- they allow a node to repel a set of pods. Tolerations are applied to pods. Tolerations allow the scheduler to schedule pods with matching taints.

How do I view pod config?

To view the entire configuration of the pod, just run kubectl describe pod nginx in your terminal. The terminal will now display the YAML for the pod, starting with the name nginx, its location, the Minikube node, start time and current status.


2 Answers

kubectl get nodes -o json | jq '.items[].spec' 

which will give the complete spec with node name, or:

kubectl get nodes -o json | jq '.items[].spec.taints' 

will produce the list of the taints per each node

like image 155
kranthi guttikonda Avatar answered Oct 08 '22 16:10

kranthi guttikonda


In Kubernetes 1.6.x the node taints have moved into the spec. Therefore the above answer by jaxxstorm will not work. Instead, you can use the following template.

{{printf "%-50s %-12s\n" "Node" "Taint"}} {{- range .items}}     {{- if $taint := (index .spec "taints") }}         {{- .metadata.name }}{{ "\t" }}         {{- range $taint }}             {{- .key }}={{ .value }}:{{ .effect }}{{ "\t" }}         {{- end }}         {{- "\n" }}     {{- end}} {{- end}} 

I have that saved into a file and then reference it like so:

kubectl get nodes -o go-template-file="./nodes-taints.tmpl" 

You'll get output like so:

Node                                            Taint ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=etcd:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=jenkins:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=etcd:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=containerlinux-canary-channel-workers:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=jenkins:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=etcd:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=etcd:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=etcd:NoSchedule ip-xxx-xxx-xxx-xxx.us-west-2.compute.internal   dedicate=jenkins:NoSchedule 

I'm not a huge go template user so I'm sure there are some things I could have done better but it is what it is.


Same as above but all in one line:

kubectl get nodes -o go-template='{{printf "%-50s %-12s\n" "Node" "Taint"}}{{- range .items}}{{- if $taint := (index .spec "taints") }}{{- .metadata.name }}{{ "\t" }}{{- range $taint }}{{- .key }}={{ .value }}:{{ .effect }}{{ "\t" }}{{- end }}{{- "\n" }}{{- end}}{{- end}}' 
like image 41
Brett Wagner Avatar answered Oct 08 '22 16:10

Brett Wagner