2.7.2. 配置 pod 反关联性,以将每个 Kafka 代理调度到不同的 worker 节点上
许多 Kafka 代理或 ZooKeeper 节点可以在同一 OpenShift worker 节点上运行。如果 worker 节点失败,它们都会同时不可用。要提高可靠性,您可以使用 podAntiAffinity
配置在不同的 OpenShift worker 节点上调度每个 Kafka 代理或 ZooKeeper 节点。
先决条件
- OpenShift 集群
- 一个正在运行的 Cluster Operator
流程
编辑指定集群部署的资源中的
affinity
属性。要确保 Kafka 代理或 ZooKeeper 节点没有共享 worker 节点,请使用strimzi.io/name
标签。将topologyKey
设置为kubernetes.io/hostname
,以指定所选 pod 没有调度到具有相同主机名的节点。这仍然允许同一 worker 节点由单个 Kafka 代理和单个 ZooKeeper 节点共享。例如:apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka spec: kafka: # ... template: pod: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: strimzi.io/name operator: In values: - CLUSTER-NAME-kafka topologyKey: "kubernetes.io/hostname" # ... zookeeper: # ... template: pod: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: strimzi.io/name operator: In values: - CLUSTER-NAME-zookeeper topologyKey: "kubernetes.io/hostname" # ...
Where
CLUSTER-NAME
是 Kafka 自定义资源的名称。如果您甚至希望确保 Kafka 代理和 ZooKeeper 节点不共享相同的 worker 节点,请使用
strimzi.io/cluster
标签。例如:apiVersion: kafka.strimzi.io/v1beta2 kind: Kafka spec: kafka: # ... template: pod: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: strimzi.io/cluster operator: In values: - CLUSTER-NAME topologyKey: "kubernetes.io/hostname" # ... zookeeper: # ... template: pod: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: strimzi.io/cluster operator: In values: - CLUSTER-NAME topologyKey: "kubernetes.io/hostname" # ...
Where
CLUSTER-NAME
是 Kafka 自定义资源的名称。创建或更新资源。
oc apply -f KAFKA-CONFIG-FILE