Skip to main content
Version: 22.3

Enable Rack Awareness in Kubernetes

Rack awareness allows you to distribute replicas of the same partition across different racks to minimize data loss in the event of a rack failure. A rack is a failure zone that has one or more Redpanda brokers assigned to it.

When you create a topic, you specify the number of partitions for the topic and the number of partition replicas. By default, Redpanda determines where to place the replicas on the cluster such that each replica is on a different broker, if possible.

By defining different racks for a Redpanda cluster, you can specify a preference for the way partition replicas are assigned to brokers. When Redpanda places partition replicas, it takes into account whether a replica has already been placed on a broker in a particular rack. If so, Redpanda chooses a broker in a different rack. This way, partition replicas are distributed across different failure zones, which provides a measure of fault tolerance in the event that a broker or an entire rack becomes unavailable.

When rack awareness is enabled, Redpanda places replicas according to these criteria:

  • Number of racks vs. replicas - If the cluster has more racks than the number of replicas, each replica is placed on a broker in a unique rack. If the cluster has fewer racks than the number of replicas, some replicas are placed on brokers in the same rack.
  • Number of available CPU cores - Brokers with more available CPU cores are chosen over brokers with fewer available CPU cores.
  • Broker utilization - Brokers with fewer partitions are chosen over brokers with more partitions.

When you enable rack awareness in the Redpanda Helm chart, Kubernetes failure zones are treated as racks. Redpanda maps each rack to a failure zone and places partition replicas across them. For more details about Kubernetes failure zones, see the Kubernetes documentation.

Prerequisites

Make sure that each of your Node resources is annotated with a key/value pair that corresponds to a failure zone. The Helm chart assigns each Redpanda broker to a particular rack, according to the failure zone of the Kubernetes node on which the broker is running.

Managed Kubernetes platforms in the cloud usually annotate Node resources with the availability zone in which the node instance is hosted. For example topology.kubernetes.io/zone=us-east-1a.

To check the value of the topology.kubernetes.io/zone key, run the following::

kubectl get node \
-o=custom-columns=NODE:.metadata.name,ZONE:.metadata.annotations."topology\.kubernetes\.io/zone"
Example output
NODE                 ZONE
example-worker us-east-1a
example-worker2 us-east-1b
example-worker3 us-east-1c

If you don't see any values in the Zone column, see the Bare-metal tab.

Configure rack awareness

To enable rack awareness in your Redpanda cluster, you need to override the default configuration in the Helm chart.

If your Node resources are annotated with the topology.kubernetes.io/zone key, do the following:

rack-awareness.yaml
rackAwareness:
enabled: true
serviceAccount:
create: true
rbac:
enabled: true
helm upgrade --install redpanda redpanda/redpanda -n redpanda --create-namespace \
--values rack-awareness.yaml

By default, the Helm chart sets the rack to the value in the well-known topology.kubernetes.io/zone key.

note

The serviceAccount and rbac configurations are required. These configurations allow the initialization container to securely read the node annotations using the Kubernetes API.

If your Node resources are annotated with a different key, set rackAwareness.nodeAnnotation to match your annotation key.

rack-awareness.yaml
rackAwareness:
enabled: true
nodeAnnotation: 'example'
serviceAccount:
create: true
rbac:
enabled: true
helm upgrade --install redpanda redpanda/redpanda -n redpanda --create-namespace \
--values rack-awareness.yaml

Verify that rack awareness is enabled

After deploying Redpanda, make sure that rack awareness is enabled and configured on your Redpanda brokers.

  1. Make sure that your Node resources include the correct annotations. For example, to check the value of the topology.kubernetes.io/zone key, run the following:

    kubectl get node \
    -o=custom-columns=NODE:.metadata.name,ZONE:.metadata.annotations."topology\.kubernetes\.io/zone"
    Example output
    NODE                 ZONE
    example-worker us-east-1a
    example-worker2 us-east-1b
    example-worker3 us-east-1c
  2. Make sure that rack awareness has been enabled and configured on your Redpanda brokers:

    kubectl -ti -n redpanda exec redpanda-0 -c redpanda -- \
    grep 'rack' etc/redpanda/redpanda.yaml
    Example output
    rack: us-east-1a
    enable_rack_awareness: true

Next steps

Use rack awareness with Continuous Data Balancing to continually maintain the configured replication level, even after a rack failure. For a given partition, Redpanda tries to move excess replicas from racks that have more than one replica to racks that have no replicas.

See the Helm chart's values.yaml file for more details about the rackAwareness, serviceAccount, and rbac configuration options.

What do you like about this doc?




Optional: Share your email address if we can contact you about your feedback.

Let us know what we do well: