How can I list the taints on Kubernetes nodes?

前端 未结 11 1552
别那么骄傲
别那么骄傲 2021-01-30 08:47

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, inclu

11条回答
  •  悲哀的现实
    2021-01-30 09:17

    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}}'
    

提交回复
热议问题