如何列出节点上的污点?

时间:2017-04-12 20:50:39

标签: kubernetes

docs非常适合解释如何在节点上设置污点或删除节点。我可以使用kubectl describe node来获得一个节点的详细描述,包括它的污点。但是,如果我忘记了我创建的污点的名称,或者我设置了哪些节点,该怎么办?我可以列出我的所有节点,它们上面存在任何污点吗?

12 个答案:

答案 0 :(得分:23)

在Kubernetes 1.6.x中,节点污点已进入规范。因此jaxxstorm的上述答案将无效。相反,您可以使用以下模板。

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

我已将其保存到文件中,然后像这样引用它:

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

你会得到这样的输出:

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

我不是一个很棒的模板用户,所以我确信有一些事情我可以做得更好但它就是它。

与上述相同,但都在一行中:

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

答案 1 :(得分:11)

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

这将提供带有节点名称的完整规范,或者:

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

将生成每个节点的污点列表

答案 2 :(得分:9)

要查找节点的污点,只需运行:

kubectl describe nodes your-node-name

输出:

Name:                   your-node-name
...
Taints:                 node-role.kubernetes.io/master:NoSchedule
CreationTimestamp:      Wed, 19 Jul 2017 06:00:23 +0800

答案 3 :(得分:2)

我希望获得具有特定污点的节点列表。我只找到了这个答案,所以如果有人在寻找这个答案,这就是解决方案:

private void OnRepositoryPartitariValidating(object sender, CancelEventArgs e)
    {
        var objConto = gridView.GetFocusedRowCellValue("Conto");
        if (((sender as TextEdit).EditValue) is Partitario) return;
        var codice = (sender as TextEdit).EditValue.ToString();
        var partitario = Partitario.Manager.GetByCodice(codice);
        if (partitario == null)
        {
            e.Cancel = true;
            if (objConto is Conto)
                using (ListPartitari form = new ListPartitari((Conto)objConto))
                {

                    form.FnOk += delegate (object item)
                    {
                        if (item is Partitario)
                        {
                            (sender as TextEdit).EditValue = item;

                            e.Cancel = false;
                        }
                    };
                    form.ShowDialog(this);
                }
            else
                using (ListPartitari form = new ListPartitari())
                {

                    form.FnOk += delegate (object item)
                    {
                        if (item is Partitario)
                        {
                            (sender as TextEdit).EditValue = item;
                            e.Cancel = false;
                        }
                    };
                    form.ShowDialog(this);
                }
        }
        else
        {
            (sender as TextEdit).EditValue = partitario;
            //if (partitario.Conto.Id != ((Conto)objConto).Id)
            //    gridView.SetFocusedRowCellValue("Conto", partitario.Conto);

        }
    }

在我的群集上,输出为:

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

答案 4 :(得分:1)

您可以使用Task<String>的go-template输出选项来帮助您,

interface{}

在我的群集上,这会打印出受污染的主人:

kubectl

答案 5 :(得分:1)

CMD kubectl提供了一个参数jsonpath,以在获取后搜索和格式化输出。您可以查看文档k8s jsonpath以获得详细信息。

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

有关更多信息,您可以使用FindResults方法来检查反映源数据的source code

答案 6 :(得分:1)

kubectl describe nodes [node_name] | grep 'Taints'

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

->这最后一步将需要安装jq(sudo apt install jq)

答案 7 :(得分:1)

不使用任何其他工具(例如JQ)的最简单方法是使用custom-columns输出选项。

$ kubectl get nodes -o custom-columns=NAME:.metadata.name,TAINTS:.spec.taints --no-headers 

输出:

master-11   [map[effect:PreferNoSchedule key:node-role.kubernetes.io/master]]
master-12   [map[effect:PreferNoSchedule key:node-role.kubernetes.io/master]]
master-13   [map[effect:PreferNoSchedule key:node-role.kubernetes.io/master]]

使用Taints之类的东西作为地图或列表,并且您希望它看起来很干净以便与其他工具一起解析,您可以使用与Edwin Tai的答案类似的东西进行清理,但需要一些额外的技巧提取密钥。

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

输出:

master-11   node-role.kubernetes.io/master
master-12   node-role.kubernetes.io/master
master-13   node-role.kubernetes.io/master
worker-21   thegoldfish.org/storage thegoldfish.org/compute
worker-22   thegoldfish.org/storage thegoldfish.org/compute
worker-23   thegoldfish.org/compute
worker-24   thegoldfish.org/storage thegoldfish.org/compute

其他示例:

使用此方法,您可以轻松创建自定义输出

节点快速概述:

kubectl get nodes -o custom-columns=NAME:.metadata.name,ARCH:.status.nodeInfo.architecture,KERNEL:.status.nodeInfo.kernelVersion,KUBLET:.status.nodeInfo.kubeletVersion,CPU:.status.capacity.cpu,RAM:.status.capacity.memory

