How can I list the taints on Kubernetes nodes?

前端 未结 11 1533
别那么骄傲
别那么骄傲 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:06

    To find taints of node can just run:

    kubectl describe nodes your-node-name
    

    Output:

    Name:                   your-node-name
    ...
    Taints:                 node-role.kubernetes.io/master:NoSchedule
    CreationTimestamp:      Wed, 19 Jul 2017 06:00:23 +0800
    
    0 讨论(0)
  • 2021-01-30 09:09

    Try this one:

        kubectl get nodes -o=custom-columns=NAME:.metadata.name,TAINTS:.spec.taints
    
    0 讨论(0)
  • 2021-01-30 09:11

    You can use kubectl's go-template output options to help you here,

    kubectl get nodes -o go-template='{{range .items}}{{if $x := index .metadata.annotations "scheduler.alpha.kubernetes.io/taints"}}{{with $x := index .metadata.name}}{{.}}{{printf "\n"}}{{end}}{{end}}{{end}}'

    On my cluster, this prints my masters, which are tainted:

    kubemaster-1.example.net
    kubemaster-2.example.net
    kubemaster-3.example.net
    
    0 讨论(0)
  • 2021-01-30 09:13

    The CMD kubectl provides an arguments jsonpath to search and format the output after getting. You can check the doc k8s jsonpath for detail.

     kubectl get node  -o=jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.taints}{"\n"}{end}'
    

    For further info, you can check the source code that reflect the source data with the method FindResults

    0 讨论(0)
  • 2021-01-30 09:16
    #Check Node Taints
    kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect
    

    Let me try and explain what this first one means and then rest should fall in place:

    NodeName:.metadata.name

    ColumnName: JSONPATH to the attribute you are looking for.

    ColumnName can be anything you want it to be.

    Something like NodeName:items[*].metadata.name is equivalent to running $kubectl get nodes -o=jsonpath='{.items[*].metadata.name}' but with custom-columns flag you get values in rows and columns format.

    Note: You don't need to start with .items[*]. It already parses that with custom-column flag

    so now all the columns explained:

    NodeName:.metadata.name - Get Node Names and put it under NodeName Column

    TaintKey:.spec.taints[*].key - return all the keys for taints by looking under taints map and put it under TaintKey custom-column

    TaintValue:.spec.taints[*].value - same as key but you are returning the value from the taints map.

    TaintEffect:.spec.taints[*].effect - same as key but you are returning the effect from the taints map.

    You set it under and alias like

    alias get-nodetaints="kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect"
    

    and you have your own nice command to get all taints and your output should look something like below

    sample output for the command

    0 讨论(0)
  • 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}}'
    
    0 讨论(0)
提交回复
热议问题