7.2. 使用 Cluster Operator


Cluster Operator 用于部署 Kafka 集群和其他 Kafka 组件。

如需有关部署 Cluster Operator 的信息,请参阅 部署 Cluster Operator

7.2.1. 基于角色的访问控制(RBAC)资源

Cluster Operator 为需要访问 OpenShift 资源的 AMQ Streams 组件创建和管理 RBAC 资源。

要使 Cluster Operator 正常工作,OpenShift 集群中的权限需要与 Kafka 资源交互,如 KafkaKafkaConnect,以及 ConfigMapPodDeploymentStatefulSetService 等受管资源。

通过 OpenShift 基于角色的访问控制(RBAC)资源指定权限:

  • ServiceAccount
  • 角色和 ClusterRole
  • RolebindingClusterRoleBinding

7.2.1.1. 委派权限到 AMQ Streams 组件

Cluster Operator 在名为 strimzi-cluster-operator 的服务帐户下运行。它会分配集群角色,授予它为 AMQ Streams 组件创建 RBAC 资源。角色绑定将集群角色与服务帐户关联。

OpenShift 可防止在一个 ServiceAccount 下运行的组件授予授予 ServiceAccount 不具有的另一个 ServiceAccount 权限。因为 Cluster Operator 创建它管理的资源所需的 RoleBindingClusterRoleBinding RBAC 资源,因此它需要赋予它相同的特权的角色。

下表描述了 Cluster Operator 创建的 RBAC 资源。

Expand
表 7.1. ServiceAccount 资源
名称使用的

<cluster_name>-kafka

Kafka 代理 pod

<cluster_name>-zookeeper

zookeeper pod

<cluster_name>-cluster-connect

Kafka Connect pod

<cluster_name>-mirror-maker

MirrorMaker pod

<cluster_name>-mirrormaker2

MirrorMaker 2.0 pod

<cluster_name>-bridge

Kafka Bridge pod

<cluster_name>-entity-operator

Entity Operator

Expand
表 7.2. ClusterRole 资源
名称使用的

strimzi-cluster-operator-namespaced

Cluster Operator

strimzi-cluster-operator-global

Cluster Operator

strimzi-cluster-operator-leader-election

Cluster Operator

strimzi-kafka-broker

Cluster Operator、机架功能(使用时)

strimzi-entity-operator

Cluster Operator、主题 Operator、用户 Operator

strimzi-kafka-client

Cluster Operator、用于机架意识的 Kafka 客户端

Expand
表 7.3. ClusterRoleBinding 资源
名称使用的

strimzi-cluster-operator

Cluster Operator

strimzi-cluster-operator-kafka-broker-delegation

Cluster Operator、用于机架意识的 Kafka 代理

strimzi-cluster-operator-kafka-client-delegation

Cluster Operator、用于机架意识的 Kafka 客户端

Expand
表 7.4. Rolebinding 资源
名称使用的

strimzi-cluster-operator

Cluster Operator

strimzi-cluster-operator-kafka-broker-delegation

Cluster Operator、用于机架意识的 Kafka 代理

Cluster Operator 最好使用 ServiceAccount 运行:

Cluster Operator 的 ServiceAccount 示例

apiVersion: v1
kind: ServiceAccount
metadata:
  name: strimzi-cluster-operator
  labels:
    app: strimzi
Copy to Clipboard Toggle word wrap

然后,Operator 的 Deployment 需要在其 spec.template.spec.serviceAccountName 中指定:

Cluster Operator 的 Deployment 的部分示例

apiVersion: apps/v1
kind: Deployment
metadata:
  name: strimzi-cluster-operator
  labels:
    app: strimzi
spec:
  replicas: 1
  selector:
    matchLabels:
      name: strimzi-cluster-operator
      strimzi.io/kind: cluster-operator
  template:
      # ...
Copy to Clipboard Toggle word wrap

注意第 12 行,其中 strimzi-cluster-operator 指定为 serviceAccountName

7.2.1.3. ClusterRole 资源

Cluster Operator 使用 ClusterRole 资源来提供对资源的必要访问权限。根据 OpenShift 集群设置,可能需要集群管理员来创建集群角色。

注意

只有创建 ClusterRole 资源时需要集群管理员权限。Cluster Operator 不会在集群管理员帐户下运行。

ClusterRole 资源遵循 最小特权原则,并只包含 Cluster Operator 运行 Kafka 组件集群所需的权限。分配的第一个权限允许 Cluster Operator 管理 OpenShift 资源,如 StatefulSetDeploymentPodConfigMap

Cluster Operator 需要所有集群角色,以便委派权限。

Cluster Operator 使用 strimzi-cluster-operator-namespacedstrimzi-cluster-operator-global 集群角色在命名空间范围的资源级别和集群范围的资源级别授予权限。

具有 Cluster Operator 的命名空间资源的 ClusterRole

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-cluster-operator-namespaced
  labels:
    app: strimzi
rules:
  # Resources in this role are used by the operator based on an operand being deployed in some namespace. When needed, you
  # can deploy the operator as a cluster-wide operator. But grant the rights listed in this role only on the namespaces
  # where the operands will be deployed. That way, you can limit the access the operator has to other namespaces where it
  # does not manage any clusters.
  - apiGroups:
      - "rbac.authorization.k8s.io"
    resources:
      # The cluster operator needs to access and manage rolebindings to grant Strimzi components cluster permissions
      - rolebindings
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - "rbac.authorization.k8s.io"
    resources:
      # The cluster operator needs to access and manage roles to grant the entity operator permissions
      - roles
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - ""
    resources:
      # The cluster operator needs to access and delete pods, this is to allow it to monitor pod health and coordinate rolling updates
      - pods
      # The cluster operator needs to access and manage service accounts to grant Strimzi components cluster permissions
      - serviceaccounts
      # The cluster operator needs to access and manage config maps for Strimzi components configuration
      - configmaps
      # The cluster operator needs to access and manage services and endpoints to expose Strimzi components to network traffic
      - services
      - endpoints
      # The cluster operator needs to access and manage secrets to handle credentials
      - secrets
      # The cluster operator needs to access and manage persistent volume claims to bind them to Strimzi components for persistent data
      - persistentvolumeclaims
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      # The cluster operator needs the extensions api as the operator supports Kubernetes version 1.11+
      # apps/v1 was introduced in Kubernetes 1.14
      - "extensions"
    resources:
      # The cluster operator needs to access and manage deployments to run deployment based Strimzi components
      - deployments
      - deployments/scale
      # The cluster operator needs to access replica sets to manage Strimzi components and to determine error states
      - replicasets
      # The cluster operator needs to access and manage replication controllers to manage replicasets
      - replicationcontrollers
      # The cluster operator needs to access and manage network policies to lock down communication between Strimzi components
      - networkpolicies
      # The cluster operator needs to access and manage ingresses which allow external access to the services in a cluster
      - ingresses
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - "apps"
    resources:
      # The cluster operator needs to access and manage deployments to run deployment based Strimzi components
      - deployments
      - deployments/scale
      - deployments/status
      # The cluster operator needs to access and manage stateful sets to run stateful sets based Strimzi components
      - statefulsets
      # The cluster operator needs to access replica-sets to manage Strimzi components and to determine error states
      - replicasets
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - "" # legacy core events api, used by topic operator
      - "events.k8s.io" # new events api, used by cluster operator
    resources:
      # The cluster operator needs to be able to create events and delegate permissions to do so
      - events
    verbs:
      - create
  - apiGroups:
      # Kafka Connect Build on OpenShift requirement
      - build.openshift.io
    resources:
      - buildconfigs
      - buildconfigs/instantiate
      - builds
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - networking.k8s.io
    resources:
      # The cluster operator needs to access and manage network policies to lock down communication between Strimzi components
      - networkpolicies
      # The cluster operator needs to access and manage ingresses which allow external access to the services in a cluster
      - ingresses
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - route.openshift.io
    resources:
      # The cluster operator needs to access and manage routes to expose Strimzi components for external access
      - routes
      - routes/custom-host
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - policy
    resources:
      # The cluster operator needs to access and manage pod disruption budgets this limits the number of concurrent disruptions
      # that a Strimzi component experiences, allowing for higher availability
      - poddisruptionbudgets
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
Copy to Clipboard Toggle word wrap

Cluster Operator 的带有集群范围资源的 ClusterRole

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-cluster-operator-global
  labels:
    app: strimzi
rules:
  - apiGroups:
      - "rbac.authorization.k8s.io"
    resources:
      # The cluster operator needs to create and manage cluster role bindings in the case of an install where a user
      # has specified they want their cluster role bindings generated
      - clusterrolebindings
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
  - apiGroups:
      - storage.k8s.io
    resources:
      # The cluster operator requires "get" permissions to view storage class details
      # This is because only a persistent volume of a supported storage class type can be resized
      - storageclasses
    verbs:
      - get
  - apiGroups:
      - ""
    resources:
      # The cluster operator requires "list" permissions to view all nodes in a cluster
      # The listing is used to determine the node addresses when NodePort access is configured
      # These addresses are then exposed in the custom resource states
      - nodes
    verbs:
      - list
Copy to Clipboard Toggle word wrap

strimzi-cluster-operator-leader-election 集群角色代表领导选举机制所需的权限。

带有领导选举权限的 ClusterRole

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-cluster-operator-leader-election
  labels:
    app: strimzi
rules:
  - apiGroups:
      - coordination.k8s.io
    resources:
      # The cluster operator needs to access and manage leases for leader election
      # The "create" verb cannot be used with "resourceNames"
      - leases
    verbs:
      - create
  - apiGroups:
      - coordination.k8s.io
    resources:
      # The cluster operator needs to access and manage leases for leader election
      - leases
    resourceNames:
      # The default RBAC files give the operator only access to the Lease resource names strimzi-cluster-operator
      # If you want to use another resource name or resource namespace, you have to configure the RBAC resources accordingly
      - strimzi-cluster-operator
    verbs:
      - get
      - list
      - watch
      - delete
      - patch
      - update
Copy to Clipboard Toggle word wrap

strimzi-kafka-broker 集群角色代表了使用机架意识的 Kafka pod 中 init 容器所需的访问权限。

名为 strimzi-<cluster_name>-kafka-init 的角色绑定会为 <cluster_name>-kafka 服务账户分配访问集群内使用 strimzi-kafka-broker 角色的节点。如果没有使用机架功能,且集群不会通过 nodeport 公开,则不会创建绑定。

