13.2. 使用 Cluster Operator
使用 Cluster Operator 部署 Kafka 集群和其他 Kafka 组件。
13.2.1. 基于角色的访问控制(RBAC)资源 复制链接链接已复制到粘贴板!
Cluster Operator 为需要访问 OpenShift 资源的 AMQ Streams 组件创建和管理 RBAC 资源。
要使 Cluster Operator 正常工作,OpenShift 集群中的权限需要与 Kafka 资源交互,如 Kafka 和 KafkaConnect,以及 ConfigMap、Pod、Deployment、StatefulSet 和 Service 等受管资源。
通过 OpenShift 基于角色的访问控制(RBAC)资源指定权限:
-
ServiceAccount -
Role和ClusterRole -
RoleBinding和ClusterRoleBinding
13.2.1.1. 将权限委派给 AMQ Streams 组件 复制链接链接已复制到粘贴板!
Cluster Operator 在名为 strimzi-cluster-operator 的服务帐户下运行。分配了集群角色,授予其为 AMQ Streams 组件创建 RBAC 资源的权限。角色绑定将集群角色绑定与服务帐户关联。
OpenShift 可防止在一个 ServiceAccount 下运行的组件授予授予 ServiceAccount 没有的另一个 ServiceAccount 特权。因为 Cluster Operator 会创建它管理的资源所需的 RoleBinding 和 ClusterRoleBinding RBAC 资源,所以它需要一个赋予同一权限的角色。
下表描述了 Cluster Operator 创建的 RBAC 资源。
| 名称 | 使用的 |
|---|---|
|
| Kafka 代理 pod |
|
| ZooKeeper pod |
|
| Kafka Connect pod |
|
| MirrorMaker pod |
|
| MirrorMaker 2 pod |
|
| Kafka Bridge pod |
|
| Entity Operator |
| 名称 | 使用的 |
|---|---|
|
| Cluster Operator |
|
| Cluster Operator |
|
| Cluster Operator |
|
| Cluster Operator,机架功能(使用时) |
|
| Cluster Operator, Topic Operator, User Operator |
|
| Cluster Operator,用于机架感知的 Kafka 客户端 |
| 名称 | 使用的 |
|---|---|
|
| Cluster Operator |
|
| Cluster Operator,用于机架感知的 Kafka 代理 |
|
| Cluster Operator,用于机架感知的 Kafka 客户端 |
| 名称 | 使用的 |
|---|---|
|
| Cluster Operator |
|
| Cluster Operator,用于机架感知的 Kafka 代理 |
13.2.1.2. 使用一个 ServiceAccount 运行 Cluster Operator 复制链接链接已复制到粘贴板!
Cluster Operator 最好使用 ServiceAccount 运行:
Cluster Operator 的 ServiceAccount 示例
apiVersion: v1
kind: ServiceAccount
metadata:
name: strimzi-cluster-operator
labels:
app: strimzi
然后,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:
# ...
注意第 12 行,其中 strimzi-cluster-operator 指定为 serviceAccountName。
13.2.1.3. ClusterRole 资源 复制链接链接已复制到粘贴板!
Cluster Operator 使用 ClusterRole 资源来提供对资源所需的访问权限。根据 OpenShift 集群设置,可能需要集群管理员来创建集群角色。
只有在创建 ClusterRole 资源时才需要集群管理员权限。Cluster Operator 不会在集群管理员帐户下运行。
ClusterRole 资源遵循 最小特权原则,并只包含 Cluster Operator 操作 Kafka 组件集群所需的权限。第一个分配的权限集允许 Cluster Operator 管理 OpenShift 资源,如 StatefulSet、Deployment、Pod 和 ConfigMap。
Cluster Operator 需要所有集群角色才能委派权限。
Cluster Operator 使用 strimzi-cluster-operator-namespaced 和 strimzi-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
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
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
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
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
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
13.2.1.4. ClusterRoleBinding 资源 复制链接链接已复制到粘贴板!
Cluster Operator 使用 ClusterRoleBinding 和 RoleBinding 资源将其 ClusterRole 与 ServiceAccount 相关联:包含集群范围资源的集群角色需要集群角色绑定。
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
委派权限时使用的集群角色还需要集群角色绑定:
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
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
仅包含命名空间的资源的集群角色仅使用角色绑定绑定。
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
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
13.2.2. Cluster Operator 日志记录的 ConfigMap 复制链接链接已复制到粘贴板!
Cluster Operator 日志记录通过名为 strimzi-cluster-operator 的 ConfigMap 来配置。
安装 Cluster Operator 时会创建一个包含日志记录配置的 ConfigMap。此 ConfigMap 在文件 install/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
或者,直接编辑 ConfigMap :
oc edit configmap strimzi-cluster-operator
要更改重新加载间隔的频率,请在创建的 ConfigMap 的 monitorInterval 选项中设置以秒为单位的时间。
如果在部署 Cluster Operator 时缺少 ConfigMap,则使用默认的日志记录值。
如果在部署 Cluster Operator 后意外删除 ConfigMap,则会使用最近载入的日志配置。创建新的 ConfigMap 以加载新的日志记录配置。
不要从 ConfigMap 中删除 monitorInterval 选项。
13.2.3. 使用环境变量配置 Cluster Operator 复制链接链接已复制到粘贴板!
您可以使用环境变量配置 Cluster Operator。这里列出了支持的环境变量。
环境变量在其 Deployment 配置文件中为 Cluster Operator 的容器镜像指定。(install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml)
STRIMZI_NAMESPACE以逗号分隔的 Operator 运行的命名空间列表。如果没有设置,则为空字符串,或设置为
*,Cluster Operator 在所有命名空间中运行。Cluster Operator 部署可能会使用 Downward API 来自动将其设置为部署了 Cluster Operator 的命名空间。
Cluster Operator 命名空间的配置示例
env: - name: STRIMZI_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespaceSTRIMZI_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 admin 客户端的会话超时,以毫秒为单位。如果 Cluster Operator 的 ZooKeeper 请求因为超时问题定期失败,请增加这个值。通过
maxSessionTimeout配置在 ZooKeeper 服务器端设置最大允许会话时间。默认情况下,最大会话超时值为 20 倍,即默认tickTime(其默认值为 2000)为 40000 ms。如果您需要更高的超时,请更改maxSessionTimeoutZooKeeper 服务器配置值。 STRIMZI_OPERATIONS_THREAD_POOL_SIZE- 可选,默认 10。worker 线程池大小,用于各种异步和阻止由 Cluster Operator 运行的操作。
STRIMZI_OPERATOR_NAME- 可选,默认为 pod 的主机名。在发出 OpenShift 事件时,Operator 名称标识 AMQ Streams 实例。
STRIMZI_OPERATOR_NAMESPACE运行 Cluster Operator 的命名空间的名称。不要手动配置此变量。使用 Downward API。
env: - name: STRIMZI_OPERATOR_NAMESPACE valueFrom: fieldRef: fieldPath: metadata.namespaceSTRIMZI_OPERATOR_NAMESPACE_LABELS可选。运行 AMQ Streams Cluster Operator 的命名空间标签。使用命名空间标签在 网络策略 中配置命名空间选择器。网络策略只允许 AMQ Streams Cluster Operator 从带有这些标签的命名空间中访问操作对象。如果没有设置,则网络策略中的命名空间选择器被配置为允许从 OpenShift 集群中的任何命名空间中访问 Cluster Operator。
env: - name: STRIMZI_OPERATOR_NAMESPACE_LABELS value: label1=value1,label2=value2STRIMZI_LABELS_EXCLUSION_PATTERN可选,默认的正则表达式为
^app.kubernetes.io/(?!part-of).*。用于过滤从主自定义资源传播到其子资源的正则表达式排除模式。标签排除过滤器不适用于模板部分中的标签,如spec.kafka.template.pod.metadata.labels。env: - name: STRIMZI_LABELS_EXCLUSION_PATTERN value: "^key1.*"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 仅在设置了指定标签的自定义资源上运行。Operator 不会看到没有这些标签的资源。标签选择器适用于
Kafka,KafkaConnect,KafkaBridge,KafkaMirrorMaker, 和KafkaMirrorMaker2资源。只有在对应的 Kafka 和 Kafka Connect 集群具有匹配的标签时,才会执行KafkaRebalance和KafkaConnector资源。env: - name: STRIMZI_CUSTOM_RESOURCE_SELECTOR value: label1=value1,label2=value2STRIMZI_KAFKA_IMAGES-
必需。从 Kafka 版本到包含该版本的 Kafka 代理的对应 Docker 镜像的映射。所需的语法为空格或以逗号分隔的 <
version> = <image>对。例如3.3.1=registry.redhat.io/amq-streams/kafka-33-rhel8:2.4.0, 3.4.0=registry.redhat.io/amq-streams/kafka-34-rhel8:2.4.0。当指定了属性Kafka.spec.kafka.version但没有在Kafka资源的Kafka.spec.kafka.image时使用这个。 STRIMZI_DEFAULT_KAFKA_INIT_IMAGE-
可选,默认
registry.redhat.io/amq-streams/strimzi-rhel8-operator:2.4.0。如果没有将镜像指定为Kafka资源中的kafka-init-image,则用作 init 容器的默认镜像名称。init 容器在代理进行初始配置工作之前启动,如机架支持。 STRIMZI_KAFKA_CONNECT_IMAGES-
必需。从 Kafka 版本映射到那个版本的 Kafka Connect 的对应 Docker 镜像。所需的语法为空格或以逗号分隔的 <
version> = <image>对。例如3.3.1=registry.redhat.io/amq-streams/kafka-33-rhel8:2.4.0, 3.4.0=registry.redhat.io/amq-streams/kafka-34-rhel8:2.4.0。当指定KafkaConnect.spec.version属性但没有KafkaConnect.spec.image时,会使用它。 STRIMZI_KAFKA_MIRROR_MAKER_IMAGES-
必需。此版本从 Kafka 版本到 MirrorMaker 的对应 Docker 镜像的映射。所需的语法为空格或以逗号分隔的 <
version> = <image>对。例如3.3.1=registry.redhat.io/amq-streams/kafka-33-rhel8:2.4.0, 3.4.0=registry.redhat.io/amq-streams/kafka-34-rhel8:2.4.0。当指定KafkaMirrorMaker.spec.version属性但没有KafkaMirrorMaker.spec.image时,会使用它。 STRIMZI_DEFAULT_TOPIC_OPERATOR_IMAGE-
可选,默认
registry.redhat.io/amq-streams/strimzi-rhel8-operator:2.4.0。如果没有将镜像指定为Kafka资源中的Kafka.spec.entityOperator.topicOperator.image,则部署 Topic Operator 时使用的镜像名称作为默认镜像。 STRIMZI_DEFAULT_USER_OPERATOR_IMAGE-
可选,默认
registry.redhat.io/amq-streams/strimzi-rhel8-operator:2.4.0。如果没有将镜像指定为 Kafka 资源中的Kafka.spec.entityOperator.userOperator.image,则部署 User Operator 时使用的镜像名称。 STRIMZI_DEFAULT_TLS_SIDECAR_ENTITY_OPERATOR_IMAGE-
可选,默认
registry.redhat.io/amq-streams/kafka-34-rhel8:2.4.0。如果没有将镜像指定为 Kafka 资源中的Kafka.spec.entityOperator.tlsSidecar.image,则用作实体 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 在 Cluster Operator 创建的所有 pod 的imagePullSecrets属性中指定。更改此列表会导致所有 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/amd64KUBERNETES_SERVICE_DNS_DOMAIN可选。覆盖默认的 OpenShift DNS 域名后缀。
默认情况下,OpenShift 集群中分配的服务具有使用默认后缀
cluster.local的 DNS 域名。例如,对于 broker kafka-0 :
<cluster-name>-kafka-0.<cluster-name>-kafka-brokers.<namespace>.svc.cluster.localDNS 域名添加到用于主机名验证的 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 解析器中缓存成功名称查找的秒数。任何负值都表示缓存永久缓存。zero 意味着不会缓存,这可用于避免因为应用长缓存策略而连接错误。 STRIMZI_POD_SET_RECONCILIATION_ONLY-
可选,默认为
false。当设置为true时,Cluster Operator 只协调StrimziPodSet资源,以及其它自定义资源(Kafka、KafkaConnect等)的任何更改。此模式可用于确保根据需要重新创建 pod,但不会对集群进行其他更改。 STRIMZI_FEATURE_GATES- 可选。启用或禁用由 功能门控制的功能和功能。
STRIMZI_POD_SECURITY_PROVIDER_CLASS-
可选。配置可插拔
PodSecurityProvider类,可用于为 Pod 和容器提供安全上下文配置。
13.2.3.1. 领导选举环境变量 复制链接链接已复制到粘贴板!
在运行额外的 Cluster Operator 副本时,请使用领导选举环境变量。您可以运行额外的副本来防止重大故障导致的中断。
STRIMZI_LEADER_ELECTION_ENABLED-
可选,
默认禁用(默认为 )。启用或禁用领导选举机制,允许额外的 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.namespaceSTRIMZI_LEADER_ELECTION_IDENTITY启用领导选举机制时需要。配置在领导选举过程中使用的给定 Cluster Operator 实例的身份。对于每个 operator 实例,身份必须是唯一的。您可以使用 Downward API 将其配置为部署 Cluster Operator 的 pod 的名称。
env: - name: STRIMZI_LEADER_ELECTION_IDENTITY valueFrom: fieldRef: fieldPath: metadata.nameSTRIMZI_LEADER_ELECTION_LEASE_DURATION_MS- 可选,默认 15000 ms。指定获取租期有效的持续时间。
STRIMZI_LEADER_ELECTION_RENEW_DEADLINE_MS- 可选,默认的 10000 ms。指定领导应尝试维护领导期。
STRIMZI_LEADER_ELECTION_RETRY_PERIOD_MS- 可选,默认的 2000 ms。指定领导到租期锁定的更新频率。
13.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
#...
13.2.3.3. 为定期协调设置时间间隔 复制链接链接已复制到粘贴板!
使用 STRIMZI_FULL_RECONCILIATION_INTERVAL_MS 变量来设置定期协调的时间间隔。
Cluster Operator 对从 OpenShift 集群接收的适用集群资源的所有通知做出反应。如果操作器没有运行,或者因为某种原因没有收到通知,资源将从正在运行的 OpenShift 集群状态不同步。为了正确处理故障转移,Cluster Operator 会执行定期协调过程,以便它可以将资源的状态与当前集群部署进行比较,以便在所有这些部署之间具有一致的状态。
13.2.4. 使用默认代理设置配置 Cluster Operator 复制链接链接已复制到粘贴板!
如果您在 HTTP 代理后运行 Kafka 集群,您仍然可以在集群内和移出数据。例如,您可以使用连接器运行 Kafka Connect,该连接器从代理外推送和拉取镜像。或者,您可以使用代理与授权服务器连接。
配置 Cluster Operator 部署以指定代理环境变量。Cluster Operator 接受标准代理配置(HTTP_PROXY、HTTPS_PROXY 和 NO_PROXY)作为环境变量。代理设置适用于所有 AMQ Streams 容器。
代理地址的格式为 http://IP-ADDRESS:PORT-NUMBER。要使用名称和密码设置代理,格式为 http://USERNAME:PASSWORD@IP-ADDRESS:PORT-NUMBER。
先决条件
-
您需要具有权限的帐户来创建和管理
CustomResourceDefinition和 RBAC (ClusterRole和RoleBinding)资源。
流程
要在 Cluster Operator 中添加代理环境变量,请更新其
部署配置 (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 # ...或者,直接编辑
部署:oc edit deployment strimzi-cluster-operator如果您更新了 YAML 文件而不是直接编辑
Deployment,请应用更改:oc create -f install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml
13.2.5. 使用领导选举机制运行多个 Cluster Operator 副本 复制链接链接已复制到粘贴板!
默认 Cluster Operator 配置启用 领导选举机制。使用领导选举机制运行 Cluster Operator 的多个并行副本。一个副本被选为活跃领导值,并运行部署的资源。其他副本以待机模式运行。当领导停止或失败时,其中一个备用副本被选为新领导,并开始操作部署的资源。
默认情况下,AMQ Streams 使用单个 Cluster Operator 副本运行,该副本始终是领导副本。当单个 Cluster Operator 副本停止或失败时,OpenShift 会启动新的副本。
运行具有多个副本的 Cluster Operator 并不重要。但是,在出现大规模中断时,在待机上具有副本非常有用。例如,假设多个 worker 节点或整个可用区失败。故障可能会导致 Cluster Operator pod 和许多 Kafka pod 同时停机。如果后续的 pod 调度导致资源丢失,这可能会在运行单个 Cluster Operator 时延迟操作。
13.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
领导选举具有自己的 ClusterRole 和 RoleBinding RBAC 资源,这些资源以 Cluster Operator 运行的命名空间为目标,而不是它监视的命名空间。
默认部署配置在与 Cluster Operator 相同的命名空间中创建一个名为 strimzi-cluster-operator 的 Lease 资源。Cluster Operator 使用租期来管理领导选举机制。RBAC 资源提供使用 Lease 资源的权限。如果您使用不同的 Lease 名称或命名空间,请相应地更新 ClusterRole 和 RoleBinding 文件。
先决条件
-
您需要具有权限的帐户来创建和管理
CustomResourceDefinition和 RBAC (ClusterRole和RoleBinding)资源。
流程
编辑用于部署 Cluster Operator 的 Deployment 资源,该资源在 060-Deployment-strimzi-cluster-operator.yaml 文件中定义。
将
replicas属性从 default (1)更改为与所需副本数匹配的值。增加 Cluster Operator 副本的数量
apiVersion: apps/v1 kind: Deployment metadata: name: strimzi-cluster-operator labels: app: strimzi spec: replicas: 3检查是否设置了 leader election
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有关可用环境变量的描述,请参阅 第 13.2.3.1 节 “领导选举环境变量”。
如果您为领导选举机制中使用的
Lease资源指定了不同的名称或命名空间,请更新 RBAC 资源。(可选)在
022-ClusterRole-strimzi-cluster-operator-role.yaml文件中编辑ClusterRole资源。使用
Lease资源的名称更新resourceNames。将 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 # ...(可选)在
022-RoleBinding-strimzi-cluster-operator.yaml文件中编辑RoleBinding资源。使用
Lease资源的名称以及创建它的命名空间更新subjects.name和subjects.namespace。将 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 # ...部署 Cluster Operator:
oc create -f install/cluster-operator -n myproject检查部署的状态:
oc get deployments -n myproject输出显示部署名称和就绪度
NAME READY UP-TO-DATE AVAILABLE strimzi-cluster-operator 3/3 3 3READY显示就绪/预期的副本数。当AVAILABLE输出显示正确的副本数时,部署可以成功。
13.2.6. FIPS 支持 复制链接链接已复制到粘贴板!
联邦信息处理标准(FIPS)是计算机安全和互操作性的标准。当在启用了 FIPS 的 OpenShift 集群上运行 AMQ Streams 时,AMQ Streams 容器镜像中使用的 OpenJDK 会自动切换到 FIPS 模式。在版本 2.4 中,AMQ Streams 可以在启用了 FIPS 的 OpenShift 集群上运行,而无需更改或特殊配置。它只使用 OpenJDK 中的 FIPS 兼容安全库。
最小密码长度
在 FIPS 模式下运行时,SCRAM-SHA-512 密码至少需要 32 个字符。从 AMQ Streams 2.4 中,AMQ Streams User Operator 中的默认密码长度也被设置为 32 个字符。如果您的 Kafka 集群带有使用小于 32 个字符的密码长度的自定义配置,则需要更新您的配置。如果您有少于 32 个字符的密码,则需要重新生成具有所需长度的密码。例如,您可以通过删除用户 secret 并等待 User Operator 创建具有适当长度的新密码来完成此操作。
如果使用启用了 FIPS 的 OpenShift 集群,与常规 OpenShift 集群相比,可能会遇到更高的内存消耗。为了避免任何问题,我们建议将内存请求增加到至少 512Mi。
13.2.6.1. 禁用 FIPS 模式 复制链接链接已复制到粘贴板!
当在启用了 FIPS 的 OpenShift 集群中运行时,AMQ Streams 会自动切换到 FIPS 模式。通过在 Cluster Operator 的部署配置中将 FIPS_MODE 环境变量设置为 禁用 FIPS 模式。禁用 FIPS 模式后,AMQ Streams 会在 OpenJDK 中为所有组件禁用 FIPS。禁用 FIPS 模式后,AMQ Streams 不兼容 FIPS。AMQ Streams operator 以及所有操作对象的运行方式与在启用了 FIPS 的 OpenShift 集群中运行的方式相同。
流程
要在 Cluster Operator 中禁用 FIPS 模式,更新其
部署配置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 # ...- 1
- 禁用 FIPS 模式。
或者,直接编辑
部署:oc edit deployment strimzi-cluster-operator如果您更新了 YAML 文件而不是直接编辑
Deployment,请应用更改:oc apply -f install/cluster-operator/060-Deployment-strimzi-cluster-operator.yaml