搜索

12.2. 使用污点和容限来控制日志记录 pod 放置

download PDF

通过污点和容限,节点可以控制哪些 pod 应该(或不应该)调度到节点上。

12.2.1. 了解污点和容限

通过使用污点(taint),节点可以拒绝调度 pod,除非 pod 具有匹配的容限(toleration)

您可以通过节点规格(NodeSpec)将污点应用到节点,并通过 Pod 规格(PodSpec)将容限应用到 pod。当您应用污点时,调度程序无法将 pod 放置到该节点上,除非 pod 可以容限该污点。

节点规格中的污点示例

apiVersion: v1
kind: Node
metadata:
  name: my-node
#...
spec:
  taints:
  - effect: NoExecute
    key: key1
    value: value1
#...

Pod 规格中的容限示例

apiVersion: v1
kind: Pod
metadata:
  name: my-pod
#...
spec:
  tolerations:
  - key: "key1"
    operator: "Equal"
    value: "value1"
    effect: "NoExecute"
    tolerationSeconds: 3600
#...

污点与容限由 key、value 和 effect 组成。

表 12.1. 污点和容限组件
参数描述

key

key 是任意字符串,最多 253 个字符。key 必须以字母或数字开头,可以包含字母、数字、连字符、句点和下划线。

value

value 是任意字符串,最多 63 个字符。value 必须以字母或数字开头,可以包含字母、数字、连字符、句点和下划线。

effect

effect 的值包括:

NoSchedule [1]

  • 与污点不匹配的新 pod 不会调度到该节点上。
  • 该节点上现有的 pod 会保留。

PreferNoSchedule

  • 与污点不匹配的新 pod 可以调度到该节点上,但调度程序会尽量不这样调度。
  • 该节点上现有的 pod 会保留。

NoExecute

  • 与污点不匹配的新 pod 无法调度到该节点上。
  • 节点上没有匹配容限的现有 pod 将被移除。

operator

Equal

key/value/effect 参数必须匹配。这是默认值。

Exists

key/effect 参数必须匹配。您必须保留一个空的 value 参数,这将匹配任何值。

  1. 如果向 control plane 节点添加了一个 NoSchedule 污点,节点必须具有 node-role.kubernetes.io/master=:NoSchedule 污点,这默认会添加。

    例如:

    apiVersion: v1
    kind: Node
    metadata:
      annotations:
        machine.openshift.io/machine: openshift-machine-api/ci-ln-62s7gtb-f76d1-v8jxv-master-0
        machineconfiguration.openshift.io/currentConfig: rendered-master-cdc1ab7da414629332cc4c3926e6e59c
      name: my-node
    #...
    spec:
      taints:
      - effect: NoSchedule
        key: node-role.kubernetes.io/master
    #...

容限与污点匹配:

  • 如果 operator 参数设为 Equal

    • key 参数相同;
    • value 参数相同;
    • effect 参数相同。
  • 如果 operator 参数设为 Exists

    • key 参数相同;
    • effect 参数相同。

OpenShift Container Platform 中内置了以下污点:

  • node.kubernetes.io/not-ready:节点未就绪。这与节点状况 Ready=False 对应。
  • node.kubernetes.io/unreachable:节点无法从节点控制器访问。这与节点状况 Ready=Unknown 对应。
  • node.kubernetes.io/memory-pressure:节点存在内存压力问题。这与节点状况 MemoryPressure=True 对应。
  • node.kubernetes.io/disk-pressure:节点存在磁盘压力问题。这与节点状况 DiskPressure=True 对应。
  • node.kubernetes.io/network-unavailable:节点网络不可用。
  • node.kubernetes.io/unschedulable:节点不可调度。
  • node.cloudprovider.kubernetes.io/uninitialized:当节点控制器通过外部云提供商启动时,在节点上设置这个污点来将其标记为不可用。在云控制器管理器中的某个控制器初始化这个节点后,kubelet 会移除此污点。
  • node.kubernetes.io/pid-pressure :节点具有 pid 压力。这与节点状况 PIDPressure=True 对应。

    重要

    OpenShift Container Platform 不设置默认的 pid.available evictionHard

12.2.2. 使用容忍度来控制日志存储 pod 放置

默认情况下,日志存储 pod 具有以下容限配置:

Elasticsearch 日志存储 pod 默认容限

apiVersion: v1
kind: Pod
metadata:
  name: elasticsearch-example
  namespace: openshift-logging
spec:
# ...
  tolerations:
  - effect: NoSchedule
    key: node.kubernetes.io/disk-pressure
    operator: Exists
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  - effect: NoSchedule
    key: node.kubernetes.io/memory-pressure
    operator: Exists
# ...

LokiStack 日志存储 pod 默认容限

apiVersion: v1
kind: Pod
metadata:
  name: lokistack-example
  namespace: openshift-logging
spec:
# ...
  tolerations:
  - effect: NoExecute
    key: node.kubernetes.io/not-ready
    operator: Exists
    tolerationSeconds: 300
  - effect: NoExecute
    key: node.kubernetes.io/unreachable
    operator: Exists
    tolerationSeconds: 300
  - effect: NoSchedule
    key: node.kubernetes.io/memory-pressure
    operator: Exists
# ...

您可以通过添加污点,然后在 ClusterLogging 自定义资源 (CR) 中修改 tolerations 语法,为日志存储 pod 配置容限。

先决条件

  • 已安装 Red Hat OpenShift Logging Operator。
  • 已安装 OpenShift CLI(oc)。
  • 您已部署了内部日志存储,可以是 Elasticsearch 或 LokiStack。

流程

  1. 运行以下命令,将污点添加到要在其上调度日志记录 pod 的节点:

    $ oc adm taint nodes <node_name> <key>=<value>:<effect>

    示例命令

    $ oc adm taint nodes node1 lokistack=node:NoExecute

    本例在 node1 上放置一个键为 lokistack 的污点,值为 node,污点效果是 NoExecute。具有 NoExecute 效果的节点仅调度与污点匹配的 Pod,并删除不匹配的现有 pod。

  2. 编辑 ClusterLogging CR 的 logstore 部分,以配置日志存储 pod 的容忍度:

    ClusterLogging CR 示例

    apiVersion: logging.openshift.io/v1
    kind: ClusterLogging
    metadata:
    # ...
    spec:
    # ...
      logStore:
        type: lokistack
        elasticsearch:
          nodeCount: 1
          tolerations:
          - key: lokistack 1
            operator: Exists 2
            effect: NoExecute 3
            tolerationSeconds: 6000 4
    # ...

    1
    指定添加到节点的键。
    2
    指定 Exists 运算符,以要求节点上存在带有键 lokistack 的污点。
    3
    指定 NoExecute 效果。
    4
    可选:指定 tolerationSeconds 参数,以设置 pod 在被驱除前可以保持绑定到节点的时长。

此容忍度与 oc adm taint 命令创建的污点匹配。具有此容忍度的 pod 可以调度到 node1 上。

12.2.3. 使用容忍度来控制日志可视化 pod 放置

您可以使用不在其他 Pod 上的特定键/值对来确保只有 Kibana Pod 可以在指定节点上运行。

先决条件

  • 已安装 Red Hat OpenShift Logging Operator、OpenShift Elasticsearch Operator 和 OpenShift CLI (oc)。

流程

  1. 运行以下命令,将污点添加到要在其上调度日志可视化 pod 的节点:

    $ oc adm taint nodes <node_name> <key>=<value>:<effect>

    示例命令

    $ oc adm taint nodes node1 kibana=node:NoExecute

    本例在 node1 上放置一个键为 kibana 且值为 node 的污点,污点效果是 NoExecute。您必须使用 NoExecute 污点设置。NoExecute 仅调度与污点匹配的 pod,并删除不匹配的现有 pod。

  2. 编辑 ClusterLogging CR 的 visualization 部分,以配置 Kibana pod 的容忍度:

    apiVersion: logging.openshift.io/v1
    kind: ClusterLogging
    metadata:
    # ...
    spec:
    # ...
      visualization:
        type: kibana
        kibana:
          tolerations:
          - key: kibana  1
            operator: Exists 2
            effect: NoExecute 3
            tolerationSeconds: 6000 4
          resources:
            limits:
              memory: 2Gi
            requests:
              cpu: 100m
              memory: 1Gi
          replicas: 1
    # ...
    1
    指定添加到节点的键。
    2
    指定 Exists 运算符,以要求、值和 effect 参数匹配。
    3
    指定 NoExecute 效果。
    4
    (可选)指定 tolerationSeconds 参数,以设置 pod 在被逐出前可以保持绑定到节点的时长。

此容忍度与 oc adm taint 命令创建的污点匹配。具有此容限的 pod 可以调度到 node1 上。

12.2.4. 使用容忍度来控制日志收集器 pod 放置

默认情况下,日志收集器 pod 具有以下 tolerations 配置:

apiVersion: v1
kind: Pod
metadata:
  name: collector-example
  namespace: openshift-logging
spec:
# ...
  collection:
    type: vector
    tolerations:
    - effect: NoSchedule
      key: node-role.kubernetes.io/master
      operator: Exists
    - effect: NoSchedule
      key: node.kubernetes.io/disk-pressure
      operator: Exists
    - effect: NoExecute
      key: node.kubernetes.io/not-ready
      operator: Exists
    - effect: NoExecute
      key: node.kubernetes.io/unreachable
      operator: Exists
    - effect: NoSchedule
      key: node.kubernetes.io/memory-pressure
      operator: Exists
    - effect: NoSchedule
      key: node.kubernetes.io/pid-pressure
      operator: Exists
    - effect: NoSchedule
      key: node.kubernetes.io/unschedulable
      operator: Exists
# ...

先决条件

  • 已安装 Red Hat OpenShift Logging Operator 和 OpenShift CLI (oc)。

流程

  1. 运行以下命令,将污点添加到要在其上调度日志记录收集器 pod 的节点:

    $ oc adm taint nodes <node_name> <key>=<value>:<effect>

    示例命令

    $ oc adm taint nodes node1 collector=node:NoExecute

    本例在 node1 上放置一个键为 collector 且值为 node 的污点,污点效果是 NoExecute。您必须使用 NoExecute 污点设置。NoExecute 仅调度与污点匹配的 pod,并删除不匹配的现有 pod。

  2. 编辑 ClusterLogging 自定义资源(CR)的 collection 小节,以配置日志记录收集器 Pod 的容忍度:

    apiVersion: logging.openshift.io/v1
    kind: ClusterLogging
    metadata:
    # ...
    spec:
    # ...
      collection:
        type: vector
        tolerations:
        - key: collector 1
          operator: Exists 2
          effect: NoExecute 3
          tolerationSeconds: 6000 4
        resources:
          limits:
            memory: 2Gi
          requests:
            cpu: 100m
            memory: 1Gi
    # ...
    1
    指定添加到节点的键。
    2
    指定 Exists 运算符,以要求匹配 key/value/effect 参数。
    3
    指定 NoExecute 效果。
    4
    (可选)指定 tolerationSeconds 参数,以设置 pod 在被逐出前可以保持绑定到节点的时长。

此容忍度与 oc adm taint 命令创建的污点匹配。具有此容忍度的 pod 可以调度到 node1 上。

12.2.5. 其他资源

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.