Perform a Rolling Restart of Redpanda in Kubernetes

A rolling restart involves restarting one broker at a time while the remaining brokers in your cluster continue running. Rolling restarts help to minimize downtime during a full cluster restart. You should perform a rolling restart during operations such as configuration updates that require a restart, version upgrades, or cluster maintenance.

Prerequisites

You must have the following:

What happens during a rolling restart

When you run Redpanda in Kubernetes, your Redpanda cluster is managed as a StatefulSet where each broker runs inside its own Pod. As a result, you can perform a rolling restart using the Kubernetes API to terminate one Pod at a time, starting from the one with the highest ordinal.

During a rolling restart the Redpanda Helm chart automates the following procedure on each broker, using the preStop and postStart lifecycle hooks:

  1. The preStop hook is executed immediately before a container is terminated. The preStop hook is responsible for the following:

    1. Place the broker into maintenance mode.

      Placing brokers into maintenance mode reduces the risk of interruption or degradation in service. When a broker is placed into maintenance mode, it reassigns its partition leadership to other brokers for all topics that have a replication factor greater than one (three is the default replication factor for topics). Reassigning partition leadership involves draining leadership from the broker and transferring that leadership to another broker.

    2. Terminate the Pod.

      After the preStop hook completes its tasks, Kubernetes sends a SIGTERM signal to the container, signaling it to shut down.

      Maintenance mode may not have finished when the SIGTERM is sent. As a result, Kubernetes waits for the duration of the terminationGracePeriodSeconds for Redpanda to shut down gracefully. If it’s still executing, a SIGKILL is sent to the container to forcefully terminate Redpanda. The Pod is then terminated and restarted due to the default rolling update policy of the StatefulSet.

      The default terminationGracePeriod is 90 seconds, which should be long enough for maintenance mode to finish in large clusters. You can test different values in a development environment. To configure the terminationGracePeriod, use the statefulset.podTemplate.spec.terminationGracePeriodSeconds setting.

  2. The postStart hook is executed immediately after a container is created. The postStart hook takes the broker out of maintenance mode. This action re-integrates the broker into the cluster, allowing it to start handling requests and participate in the cluster’s operations again.

How the Redpanda Operator gates each restart

If the Redpanda Operator manages your cluster, the operator itself replaces the Pods during restarts that it performs, such as applying a configuration change that requires a restart or rolling out a version upgrade. In Redpanda Operator v26.2.1 or later, the operator gates every restart with Redpanda’s per-broker restart probes, in addition to the maintenance-mode hooks. It restarts at most one broker per pass and re-evaluates the cluster against a fresh view of the brokers before touching the next Pod:

  1. Before restarting a broker, the operator calls the broker’s pre-restart probe (Admin API GET /v1/broker/pre_restart_probe) to determine which partitions the restart would put at risk. The operator delays the restart, and retries on its next pass, while the probe reports any of the following risks:

    • Partitions that would lose data acknowledged with acks=1

    • Partitions that would become unavailable

    • Partitions that could no longer complete acks=all produce requests

    Partitions on topics with a replication factor of 1 do not block the restart, because they have no redundancy for the restart to preserve. To keep them available, temporarily increase their replication factor before you restart. See Perform a rolling restart.

  2. After the restarted broker’s Pod passes its Kubernetes readiness probe, the operator calls the broker’s post-restart probe (Admin API GET /v1/broker/post_restart_probe) and holds the next restart until the broker reports that it has reclaimed 100% of its in-sync replica load. A Pod can become Ready while the broker inside it is still replaying partition state from its peers, so this gate prevents the operator from taking a second replica down before the first has caught up.

The restart probes require Redpanda 25.1 or later. On earlier Redpanda versions, the operator falls back to gating restarts on the cluster-wide health check. The probes run only while a restart is in progress, so they add no load during steady-state operation.

Impact of broker restarts

When brokers restart, clients may experience higher latency, nodes may experience CPU spikes when the broker becomes available again, and you may receive alerts about under-replicated partitions. Topics that weren’t using replication (that is, topics that had replication.factor=1) will be unavailable.

Temporary increase in latency on clients (producers and consumers)

When you restart one or more brokers in a cluster, clients (consumers and producers) may experience higher latency due to partition leadership reassignment. Clients must communicate with the leader of a partition, so a client may send a request to a broker whose leadership has moved. The broker then returns a NOT_LEADER_OR_FOLLOWER error (formerly NOT_LEADER_FOR_PARTITION).

Redpanda shortens this interruption in two ways:

  • The error response names the new leader (KIP-951). A client that supports KIP-951 retries against the new leader without first requesting metadata.

  • Brokers briefly hold requests during the leadership change instead of failing them immediately. A broker that is becoming the leader holds produce, fetch, and OffsetForLeaderEpoch requests until it can serve them. A broker that is handing off leadership holds a produce request it refuses until it knows the new leader, so the error names that leader. While the former leader doesn’t yet know its successor, a fetch of that partition returns no data instead of an error. Fetch requests from consumers that set client.rack are not held.

Each hold lasts at most the time set by the kafka_leader_hint_wait_ms cluster property (default: 100 milliseconds). Set it to 0 to turn off these behaviors, so that requests fail immediately and name the leader known at that time.

For example, when broker A hands off leadership of a partition to broker B:

  1. Client sends a produce request to broker A.

  2. Broker A holds the request until it knows that broker B is the new leader, then returns NOT_LEADER_OR_FOLLOWER naming broker B.

  3. Client sends the request to broker B, which serves it.

A client still requests metadata from the cluster to find the new leader when:

  • It doesn’t support KIP-951.

  • The error doesn’t name a leader that can serve the request.

  • It receives other retryable errors that indicate that its metadata may be stale.

Clients based on librdkafka, including the confluent-kafka-* clients, receive no leader in produce error responses, so they refresh metadata instead. Fetch error responses still name the leader for these clients.

To see how often brokers hold requests, and whether the leadership change finished before the hold expired, monitor the vectorized_kafka_leader_waits_total internal metric. Its request label is produce or fetch (fetch and OffsetForLeaderEpoch requests), and its outcome label is resolved or expired.

CPU spikes upon broker restart

When a restarted broker becomes available again, you may see your nodes' CPU usage increase temporarily. This temporary increase in CPU usage is due to the cluster rebalancing the partition replicas.

Under-replicated partitions

When a broker is in maintenance mode, Redpanda continues to replicate updates to that broker. When a broker is taken offline during a restart, partitions with replicas on the broker could become out of sync until it is brought back online. Once the broker is available again, data is copied to its under-replicated replicas until all affected partitions are in sync with the partition leader.

Perform a rolling restart

These steps restart the brokers of a cluster that is managed by a StatefulSet. If the cluster uses Broker resources, no StatefulSet exists. The Redpanda Operator restarts the brokers one at a time when a configuration change requires it. To restart a single broker, delete its Pod with kubectl delete pod <pod-name> --namespace <namespace>. The Broker resource recreates the Pod with the same PVC and broker ID. You can’t trigger a rolling restart of the whole cluster. See Limitations.
  1. Check for topics that have a replication factor greater than one.

    Partitions that live on only one broker will be offline during the restart. If you have topics with a replication factor of 1, and if you have sufficient disk space, temporarily increase the replication factor to limit outages for these topics during the rolling upgrade.

  2. Ensure that the cluster is healthy:

    kubectl exec <pod-name> --namespace <namespace> -c redpanda -- \
      rpk cluster health

    The draining process won’t start until the cluster is healthy.

    Example output:
    CLUSTER HEALTH OVERVIEW
    =======================
    Healthy:                     true (1)
    Controller ID:               0
    All nodes:                   [0 1 2] (2)
    Nodes down:                  [] (3)
    Leaderless partitions:       [] (3)
    Under-replicated partitions: [] (3)
    1 The cluster is either healthy (true) or unhealthy (false).
    2 The node IDs of all brokers in the cluster.
    3 These fields contain data only when the cluster is unhealthy.
  3. Trigger a rolling restart of all Pods in the StatefulSet:

    kubectl rollout restart statefulset redpanda --namespace=<namespace>
  4. Wait for all Pods to restart:

    kubectl rollout status statefulset redpanda --namespace=<namespace> --watch

Verify the cluster’s health

To verify that the cluster is running properly, run:

kubectl exec <pod-name> --namespace <namespace> -c redpanda -- \
  rpk cluster health

To view additional information about your brokers, run:

kubectl exec <pod-name> --namespace <namespace> -c redpanda -- \
  rpk cluster info -b --detailed

Suggested reading