Cluster Operator 的 ClusterRole 允许您将访问权限委派给 Kafka 代理 pod

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-kafka-broker
  labels:
    app: strimzi
rules:
  - apiGroups:
      - ""
    resources:
      # The Kafka Brokers require "get" permissions to view the node they are on
      # This information is used to generate a Rack ID that is used for High Availability configurations
      - nodes
    verbs:
      - get
Copy to Clipboard Toggle word wrap

strimzi-entity-operator 集群角色代表主题 Operator 和 User Operator 所需的访问权限。

Topic Operator 使用状态信息生成 OpenShift 事件,因此 < cluster_name&gt; -entity-operator 服务帐户被绑定到 strimzi-entity-operator 角色,它通过 strimzi-entity-operator 角色绑定授予这个访问权限。

Cluster Operator 的 ClusterRole,允许它将访问权限委派给主题和用户 Operator

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-entity-operator
  labels:
    app: strimzi
rules:
  - apiGroups:
      - "kafka.strimzi.io"
    resources:
      # The entity operator runs the KafkaTopic assembly operator, which needs to access and manage KafkaTopic resources
      - kafkatopics
      - kafkatopics/status
      # The entity operator runs the KafkaUser assembly operator, which needs to access and manage KafkaUser resources
      - kafkausers
      - kafkausers/status
    verbs:
      - get
      - list
      - watch
      - create
      - patch
      - update
      - delete
  - apiGroups:
      - ""
    resources:
      - events
    verbs:
      # The entity operator needs to be able to create events
      - create
  - apiGroups:
      - ""
    resources:
      # The entity operator user-operator needs to access and manage secrets to store generated credentials
      - secrets
    verbs:
      - get
      - list
      - watch
      - create
      - delete
      - patch
      - update
Copy to Clipboard Toggle word wrap

strimzi-kafka-client 集群角色代表使用机架意识的 Kafka 客户端所需的访问权限。

Cluster Operator 的 ClusterRole 允许您将访问权限委派给基于 Kafka 客户端的 pod

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: strimzi-kafka-client
  labels:
    app: strimzi
rules:
  - apiGroups:
      - ""
    resources:
      # The Kafka clients (Connect, Mirror Maker, etc.) require "get" permissions to view the node they are on
      # This information is used to generate a Rack ID (client.rack option) that is used for consuming from the closest
      # replicas when enabled
      - nodes
    verbs:
      - get
Copy to Clipboard Toggle word wrap

7.2.1.4. ClusterRoleBinding 资源

Cluster Operator 使用 ClusterRoleBindingRoleBinding 资源将其 ClusterRoleServiceAccount 相关联:包含集群范围资源的集群角色需要集群角色绑定。

Cluster Operator 的 ClusterRoleBinding 示例

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: strimzi-cluster-operator
  labels:
    app: strimzi
subjects:
  - kind: ServiceAccount
    name: strimzi-cluster-operator
    namespace: myproject
roleRef:
  kind: ClusterRole
  name: strimzi-cluster-operator-global
  apiGroup: rbac.authorization.k8s.io
Copy to Clipboard Toggle word wrap

委派权限中使用的集群角色需要集群角色绑定:

Cluster Operator 和 Kafka 代理机架意识的 ClusterRoleBinding 示例

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: strimzi-cluster-operator-kafka-broker-delegation
  labels:
    app: strimzi
# The Kafka broker cluster role must be bound to the cluster operator service account so that it can delegate the cluster role to the Kafka brokers.
# This must be done to avoid escalating privileges which would be blocked by Kubernetes.
subjects:
  - kind: ServiceAccount
    name: strimzi-cluster-operator
    namespace: myproject
roleRef:
  kind: ClusterRole
  name: strimzi-kafka-broker
  apiGroup: rbac.authorization.k8s.io
Copy to Clipboard Toggle word wrap

Cluster Operator 和 Kafka 客户端的 ClusterRoleBinding 示例

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: strimzi-cluster-operator-kafka-client-delegation
  labels:
    app: strimzi
# The Kafka clients cluster role must be bound to the cluster operator service account so that it can delegate the
# cluster role to the Kafka clients using it for consuming from closest replica.
# This must be done to avoid escalating privileges which would be blocked by Kubernetes.
subjects:
  - kind: ServiceAccount
    name: strimzi-cluster-operator
    namespace: myproject
roleRef:
  kind: ClusterRole
  name: strimzi-kafka-client
  apiGroup: rbac.authorization.k8s.io
Copy to Clipboard Toggle word wrap

仅包含命名空间资源的集群角色仅使用角色绑定进行绑定。

Cluster Operator 的 RoleBinding 示例

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: strimzi-cluster-operator
  labels:
    app: strimzi
subjects:
  - kind: ServiceAccount
    name: strimzi-cluster-operator
    namespace: myproject
roleRef:
  kind: ClusterRole
  name: strimzi-cluster-operator-namespaced
  apiGroup: rbac.authorization.k8s.io
Copy to Clipboard Toggle word wrap

Cluster Operator 和 Kafka 代理机架意识的 RoleBinding 示例

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: strimzi-cluster-operator-entity-operator-delegation
  labels:
    app: strimzi
# The Entity Operator cluster role must be bound to the cluster operator service account so that it can delegate the cluster role to the Entity Operator.
# This must be done to avoid escalating privileges which would be blocked by Kubernetes.
subjects:
  - kind: ServiceAccount
    name: strimzi-cluster-operator
    namespace: myproject
roleRef:
  kind: ClusterRole
  name: strimzi-entity-operator
  apiGroup: rbac.authorization.k8s.io
Copy to Clipboard Toggle word wrap

7.2.2. Cluster Operator 日志记录的 ConfigMap

Cluster Operator 日志记录通过名为 strimzi-cluster-operatorConfigMap 配置。

安装 Cluster Operator 时会创建包含日志记录配置的 ConfigMap。此 ConfigMapinstall/cluster-operator/050-ConfigMap-strimzi-cluster-operator.yaml 文件中描述。您可以通过更改此 ConfigMap 中的数据字段 log4j2.properties 来配置 Cluster Operator 日志记录。

要更新日志记录配置,您可以编辑 050-ConfigMap-strimzi-cluster-operator.yaml 文件,然后运行以下命令:

oc create -f install/cluster-operator/050-ConfigMap-strimzi-cluster-operator.yaml
Copy to Clipboard Toggle word wrap

或者,直接编辑 ConfigMap

oc edit configmap strimzi-cluster-operator
Copy to Clipboard Toggle word wrap

要更改重新加载间隔的频率,请在所创建 ConfigMapmonitorInterval 选项中设置一个时间(以秒为单位)。

如果部署 Cluster Operator 时缺少 ConfigMap,则会使用默认的日志记录值。

如果在部署 Cluster Operator 后意外删除 ConfigMap,则会使用最近加载的日志配置。创建新的 ConfigMap 来加载新的日志记录配置。

注意

不要从 ConfigMap 中删除 monitorInterval 选项。

7.2.3. 使用环境变量配置 Cluster Operator

您可以使用环境变量配置 Cluster Operator。此处列出了支持的环境变量。

注意

环境变量与 Cluster Operator 镜像部署的容器配置相关。有关 镜像 配置的详情请参考 第 12.1.6 节 “image

STRIMZI_NAMESPACE

Operator 操作的、以逗号分隔的命名空间列表。如果没有设置,则 Cluster Operator 会在所有命名空间中运行空字符串,或设置为 *

Cluster Operator 部署可能会使用 Downward API 自动将其设置为 Cluster Operator 部署的命名空间。

Cluster Operator 命名空间配置示例

env:
  - name: STRIMZI_NAMESPACE
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
Copy to Clipboard Toggle word wrap

STRIMZI_FULL_RECONCILIATION_INTERVAL_MS
可选,默认为 120000 ms。定期协调之间的间隔( 以毫秒为单位)。
STRIMZI_OPERATION_TIMEOUT_MS
可选,默认为 300000 ms。内部操作的超时时间,以毫秒为单位。在使用常规 OpenShift 操作的集群上使用 AMQ Streams 时,增加这个值会比平常完成(因为下载 Docker 镜像很慢)。
STRIMZI_ZOOKEEPER_ADMIN_SESSION_TIMEOUT_MS
可选,默认为 10000 ms。Cluster Operator 的 ZooKeeper 管理客户端的会话超时,以毫秒为单位。如果因为超时问题,Cluster Operator 中的 ZooKeeper 请求会定期失败,增加这个值。通过 maxSessionTimeout 配置,ZooKeeper 服务器端设置最大允许的会话时间。默认情况下,最多会话超时值为 20 倍,默认的 tickTime (默认为 2000)为 40000 ms。如果需要更高的超时,请更改 maxSessionTimeout ZooKeeper 服务器配置值。
STRIMZI_OPERATIONS_THREAD_POOL_SIZE
可选,默认 10。worker 线程池大小,用于各种异步和阻止由 Cluster Operator 运行的操作。
STRIMZI_OPERATOR_NAME
可选,默认为 pod 的主机名。在发出 OpenShift 事件时,操作器名称标识 AMQ Streams 实例。
STRIMZI_OPERATOR_NAMESPACE

运行 Cluster Operator 的命名空间的名称。不要手动配置此变量。使用 Downward API。

env:
  - name: STRIMZI_OPERATOR_NAMESPACE
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
Copy to Clipboard Toggle word wrap
STRIMZI_OPERATOR_NAMESPACE_LABELS

可选。运行 AMQ Streams Cluster Operator 的命名空间的标签。使用命名空间标签 在 网络策略 中配置命名空间选择器。网络策略允许 AMQ Streams Cluster Operator 只访问带有这些标签的命名空间中的操作对象。如果没有设置,网络策略中的命名空间选择器配置为允许从 OpenShift 集群中的任何命名空间中访问 Cluster Operator。

env:
  - name: STRIMZI_OPERATOR_NAMESPACE_LABELS
    value: label1=value1,label2=value2
Copy to Clipboard Toggle word wrap
STRIMZI_LABELS_EXCLUSION_PATTERN

可选,默认的 regex 模式是 ^app.kubernetes.io/(?!part-of)*。正则表达式排除模式用于从主自定义资源过滤标签传播到其子资源。labels exclusion 过滤器不适用于 template 部分中的标签,如 spec.kafka.template.pod.metadata.labels

env:
  - name: STRIMZI_LABELS_EXCLUSION_PATTERN
    value: "^key1.*"
Copy to Clipboard Toggle word wrap
STRIMZI_CUSTOM_{COMPONENT_NAME}_LABELS

可选。一个或多个自定义标签应用到由 {COMPONENT_NAME} 自定义资源创建的所有 pod。当创建自定义资源或进行下一个协调时,Cluster Operator 会标记 pod。

标签可以应用到以下组件:

  • KAFKA
  • KAFKA_CONNECT
  • KAFKA_CONNECT_BUILD
  • ZOOKEEPER
  • ENTITY_OPERATOR
  • KAFKA_MIRROR_MAKER2
  • KAFKA_MIRROR_MAKER
  • CRUISE_CONTROL
  • KAFKA_BRIDGE
  • KAFKA_EXPORTER
STRIMZI_CUSTOM_RESOURCE_SELECTOR

可选。用于过滤 Cluster Operator 处理的自定义资源的标签选择器。Operator 只会针对那些设置了指定标签的自定义资源进行操作。没有这些标签的资源不会被操作员查看。标签选择器适用于 Kafka, KafkaConnect, KafkaBridge, KafkaMirrorMaker, 和 KafkaMirrorMaker2 资源。KafkaRebalanceKafkaConnector 资源仅在对应的 Kafka 和 Kafka Connect 集群有匹配的标签时才会执行。

env:
  - name: STRIMZI_CUSTOM_RESOURCE_SELECTOR
    value: label1=value1,label2=value2
Copy to Clipboard Toggle word wrap
STRIMZI_KAFKA_IMAGES
必需。从 Kafka 版本映射到包含该版本的 Kafka 代理的对应 Docker 镜像的映射。所需语法为空格或用逗号分开的 < version> = &lt;image> 对。例如 3.2.3=registry.redhat.io/amq7/amq-streams-kafka-32-rhel8:2.3.0, 3.3.1=registry.redhat.io/amq7/amq-streams-kafka-33-rhel8:2.3.0。当指定了属性 Kafka.spec.kafka.version 但没有在 Kafka 资源的 Kafka.spec.kafka.image 时使用这个。
STRIMZI_DEFAULT_KAFKA_INIT_IMAGE
可选,默认的 registry.redhat.io/amq7/amq-streams-rhel8-operator:2.3.0。如果没有将镜像指定为 Kafka 资源中的 kafka-init-image,则用作 init 容器的镜像名称。init 容器在代理进行初始配置前启动,如机架支持。
STRIMZI_KAFKA_CONNECT_IMAGES
必需。从 Kafka 版本映射到特定版本的 Kafka Connect 的对应 Docker 镜像的映射。所需语法为空格或用逗号分开的 < version> = &lt;image> 对。例如 3.2.3=registry.redhat.io/amq7/amq-streams-kafka-32-rhel8:2.3.0, 3.3.1=registry.redhat.io/amq7/amq-streams-kafka-33-rhel8:2.3.0。当指定了 KafkaConnect.spec.version 属性但未指定 KafkaConnect.spec.image 时,会使用此设置。
STRIMZI_KAFKA_MIRROR_MAKER_IMAGES
必需。从 Kafka 版本映射到该版本的 mirrorMaker 的对应 Docker 镜像的映射。所需语法为空格或用逗号分开的 < version> = &lt;image> 对。例如 3.2.3=registry.redhat.io/amq7/amq-streams-kafka-32-rhel8:2.3.0, 3.3.1=registry.redhat.io/amq7/amq-streams-kafka-33-rhel8:2.3.0。当指定 KafkaMirrorMaker.spec.version 属性,但没有 KafkaMirrorMaker.spec.image 时会使用这个属性。
STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE
可选,默认的 registry.redhat.io/amq7/amq-streams-rhel8-operator:2.3.0。如果没有在 Kafka 资源中指定为 Kafka.spec.entityOperator.topicOperator.image 镜像时,用于部署主题 Operator 时用作默认镜像名称。
STRIMZI_DEFAULT_USER_OPERATOR_IMAGE
可选,默认的 registry.redhat.io/amq7/amq-streams-rhel8-operator:2.3.0。如果没有在 Kafka 资源中指定为 Kafka.spec.entityOperator.userOperator.image,则部署 User Operator 时用作默认 镜像名称
STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE
可选,默认的 registry.redhat.io/amq7/amq-streams-kafka-33-rhel8:2.3.0。如果没有将镜像指定为 Kafka. spec.entityOperator.tls.tlsSidecar.image,在 Kafka 资源中为 Entity Operator 部署 sidecar 时使用镜像名称。sidecar 提供 TLS 支持。
STRIMZI_IMAGE_PULL_POLICY
可选。应用到由 Cluster Operator 管理的所有 pod 中的容器的 ImagePullPolicy。有效值为 Always,IfNotPresent, Never。如果未指定,则使用 OpenShift 默认值。更改策略将导致所有 Kafka、Kafka Connect 和 Kafka MirrorMaker 集群滚动更新。
STRIMZI_IMAGE_PULL_SECRETS
可选。以逗号分隔的 Secret 名称列表。此处引用的 secret 包含从中拉取容器镜像的容器 registry 的凭证。secret 在 imagePullSecrets 属性中指定,用于 Cluster Operator 创建的所有 Pod。更改此列表会导致所有 Kafka、Kafka Connect 和 Kafka MirrorMaker 集群的滚动更新。
STRIMZI_KUBERNETES_VERSION

可选。覆盖从 API 服务器检测到的 OpenShift 版本信息。

OpenShift 版本覆盖配置示例

env:
  - name: STRIMZI_KUBERNETES_VERSION
    value: |
           major=1
           minor=16
           gitVersion=v1.16.2
           gitCommit=c97fe5036ef3df2967d086711e6c0c405941e14b
           gitTreeState=clean
           buildDate=2019-10-15T19:09:08Z
           goVersion=go1.12.10
           compiler=gc
           platform=linux/amd64
Copy to Clipboard Toggle word wrap

KUBERNETES_SERVICE_DNS_DOMAIN

可选。覆盖默认的 OpenShift DNS 域名后缀。

默认情况下,OpenShift 集群中分配的服务具有使用默认后缀 cluster.local 的 DNS 域名。

例如,对于 broker kafka-0:

<cluster-name>-kafka-0.<cluster-name>-kafka-brokers.<namespace>.svc.cluster.local
Copy to Clipboard Toggle word wrap

DNS 域名添加到用于主机名验证的 Kafka 代理证书中。

如果您在集群中使用不同的 DNS 域名后缀,请将 KUBERNETES_SERVICE_DNS_DOMAIN 环境变量从默认环境变量改为您要用来与 Kafka 代理建立连接。

STRIMZI_CONNECT_BUILD_TIMEOUT_MS
可选,默认为 300000 ms。以毫秒为单位构建带有额外连接器的新 Kafka Connect 镜像的超时时间。当使用 AMQ Streams 构建包含许多连接器或使用较慢的容器 registry 的容器镜像时,请考虑增大这个值。
STRIMZI_NETWORK_POLICY_GENERATION

可选,默认 true。资源的网络策略。网络策略允许 Kafka 组件间的连接。

将此环境变量设置为 false 可禁用网络策略生成。例如,您可能想要使用自定义网络策略。自定义网络策略可让更多地控制组件间的连接。

STRIMZI_DNS_CACHE_TTL
可选,默认 30。本地 DNS 解析器中缓存成功名称查找的秒数。任何负值都意味着每次缓存。零表示不缓存,由于应用了较长的缓存策略,避免连接错误会很有用。
STRIMZI_POD_SET_RECONCILIATION_ONLY
可选,默认 false。当设置为 true 时,Cluster Operator 只协调 StrimziPodSet 资源,以及对其他自定义资源(KafkaKafkaConnect 等等)的任何更改。此模式可用于确保根据需要重新创建您的 pod,但集群没有其他更改。
STRIMZI_FEATURE_GATES
可选。启用或禁用由 功能门 控制的功能和功能。
STRIMZI_POD_SECURITY_PROVIDER_CLASS
可选。可插拔 PodSecurityProvider 类的配置,可用于为 Pod 和容器提供安全性上下文配置。

7.2.3.1. 领导选举环境变量

在运行额外的 Cluster Operator 副本时,请使用领导选举环境变量。您可以运行额外的副本来防出现主要故障造成的中断。

STRIMZI_LEADER_ELECTION_ENABLED
可选,默认为禁用(false)。启用或禁用领导选举机制,允许其他 Cluster Operator 副本在待机上运行。
注意

默认禁用领导选举机制。仅在安装时应用此环境变量时启用。

STRIMZI_LEADER_ELECTION_LEASE_NAME
启用领导选举时是必需的。用于领导选举机制的 OpenShift Lease 资源的名称。
STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE

启用领导选举时是必需的。创建用于领导选举 OpenShift Lease 资源的命名空间。您可以使用 Downward API 将其配置为部署 Cluster Operator 的命名空间。

env:
  - name: STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE
    valueFrom:
      fieldRef:
        fieldPath: metadata.namespace
Copy to Clipboard Toggle word wrap
STRIMZI_LEADER_ELECTION_IDENTITY

启用领导选举时是必需的。配置在领导选举过程中使用的给定 Cluster Operator 实例的身份。身份必须为每个 operator 实例唯一。您可以使用 Downward API 将其配置为部署 Cluster Operator 的 pod 的名称。

env:
  - name: STRIMZI_LEADER_ELECTION_IDENTITY
    valueFrom:
      fieldRef:
        fieldPath: metadata.name
Copy to Clipboard Toggle word wrap
STRIMZI_LEADER_ELECTION_LEASE_DURATION_MS
可选,默认为 15000 ms。指定获取租期有效的持续时间。
STRIMZI_LEADER_ELECTION_RENEW_DEADLINE_MS
可选,默认为 10000 ms。指定领导机应尽力维护领导的期限。
STRIMZI_LEADER_ELECTION_RETRY_PERIOD_MS
可选,默认为 2000 ms。指定领导领导对租期锁定的更新频率。

7.2.3.2. 使用网络策略限制 Cluster Operator 访问

使用 STRIMZI_OPERATOR_NAMESPACE_LABELS 环境变量使用命名空间标签为 Cluster Operator 建立网络策略。

Cluster Operator 可以在与它管理的资源相同的命名空间中运行,或者在单独的命名空间中运行。默认情况下,STRIMZI_OPERATOR_NAMESPACE 环境变量被配置为使用 Downward API 找到 Cluster Operator 在其中运行的命名空间。如果 Cluster Operator 与资源在同一命名空间中运行,则只有本地访问权限才需要并在 AMQ Streams 中允许。

