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?
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.
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.
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
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}}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With