4.2. 为 Alertmanager 设置 pod 拓扑分布限制

对于 OpenShift Container Platform 核心平台监控,您可以为 Alertmanager 设置 pod 拓扑分布限制,以微调如何在区调度到节点的 pod 副本。这有助于确保 Alertmanager pod 具有高可用性并更有效地运行,因为工作负载分散在不同的数据中心或分层基础架构区域中。

您可以在 cluster-monitoring-config 配置映射中为 Alertmanager 配置 pod 拓扑分布限制。

先决条件

  • 已安装 OpenShift CLI(oc)。
  • 您可以使用具有 cluster-admin 集群角色的用户身份访问集群。
  • 您已创建 cluster-monitoring-config ConfigMap 对象。

流程

  1. 编辑 openshift-monitoring 命名空间中的 cluster-monitoring-config ConfigMap 对象:

    $ oc -n openshift-monitoring edit configmap cluster-monitoring-config
  2. data/config.yaml/alertmanagermain 下添加以下设置的值来配置 pod 拓扑分布限制:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: cluster-monitoring-config
      namespace: openshift-monitoring
    data:
      config.yaml: |
        alertmanagerMain:
          topologySpreadConstraints:
          - maxSkew: 1 1
            topologyKey: monitoring 2
            whenUnsatisfiable: DoNotSchedule 3
            labelSelector:
              matchLabels: 4
                app.kubernetes.io/name: alertmanager
    1
    maxSkew 指定数字值,它定义了允许不均匀分布 pod 的程度。此字段是必需的,值必须大于零。指定的值会根据您为 whenUnsatisfiable 指定的值的不同而有所不同。
    2
    topologyKey 指定节点标签键。此字段是必需的。带有具有此键和相同值标签的节点被视为在同一拓扑中。调度程序会尝试将大量 pod 放置到每个域中。
    3
    whenUnsatisfiable 指定一个值。此字段是必需的。可用选项包括 DoNotScheduleScheduleAnyway。如果您希望 maxSkew 值定义目标拓扑和全局最小值中匹配 pod 数量之间允许的最大值,则指定 DoNotSchedule。如果您希望调度程序仍然调度 pod,但为可能降低 skew 的节点赋予更高的优先级,请指定 ScheduleAnyway
    4
    matchLabels 指定一个值。这个值用于标识要应用约束的匹配 pod 的集合。
  3. 保存文件以自动应用更改。

    警告

    当您保存对 cluster-monitoring-config 配置映射的更改时,可能会重新部署 openshift-monitoring 项目中的 Pod 和其他资源。该项目中正在运行的监控进程可能会重启。