1.2. AMQ Streams operator


AMQ Streams operator 是专门构建的,具有专家操作知识,以便在 OpenShift 上有效地管理 Kafka。每个操作器都执行不同的功能。

Cluster Operator
Cluster Operator 在 OpenShift 上处理 Apache Kafka 集群的部署和管理。它自动设置 Kafka 代理和其他 Kafka 组件和资源。
Topic Operator
主题 Operator 管理 Kafka 集群中的创建、配置和删除主题。
User Operator
User Operator 管理需要访问 Kafka 代理的 Kafka 用户。

部署 AMQ Streams 时,您首先部署 Cluster Operator。然后,Cluster Operator 已准备好处理 Kafka 的部署。您还可以使用 Cluster Operator (推荐)或独立 Operator 部署 Topic Operator 和 User Operator。您可以将独立 Operator 与不是由 Cluster Operator 管理的 Kafka 集群一起使用。

主题 Operator 和 User Operator 是实体 Operator 的一部分。Cluster Operator 可以基于 Entity Operator 配置部署一个或多个 Operator。

重要

要部署独立 Operator,您需要设置环境变量以连接到 Kafka 集群。如果您使用 Cluster Operator 部署 Operator,则不需要设置这些环境变量,因为它们将由 Cluster Operator 设置。

Operator 在 OpenShift 命名空间中观察和管理 AMQ Streams 资源。Cluster Operator 可以监控单个命名空间、多个命名空间或 OpenShift 集群中的所有命名空间。主题 Operator 和用户 Operator 可以监视单个命名空间。

  • Cluster Operator 监视 Kafka 资源
  • 主题 Operator 监视 KafkaTopic 资源
  • User Operator 监视 KafkaUser 资源

主题 Operator 和 User Operator 只能监视命名空间中的单个 Kafka 集群。它们只能连接到单个 Kafka 集群。

如果多个主题 Operator 监视同一命名空间,则可能会出现名称冲突和主题删除。这是因为每个 Kafka 集群都使用具有相同名称的 Kafka 主题(如 __consumer_offsets)。请确定只有一个主题 Operator 会监视给定的命名空间。

当将多个用户 Operator 与单个命名空间一起使用时,带有给定用户名的用户可在多个 Kafka 集群中存在。

如果使用 Cluster Operator 部署 Topic Operator 和 User Operator,它们默认监控 Cluster Operator 部署的 Kafka 集群。您还可以使用 operator 配置中的 watchedNamespace 指定命名空间。

对于每个 Operator 的独立部署,您可以指定一个命名空间和与 Kafka 集群的连接,以便在配置中监视。

1.2.2. 管理 RBAC 资源

Cluster Operator 为需要访问 OpenShift 资源的 AMQ Streams 组件创建和管理基于角色的访问控制(RBAC)资源。

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

通过以下 OpenShift RBAC 资源指定权限:

  • ServiceAccount
  • RoleClusterRole
  • RoleBindingClusterRoleBinding

1.2.2.1. 将权限委派给 AMQ Streams 组件

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

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

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

Expand
表 1.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 pod

<cluster_name>-bridge

Kafka Bridge pod

<cluster_name>-entity-operator

Entity Operator

Expand
表 1.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, Topic Operator, User Operator

strimzi-kafka-client

Cluster Operator,用于机架感知的 Kafka 客户端

Expand
表 1.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
表 1.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 的部署需要在 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:
    metadata:
      labels:
        name: strimzi-cluster-operator
        strimzi.io/kind: cluster-operator
    spec:
      serviceAccountName: strimzi-cluster-operator
      # ...
Copy to Clipboard Toggle word wrap

1.2.2.3. ClusterRole 资源

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

注意

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

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

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:
      - "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:
      - image.openshift.io
    resources:
      # The cluster operator needs to verify the image stream when used for Kafka Connect image build
      - imagestreams
    verbs:
      - get
  - 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 角色的节点。如果没有使用 rack 功能,且集群没有通过 nodeport 公开,则不会创建绑定。

Cluster Operator 的 ClusterRole 允许它将 OpenShift 节点的访问权限委派给 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 集群角色代表 Topic Operator 和 User Operator 所需的访问权限。

主题 Operator 生成带有状态信息的 OpenShift 事件,因此 & lt;cluster_name> -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 允许它将对 OpenShift 节点的访问权限委派给基于 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

1.2.2.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

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部