12.3. 反关联性策略配置


Infinispan CR 中配置反关联性策略,以控制 OpenShift 调度 Data Grid 副本 pod 的位置。

将 pod 调度到不同的 OpenShift 节点上

如果没有在 Infinispan CR 中配置 spec.affinity 字段,则 Data Grid Operator 会使用反关联性策略:

spec:
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100 
1

        podAffinityTerm:
          labelSelector:
            matchLabels:
              app: infinispan-pod
              clusterName: <cluster_name>
              infinispan_cr: <cluster_name>
          topologyKey: "kubernetes.io/hostname" 
2
Copy to Clipboard Toggle word wrap
1
将 hostname 策略设置为首选。
2
将 Data Grid 副本 pod 调度到不同的 OpenShift 节点上。

需要不同的节点

spec:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution: 
1

      - labelSelector:
          matchLabels:
            app: infinispan-pod
            clusterName: <cluster_name>
            infinispan_cr: <cluster_name>
        topologyKey: "topology.kubernetes.io/hostname"
Copy to Clipboard Toggle word wrap

1
如果没有可用的不同节点,OpenShift 不会调度 Data Grid pod。
注意

为确保您可以在不同的 OpenShift 节点上调度 Data Grid 副本容器集,可用的 OpenShift 节点数量必须大于 spec.replicas 的值。

在多个 OpenShift 区域间调度 pod

以下示例在调度 pod 时首选多个区:

spec:
  affinity:
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 100 
1

        podAffinityTerm:
          labelSelector:
            matchLabels:
              app: infinispan-pod
              clusterName: <cluster_name>
              infinispan_cr: <cluster_name>
          topologyKey: "topology.kubernetes.io/zone" 
2

      - weight: 90 
3

        podAffinityTerm:
          labelSelector:
            matchLabels:
              app: infinispan-pod
              clusterName: <cluster_name>
              infinispan_cr: <cluster_name>
          topologyKey: "kubernetes.io/hostname" 
4
Copy to Clipboard Toggle word wrap
1
将 zone 策略设置为首选。
2
在多个区域间调度 Data Grid 副本 pod。
3
将 hostname 策略设置为下一个首选。
4
如果无法在跨区域调度,将 Data Grid 副本 pod 调度到不同的 OpenShift 节点上。

需要多个区域

spec:
  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution: 
1

      - labelSelector:
          matchLabels:
            app: infinispan-pod
            clusterName: <cluster_name>
            infinispan_cr: <cluster_name>
        topologyKey: "topology.kubernetes.io/zone"
Copy to Clipboard Toggle word wrap

1
仅在调度 Data Grid 副本 pod 时使用 zone 策略。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat