Configure Kafka Rack Awareness
Apache Kafka®’s rack awareness feature spreads replicas of the same partition across different racks to minimize data loss if a rack fails.
When you enable rack awareness in Confluent for Kubernetes (CFK), CFK treats Kubernetes Availability Zones (AZs) as racks. It maps each Kafka rack to an AZ and places Kafka partition replicas across AZs.
For more information about Kafka rack awareness, see Balancing Replicas Across Racks.
For a configuration example, see Rack Awareness Tutorial.
For an example of deploying CFK across multiple Availability Zones, see Multiple Availability Zones Deployment.
Enable rack awareness
Check the Kubernetes node labels.
The Kubernetes cluster must have node labels set for the fault domain (the Availability Zone, or AZ), and the nodes in each zone should have the same node label.
Use the following command to check the node labels for
topology.kubernetes.io/zone:kubectl get node \ -o=custom-columns=NODE:.metadata.name,ZONE:.metadata.labels."topology\.kubernetes\.io/zone" \ | sort -k2
Configure your Kubernetes cluster with a service account. The service account must be configured with a
ClusterRoleorRolethat provides thegetandlistaccess to both thepodsandnodesresources.An example custom resource (CR) for a service account with the required role and role binding:
apiVersion: v1 kind: ServiceAccount metadata: name: kafka namespace: confluent --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: kafka-role rules: - apiGroups: - "" resources: - nodes - pods verbs: - get - list --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: name: kafka-binding subjects: - kind: ServiceAccount name: kafka namespace: confluent roleRef: kind: ClusterRole name: kafka-role apiGroup: rbac.authorization.k8s.io
Enable rack awareness in the Kafka CR:
spec: rackAssignment: nodeLabels: - topology.kubernetes.io/zone --- [1] podTemplate: serviceAccountName: --- [2] oneReplicaPerNode: true --- [3]
[1] Required.
[2] The service account that you set up in the previous step with the needed
ClusterRoleorRole.[3] Required. For details about this property, see One replica per node.
Apply the CR using the
kubectl applycommand.
Verify the rack awareness configuration
You can verify that rack awareness is correctly configured after you deploy CFK and Confluent Platform.
Check that the Kafka pods are created and running:
kubectl get pods -owide
Check the node labels for
topology.kubernetes.io/zone:kubectl get node \ -o=custom-columns=NODE:.metadata.name,ZONE:.metadata.labels."topology\.kubernetes\.io/zone"
Check that the
broker.rackproperty has been set inside broker 0 with the correct AZ, cross referencing the outputs from the previous steps:kubectl exec -it kafka-0 -- \ grep 'broker.rack' /opt/confluentinc/etc/kafka/kafka.properties
Verify that there is only one broker per node:
kubectl get pod \ -o=custom-columns=NODE:.spec.nodeName,NAME:.metadata.name \ | grep kafka | sort