如果 Cluster Operator 在单独的命名空间中运行到其管理的资源,则 OpenShift 集群中的任何命名空间都可以访问 Cluster Operator,除非配置了网络策略。通过添加命名空间标签,对 Cluster Operator 的访问仅限于指定的命名空间。

为 Cluster Operator 部署配置的网络策略

#...
env:
  # ...
  - name: STRIMZI_OPERATOR_NAMESPACE_LABELS
    value: label1=value1,label2=value2
  #...
Copy to Clipboard Toggle word wrap

7.2.3.3. 为定期协调设置时间间隔

使用 STRIMZI_FULL_RECONCILIATION_INTERVAL_MS 变量设置定期协调的时间间隔。

Cluster Operator 会响应所有从 OpenShift 集群收到的适用集群资源的通知。如果操作器没有运行,或者因为某种原因没有收到通知,资源将不与正在运行的 OpenShift 集群的状态同步。为了正确处理故障转移,Cluster Operator 会执行定期协调过程,以便它可以将资源的状态与当前集群部署进行比较,以便在所有节点上具有一致状态。

7.2.4. 使用默认代理设置配置 Cluster Operator

如果您在 HTTP 代理后运行 Kafka 集群,您仍然可以在集群内和移出数据。例如,您可以使用连接器运行 Kafka Connect,从代理外推送和拉取数据。或者,您可以使用代理与授权服务器连接。

配置 Cluster Operator 部署以指定代理环境变量。Cluster Operator 接受标准代理配置(HTTP_PROXYHTTPS_PROXYNO_PROXY)作为环境变量。代理设置适用于所有 AMQ Streams 容器。

代理地址的格式是 http://IP-ADDRESS:PORT-NUMBER。要使用名称和密码设置代理,格式为 http://USERNAME:PASSWORD@IP-ADDRESS:PORT-NUMBER

先决条件

  • 您需要具有权限的帐户来创建和管理 CustomResourceDefinition 和 RBAC (ClusterRoleRoleBinding)资源。

流程

  1. 要在 Cluster Operator 中添加代理环境变量,请更新其 Deployment 配置(install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml)。

    Cluster Operator 的代理配置示例

    apiVersion: apps/v1
    kind: Deployment
    spec:
      # ...
      template:
        spec:
          serviceAccountName: strimzi-cluster-operator
          containers:
            # ...
            env:
            # ...
            - name: "HTTP_PROXY"
              value: "http://proxy.com" 
    1
    
            - name: "HTTPS_PROXY"
              value: "https://proxy.com" 
    2
    
            - name: "NO_PROXY"
              value: "internal.com, other.domain.com" 
    3
    
      # ...
    Copy to Clipboard Toggle word wrap

    1
    代理服务器的地址。
    2
    代理服务器的安全地址。
    3
    作为代理服务器例外访问的服务器地址。URL 是用逗号分开的。

    或者,直接编辑 Deployment

    oc edit deployment strimzi-cluster-operator
    Copy to Clipboard Toggle word wrap
  2. 如果您更新了 YAML 文件而不是直接编辑 Deployment,请应用更改:

    oc create -f install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
    Copy to Clipboard Toggle word wrap

默认 Cluster Operator 配置启用 领导选举机制。使用领导选举机制运行 Cluster Operator 的多个并行副本。一个副本被选为活跃领导值,并运行部署的资源。其他副本以待机模式运行。当领导机停止或失败时,其中一个备用副本被选为新的领导机,并开始操作部署的资源。

默认情况下,AMQ Streams 使用单个 Cluster Operator 副本运行,该副本始终是领导副本。当单个 Cluster Operator 副本停止或失败时,OpenShift 会启动新的副本。

使用多个副本运行 Cluster Operator 并不重要。但是,在出现大规模中断时,将副本处于待机位置上非常有用。例如,假设多个 worker 节点或整个可用区失败。故障可能会导致 Cluster Operator pod 和许多 Kafka pod 同时停机。如果后续 pod 调度会导致出现缺少资源的情况,这可以在运行单个 Cluster Operator 时延迟操作。

7.2.5.1. 配置 Cluster Operator 副本

要以待机模式运行额外的 Cluster Operator 副本,您需要增加副本数并启用领导选举机制。要配置领导选举机制,请使用领导选举环境变量。

要进行必要的更改,请配置位于 install/cluster-operator/ 中的以下 Cluster Operator 安装文件:

  • 060-Deployment-strimzi-cluster-operator.yaml
  • 022-ClusterRole-strimzi-cluster-operator-role.yaml
  • 022-RoleBinding-strimzi-cluster-operator.yaml

领导选举具有自己的 ClusterRoleRoleBinding RBAC 资源,以针对 Cluster Operator 运行的命名空间,而不是对其进行监视的命名空间。

默认部署配置在与 Cluster Operator 相同的命名空间中创建一个名为 strimzi-cluster-operatorLease 资源。Cluster Operator 使用租期来管理领导选举机制。RBAC 资源提供使用 Lease 资源的权限。如果您使用不同的 Lease 名称或命名空间,请相应地更新 ClusterRoleRoleBinding 文件。

先决条件

  • 您需要具有权限的帐户来创建和管理 CustomResourceDefinition 和 RBAC (ClusterRoleRoleBinding)资源。

