如何通过 kubectl 查找节点的污点信息

问题描述 投票:0回答:2

我有多个获取污点信息的问题。我知道可以从这里获取污点信息:(查看当前节点上存在污点的现有污点。)

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

  • 上面是根据此链接中给出的文档,但是这是从哪里引用的?这是在哪里列出的?

    https://kubernetes.io/docs/reference/kubectl/cheatsheet/

  • 但是我如何发现污点在规范下。根据 kubectl 命令,“Taint”值仅出现在“kubectl描述节点”下,而不出现在“kubectl get node -o yaml”下。文件输出如下:

kubectl get node server.ec2.internal -o yaml > nodespecoutput.yaml
    name: server.ec2.internal
          resourceVersion: "..."
          uid: 3a6be337-f45d-4d88-95de-ce3a727fc89b
        spec:
          providerID: aws:///us-east-1b/i-0ba5c3380ed5e423e
        status:
          addresses:
          - address: 172.24.16.207
            type: InternalIP
kubectl describe node server.ec2.internal -o yaml > nodespecoutputdesc.yaml
volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Tue, 05 Jul 2022 16:17:44 -0600
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  server.ec2.internal
  AcquireTime:     <unset>
  RenewTime:       Thu, 03 Nov 2022 19:57:02 -0600
  • 我只能找到这个文档:(这里什么也没有。)

    https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#nodespec-v1-core

  • 我如何找出(证明)规范包含“污点”,要么是一些文档,要么是一些“--help”样式文档,要么是“-o yaml”的输出,要么是“-o json”的输出?

我尝试过使用kubectl“get”和“describe”。我也尝试过理解YAML结构,但它没有在那里列出,或者我可能会遗漏一些东西。

kubernetes kubectl
2个回答
0
投票

了解 Kubernetes 资源结构的一个好方法是通过一页 Kubernetes API 参考

  • 查找节点资源
  • 然后根据您的示例,查看
    spec
    下的类型
    NodeSpec
  • 看到
    taints
    是一个
    Taint
  • 的数组

然后,知道你可以

kubectl get {resource} --output
各种口味(我更喜欢
jsonpath
),你可以使用例如Kubernetes 使用的
JSONPath
实现(与其他地方的
JSONPath
不同)来过滤输出。

如果

JSONPath
过滤不够,您可以将结果通过管道传输到其他工具,例如
jq
.

如果您更喜欢使用 YAML,则需要

--output=yaml
,但
kubectl
不包含 YAML 输出的内置处理,因此您需要使用像
yq
这样的工具。

您还可以将

--v
(日志级别详细程度)添加到任何
kubectl
命令。
--v=6
(或以上)应包括为实现命令而进行的底层 Kubernetes API 调用。


0
投票

我将首先回答你的第二个要点,

  1. taints
    的值在所描述的输出和获取 YAML 输出中都可见。

仅供参考,在描述输出中,它将将该字段显示为

Taints
并在 yamls,它显示为
taints

。要查看该内容,请运行以下命令:

# This is the YAML of node
kubectl get node <node-name> -oyaml > node-get-output.yaml 

# This is the describe output of node
kubectl describe node <node-name> > node-describe-output.yaml

现在,在

get
的输出中,您会注意到:(粘贴演示 YAML)

spec:
  podCIDR: ....
  podCIDRs:
  - ...
  providerID: gce://.../us-central1-f/...
  taints:
  - effect: NoSchedule
    key: demo
    value: StackOverflow

describe
输出将如下所示:

Name:               ...
Roles:              ...
Labels:             beta.kubernetes.io/arch=amd64
              
Annotations:        container.googleapis.com/instance_id: ...
                 
CreationTimestamp:  ...
Taints:             demo=StackOverflow:NoSchedule
Unschedulable:      false
  1. 这是 kubernetes 的一个概念,对于每个 Kubernetes 对象,所有配置内容都将位于 YAML 的
    spec
    部分下,您也可以参考文档,污点也位于其下。您还可以使用 kubectl 实用程序查看它,其输出包含
    spec
    :
  2. 下的所有属性
kubectl explain node.spec
© www.soinside.com 2019 - 2024. All rights reserved.