- Consolidate a multi-zone cluster into a single zone, for example to cut inter-zone data transfer cost in a non-production environment
- Spread a single-zone cluster across several zones
- Rebalance a cluster whose pods ended up unevenly placed after a zone outage or a capacity shortage
This page applies to clusters you manage through the
ZooKeeperCluster, BookKeeperCluster, PulsarBroker, and PulsarProxy resources. If you deploy with the sn-platform or sn-platform-slim Helm chart, follow Relocate ZooKeeper and BookKeeper pods for Private Cloud v1 instead.How it works
Brokers, proxies, and the other stateless components can move anywhere with a restart. ZooKeeper and BookKeeper cannot, because their data lives on persistent volumes that are bound to a zone (cloud block storage such as AWS EBS, GCP Persistent Disk, or Azure Disk) or to a single node (local SSD). A pod always follows its volume, so a ZooKeeper server or bookie stays where its volume is until the volume is replaced. Relocating a stateful pod therefore means giving it a new, empty volume in the target location and letting Pulsar refill it:- ZooKeeper replicates its full state to every server. A server that starts with empty volumes downloads a snapshot from the leader.
- BookKeeper does not. The operator decommissions the bookie first, which re-replicates every ledger it holds onto the other bookies, and only then deletes its volumes. The pod comes back as an empty bookie with the same identity.
Prerequisites
- Everything listed in the prerequisites of Replace ZooKeeper storage and Replace BookKeeper storage
- Permission to create a StorageClass, and to edit the
ZooKeeperCluster,BookKeeperCluster,PulsarBroker, andPulsarProxyresources
Inspect your environment first
1. Where pods and volumes are today.kubernetes.io/hostname (requiredDuringSchedulingIgnoredDuringExecution), each node runs at most one ZooKeeper server, one bookie, and one broker. The target location needs at least as many schedulable nodes as the largest of the ZooKeeper replica count, the bookie replica count, and the broker replica count (the broker HPA maximum, if autoscaling is enabled). Each node also needs enough allocatable CPU and memory for one pod of each. If you rely on a node autoscaler, make sure it can add nodes in the target location.
4. That BookKeeper does not require multiple racks. If you configured spec.config.rackAwareTopologyLabels on the BookKeeperCluster with the zone label and set bookkeeperClientEnforceMinNumRacksPerWriteQuorum: "true" on the brokers, the brokers refuse to create ledgers once fewer racks are available than bookkeeperClientMinNumRacksPerWriteQuorum. Before consolidating zones, set bookkeeperClientEnforceMinNumRacksPerWriteQuorum to "false" on the PulsarBroker, or remove the zone label from rackAwareTopologyLabels. Rack-aware placement without enforcement falls back to a single rack on its own and needs no change.
5. That the cluster is healthy. All pods must be Running and Ready, ZooKeeper must have a leader, and BookKeeper must report no under-replicated ledgers, as described in the “Inspect your environment first” sections of the two storage pages.
Step 1: Create a StorageClass for the target location
Create a StorageClass that provisions volumes only in the target location. Start from the class your ZooKeeper and BookKeeper volumes use today, keep its provisioner and parameters, give it a new name, and addallowedTopologies and volumeBindingMode: WaitForFirstConsumer:
Step 2: Point ZooKeeper and BookKeeper at the new StorageClass
Set the new StorageClass on theZooKeeperCluster and the BookKeeperCluster, as described in Option A of Replace ZooKeeper storage and Replace BookKeeper storage:
Step 3: Move the stateless components
Add anodeSelector for the target location to the stateless components. Each change rolls the component’s pods, and they come back in the target location.
topology.kubernetes.io/zone, remove it from spec.pod.affinity at the same time. The scheduler cannot satisfy it in a single zone.
Do not add a nodeSelector to the ZooKeeperCluster or to the bookies. The StorageClass from Step 1 already keeps relocated ZooKeeper servers and bookies in the target location.
Verify before continuing:
Step 4: Relocate ZooKeeper servers
For each ZooKeeper server whose volumes are outside the target location, follow Step 2 of Replace ZooKeeper storage. Skip Step 1 of that page; Step 2 on this page already did it. Because the new claims use the StorageClass from Step 1, the recreated pod is scheduled in the target location, and its new volumes are provisioned there. No other ZooKeeper server restarts.- Process followers first and the leader last.
- Delete the
dataanddata-logclaims of a server together. - Do not move to the next server until the leader reports all followers synced.
Delete, set their PersistentVolumes to Retain before deleting the claims, and note their names:
Step 5: Relocate bookies
For each bookie whose volumes are outside the target location, follow Step 2 of Replace BookKeeper storage. Skip Step 1 of that page; Step 2 on this page already did it. The operator re-replicates the bookie’s ledgers to the remaining bookies, deletes the old claims, and recreates the pod in the target location with new volumes.- Process one bookie at a time, from the highest ordinal down.
- Do not move to the next bookie until the replacement is Ready and writable and
listunderreplicatedreports nothing.
Finish
When every ZooKeeper server and bookie is in the target location:- Run the health checks from Inspect your environment first again.
- Retire the nodes in the old location if nothing else needs them.
nodeSelector there if they should follow.
Impact on clients
Roll back
Re-bind a ZooKeeper server to its old volume
Use this when a relocated ZooKeeper server fails to rejoin and its old PersistentVolume still exists, either because the StorageClass reclaim policy isRetain or because you set the volume to Retain in Step 4. The server comes back in its original location with its original data, then catches up from the leader.
Do not delete the new claim and recreate it by hand. As soon as the pod is deleted, the StatefulSet recreates the claim from its template, and that claim would get a new volume. Instead, reserve the old volume for the claim name, so the claim that the StatefulSet creates binds to it.
-
Reserve the old volume for the server’s claim. This clears the reference to the deleted claim and leaves the volume
Availablefor a claim with this name only:The volume showsAvailablewith your claim name. If the server also has adata-logvolume, repeat this step for it withCLAIM=data-log-$ZK. The recreated claim binds to the reserved volume even though the claim template now names the target StorageClass. If the claim staysPendinginstead, setstorageClassNameback to the original class as in Step 2, then repeat steps 3 and 4. - Make sure the old volume’s location has a schedulable node with room for the pod.
-
Delete the current claims and the pod:
-
Confirm that the recreated claim is bound to the old volume and the pod runs in the old location:
- Wait until the leader reports all followers synced, as in Confirm the server rejoined and fully synced. The pod can report Ready several seconds before the server has rejoined the quorum.
Clean up retained volumes
If your StorageClasses use reclaim policyRetain, every replaced ZooKeeper server and bookie leaves its old volumes behind in the Released phase. They keep incurring cost until you delete them. Follow the cleanup sections of Replace ZooKeeper storage and Replace BookKeeper storage once the cluster has run cleanly for a while.