流程

编辑用于部署 Cluster Operator 的 Deployment 资源,该 Operator 在 060-Deployment-strimzi-cluster-operator.yaml 文件中定义。

  1. replicas 属性从默认的(1)更改为与所需副本数匹配的值。

    增加 Cluster Operator 副本数量

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: strimzi-cluster-operator
      labels:
        app: strimzi
    spec:
      replicas: 3
    Copy to Clipboard Toggle word wrap

  2. 检查是否设置了领导选举 env 属性。

    如果没有设置,请配置它们。

    要启用领导选举机制,STRIMZI_LEADER_ELECTION_ENABLED 必须设置为 true (默认)。

    在本例中,租期的名称被改为 my-strimzi-cluster-operator

    为 Cluster Operator 配置领导选举环境变量

    # ...
    spec
      containers:
        - name: strimzi-cluster-operator
          # ...
          env:
            - name: STRIMZI_LEADER_ELECTION_ENABLED
              value: "true"
            - name: STRIMZI_LEADER_ELECTION_LEASE_NAME
              value: "my-strimzi-cluster-operator"
            - name: STRIMZI_LEADER_ELECTION_LEASE_NAMESPACE
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.namespace
            - name: STRIMZI_LEADER_ELECTION_IDENTITY
                valueFrom:
                  fieldRef:
                    fieldPath: metadata.name
    Copy to Clipboard Toggle word wrap

    有关可用环境变量的描述,请参阅 第 7.2.3.1 节 “领导选举环境变量”

    如果您为领导选举机制中使用的 Lease 资源指定不同的名称或命名空间,请更新 RBAC 资源。

  3. (可选)在 022-ClusterRole-strimzi-cluster-operator-role.yaml 文件中编辑 ClusterRole 资源。

    使用 Lease 资源名称更新 resourceName

    更新对租期的 ClusterRole 引用

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: strimzi-cluster-operator-leader-election
      labels:
        app: strimzi
    rules:
      - apiGroups:
          - coordination.k8s.io
        resourceNames:
          - my-strimzi-cluster-operator
    # ...
    Copy to Clipboard Toggle word wrap

  4. (可选)在 022-RoleBinding-strimzi-cluster-operator.yaml 文件中编辑 RoleBinding 资源。

    更新 subjects.namesubjects.namespace,其名称为 Lease resource,以及创建它的命名空间。

    更新对租期的 RoleBinding 引用

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: strimzi-cluster-operator-leader-election
      labels:
        app: strimzi
    subjects:
      - kind: ServiceAccount
        name: my-strimzi-cluster-operator
        namespace: myproject
    # ...
    Copy to Clipboard Toggle word wrap

  5. 部署 Cluster Operator:

    oc create -f install/cluster-operator -n myproject
    Copy to Clipboard Toggle word wrap
  6. 检查部署的状态:

    oc get deployments -n myproject
    Copy to Clipboard Toggle word wrap

    输出显示了部署名称和就绪状态

    NAME                      READY  UP-TO-DATE  AVAILABLE
    strimzi-cluster-operator  3/3    3           3
    Copy to Clipboard Toggle word wrap

    READY 显示 ready/expected 的副本数量。当 AVAILABLE 输出显示正确的副本数时,部署可以成功。

7.2.6. 在 Cluster Operator 中配置 FIPS 模式

联邦信息处理标准(FIPS)是计算机安全性和互操作性的标准。当在启用了 FIPS 的 OpenShift 集群上运行 AMQ Streams 时,AMQ Streams 容器镜像中使用的 OpenJDK 会自动切换到 FIPS 模式。这可防止 AMQ Streams 在集群中运行。将 AMQ Streams 部署到集群时,您会看到类似如下的错误:

Exception in thread "main" io.fabric8.kubernetes.client.KubernetesClientException: An error has occurred.
	...
Caused by: java.security.KeyStoreException: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
	...
Caused by: sun.security.pkcs11.wrapper.PKCS11Exception: CKR_SESSION_READ_ONLY
	...
Copy to Clipboard Toggle word wrap

如果要在启用了 FIPS 的集群中运行 AMQ Streams,您可以通过将 Cluster Operator 部署配置中禁用 FIPS_MODE 环境变量 来禁用 OpenJDK FIPS 模式。AMQ Streams 部署不兼容 FIPS,但 AMQ Streams 操作器及其操作对象都可以在启用了 FIPS 的 OpenShift 集群上运行。

流程

  1. 要在 Cluster Operator 中禁用 FIPS 模式,请更新其 Deployment 配置(install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml)并添加 FIPS_MODE 环境变量。

    Cluster Operator 的 FIPS 配置示例

    apiVersion: apps/v1
    kind: Deployment
    spec:
      # ...
      template:
        spec:
          serviceAccountName: strimzi-cluster-operator
          containers:
            # ...
            env:
            # ...
            - name: "FIPS_MODE"
              value: "disabled" 
    1
    
      # ...
    Copy to Clipboard Toggle word wrap

    1
    禁用 FIPS 模式。

    或者,直接编辑 Deployment

    oc edit deployment strimzi-cluster-operator
    Copy to Clipboard Toggle word wrap
  2. 如果您更新了 YAML 文件而不是直接编辑 Deployment,请应用更改:

    oc apply -f install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
    Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat