Red Hat Training

A Red Hat training course is available for OpenShift Container Platform

16.10.2. 配置 Node Selectors

在 pod 配置中使用 nodeSelector,您可以确保 pod 只放置到带有特定标签的节点上。

  1. 确保您有所需的标签(请参阅 在节点上更新标签)和节点选择器设置。

    例如,请确保您的 pod 配置具有指明所需标签的 nodeSelector 值:

    apiVersion: v1
    kind: Pod
    spec:
      nodeSelector:
        <key>: <value>
    ...
  2. 修改 master 配置文件 /etc/origin/master/master-config.yaml,将 nodeSelectorLabelBlacklist 添加到 admissionConfig 部分,带有分配给您要拒绝 pod 放置的节点主机的标签:

    ...
    admissionConfig:
      pluginConfig:
        PodNodeConstraints:
          configuration:
            apiversion: v1
            kind: PodNodeConstraintsConfig
            nodeSelectorLabelBlacklist:
              - kubernetes.io/hostname
              - <label>
    ...
  3. 重启 OpenShift Container Platform 以使更改生效。

    # master-restart api
    # master-restart controllers
注意

如果您在同一 pod 配置中同时使用节点选择器和节点关联性,请注意:

  • 如果同时配置了 nodeSelectornodeAffinity,则必须满足这两个条件时 pod 才能调度到候选节点。
  • 如果您指定了多个与 nodeAffinity 类型关联的 nodeSelectorTerms,那么其中一个 nodeSelectorTerms 满足时 pod 就能调度到节点上。
  • 如果您指定了多个与 nodeSelectorTerms 关联的 matchExpressions,那么只有所有 matchExpressions 都满足时 pod 才能调度到节点上。