输出:

NAME        ARCH    KERNEL                       KUBLET    CPU   RAM
master-11   amd64   3.10.0-1062.9.1.el7.x86_64   v1.17.0   6     7910096Ki
master-12   amd64   3.10.0-1062.9.1.el7.x86_64   v1.17.0   6     7910096Ki
master-13   amd64   3.10.0-1062.9.1.el7.x86_64   v1.17.0   6     7910096Ki

吊舱概述以及在何处可以找到它们,按创建时间排序:

kubectl get pods -A -o custom-columns=NAMESPACE:.metadata.namespace,NAME:.metadata.name,NODE:.spec.nodeName,HOSTIP:.status.hostIP,PHASE:.status.phase,START_TIME:.metadata.creationTimestamp --sort-by=.metadata.creationTimestamp

输出:

NAMESPACE              NAME                                                  NODE        HOSTIP            PHASE       START_TIME
kube-system            kube-proxy-rhmrz                                      master-11   192.168.121.108   Running     2019-12-26T14:22:03Z
kube-system            coredns-6955765f44-777v9                              master-11   192.168.121.108   Running     2019-12-26T14:22:03Z
kube-system            coredns-6955765f44-w7rch                              master-11   192.168.121.108   Running     2019-12-26T14:22:03Z
kube-system            kube-scheduler-master-11                              master-11   192.168.121.108   Running     2019-12-26T14:22:05Z
kube-system            kube-controller-manager-master-11                     master-11   192.168.121.108   Running     2019-12-26T14:22:05Z
kube-system            etcd-master-11                                        master-11   192.168.121.108   Running     2019-12-26T14:22:05Z
kube-system            kube-apiserver-master-11                              master-11   192.168.121.108   Running     2019-12-26T14:22:05Z
kube-system            calico-node-sxls8                                     master-11   192.168.121.108   Running     2019-12-26T14:55:41Z
kube-system            calico-kube-controllers-6d85fdfbd8-dnpn4              master-11   192.168.121.108   Running     2019-12-26T14:55:41Z
kubernetes-dashboard   dashboard-metrics-scraper-76585494d8-jx9cg            master-11   192.168.121.108   Running     2019-12-26T16:10:16Z
kubernetes-dashboard   kubernetes-dashboard-5996555fd8-5z5p2                 master-11   192.168.121.108   Running     2019-12-26T16:10:16Z

此文档为https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns

答案 8 :(得分:0)

  

PowerShell:\> kubectl描述节点| findstr“ Taint主机名”

  

Bash#kubectl描述节点| egrep“ Taint |主机名”

此命令非常容易记住

输出看起来像这样:

Taints:             <none>  
  Hostname:   aks-agentpool-30208295-0  
Taints:             <none>    
  Hostname:  aks-agentpool-30208295-1
...

答案 9 :(得分:0)

尝试这个:

    kubectl get nodes -o=custom-columns=NAME:.metadata.name,TAINTS:.spec.taints

答案 10 :(得分:0)

#Check Node Taints
kubectl get nodes -o=custom-columns=NodeName:.metadata.name,TaintKey:.spec.taints[*].key,TaintValue:.spec.taints[*].value,TaintEffect:.spec.taints[*].effect

让我尝试解释一下这第一个含义,然后休息一下:

节点名称:.metadata.name

ColumnName:要查找的属性的JSONPATH。

ColumnName可以是您想要的任何名称。

类似于 NodeName:items [*]。metadata.name 的东西等效于运行 $ kubectl get节点-o = jsonpath ='{。items [*]。metadata.name} ,但是带有自定义列标志,您可以获取行和列格式的值。

注意:您不需要以.items [*]开头。它已经使用自定义列标志对此进行了解析

所以现在所有列都进行了解释:

NodeName:.metadata.name -获取节点名称并将其放在NodeName列下

TaintKey:.spec.taints [*]。key -通过在污点图下查看并将其放置在TaintKey自定义列下返回污点的所有键

TaintValue:.spec.taints [*]。value -与键相同,但是您正在从taints映射中返回该值。

TaintEffect:.spec.taints [*]。effect -与key相同,但是您要从taints贴图返回效果。

您将其设置为别名,如

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

并且您拥有自己的漂亮命令来获取所有污点,并且您的输出应类似于以下内容

sample output for the command

答案 11 :(得分:0)

以下命令对我有用:

  1. 如果你有节点IP,你可以试试

kubectl get node $node_ip -o json | jq '.spec.taints'
Output:
[
  {
    "effect": "NoSchedule",
    "key": "dedicated"
  }
]

(OR)

kubectl describe node $node_ip  | grep -i Taints
Output:
Taints:             dedicated:NoSchedule

  1. 获取命名空间上的所有污点配置

kubectl get nodes -o json | jq '.items[].spec.taints'
Output:
[
  {
    "effect": "NoSchedule",
    "key": "dedicated"
  }
]