spec.replication in
the deployment body.
A follower is never promoted automatically. To take writes on its data,
fence it and promote it.
What a follower guarantees
- Every node, the one KubeBlocks shows as primary included, is a read-only
replica of the source. Writes answer
READONLY. - No node is ever promoted automatically: its replica priority stays
0, and the deployment’s own sentinels stop monitoring it. - The deployment’s own sentinels can’t point the replicas anywhere else.
replica-read-onlycan’t be changed inconfig.server, andreplica-prioritycan’t be set there at all: a value set now would stay after a promotion.REPLICAOFstays available, so you can still promote a node by hand in an emergency. - A switchover is refused with
409, since there is no primary to hand over from.
Requirements
Fencing a deployment needs none of the external domain, the absence of TLS or a
reachable source: a fenced deployment connects nowhere.
Create a follower
1
Copy the source's replication password
The follower authenticates to the source as the source’s replication
account, Leave
kbreplicator by default. Its password is the source’s default
account password. Copy it into a Secret in the follower’s namespace:passwordSecretRef out only for a source without a password: the
check before create sends PING with no password then, so a source that
asks for one answers 422. Name the Secret even when both deployments
share a password.2
Create the deployment with spec.replication
Point
source.host at the source’s primary, by a DNS name the follower’s
pods resolve, such as the source’s external DNS record. An IP address is
refused, because the API can’t tell whether it is the follower’s own:3
Check it replicates
Open the deployment’s Pods tab: a note says what the deployment
follows, and no pod offers Switchover. Every node reports role
slave in INFO replication, with master_host set to the source.PING to the source as the replication
account. A source that doesn’t answer, or refuses the credentials, answers
422 on spec.replication.source with the reason. A Job that can’t run at
all answers 503.
source.host names one node. Point it at a name that follows the source’s
primary, or re-point the follower after the source fails over. A follower
of a node that became a replica still replicates, through that replica.Fence, re-point and follow again
Changingspec.replication restarts the follower’s nodes straight away, without
waiting for the maintenance window: fencing
during an outage can’t wait.
In the Admin UI, a follower’s Pods tab offers Fence; it asks you to
confirm first. Re-pointing and following again are done with the CLI or the
API.
A fenced deployment keeps
source, so following again needs no address. A new
source is checked like a create.
You can also fence a deployment that runs as a primary, for example a former
primary that comes back after a region outage while its standby has taken
over. Its nodes keep their data and stop taking writes.
Promote a follower
Promoting gives a fenced deployment a primary of its own: one of its nodes takes writes, the others replicate from it, andspec.replication goes away.
It is how a standby takes over when its source is lost for good.
1
Fence the deployment
2
Fence the source too, if it still runs
In a planned move, or once a lost region comes back, fence the deployment
you followed as well. Its sentinels know this deployment’s nodes as its
replicas, and would turn the node you promote back into one whenever
they can log in to it. Fencing the source makes them forget it: wait
until its nodes have restarted and it is running again. Each node asks
the sentinels as it starts, so check that none still monitors the source
(
SENTINEL MASTERS lists nothing on each). Skip this when the source is
gone.3
Promote it
POST /api/clusters/{name}/ops/promote, or Promote in the
deployment’s Pods tab. It answers 202 with the operation’s name, and
409 for a deployment that isn’t fenced or is being promoted already.4
Wait for it to finish
The operation runs on the node KubeBlocks shows as primary, node 0 unless
it is down:
- Every node reports how much of the old source’s data it received. If another node received more, this one catches up from it first, for up to five minutes, so no write any node holds is lost.
- The node becomes a writable primary and the others replicate from it. With sentinels, they monitor it and fail it over from then on.
spec.replication.
The nodes restart and follow the new primary. The operation shows in the
Operations tab, and the audit log records both steps.spec.replication can’t change.
A promotion fails while a node doesn’t answer: that node may have received
more of the old source’s data than any node that does, and it would lose that
part once it follows the new primary. Bring the node back and promote again.
If you can’t, and accept losing what only that node received, promote without
it: add --allow-unreachable-pods to the CLI command, send
{"allowUnreachablePods": true} in the API request’s body, or tick Promote
even if a pod doesn’t answer in the dialog. The node follows the new primary
when it restarts.
A promotion that fails leaves the deployment fenced: the operation puts back
what it changed, and spec.replication stays. Read the operation’s log for
why, and for anything it couldn’t put back, before you promote it again. It
fails rather than guess when a node answers with an error, or when a node
promoted by hand is behind another.
Promote a node by hand
For an emergency when the promote operation can’t run, for example while the Admin Server is down. The deployment takes writes within seconds, but it stays fenced in its spec, so the API keeps treating it as fenced. Promote it with the operation afterwards: it accepts the node you promoted.1
Fence the deployment
2
Promote the node KubeBlocks shows as primary
That is node 0, or the next node while node 0 is down. The deployment’s
primary Service already sends writes to it. Find it:Then promote it,
<primary-pod> being the name that printed:3
Point every other node at it
For each of the other nodes,
<other-pod>:- Anything that restarts a node fences it again: a node that moves, a restart, or a change applied in the maintenance window. If that node is the one you promoted, the deployment stops taking writes until you promote one again.
- The node running as primary keeps the primary role and the primary Service, even if a node with a lower number comes back.
- The sentinels don’t monitor the deployment, so nothing fails it over if the node you promoted goes down.
- The Admin UI and API still show the deployment as fenced.
Restore a copy
Slower, but the copy is an ordinary deployment that the API fully manages.- Fence the follower, so its data stops changing.
- Back it up.
- Restore the backup to a new deployment.
A restore doesn’t copy
spec.replication, so the new deployment starts as a primary and takes writes. - Point your clients at the new deployment.
Limits
spec.replicationcan’t be removed by an update: a deployment stops following by being fenced and promoted.- Sharded deployments can’t follow another.
- TLS between the two Kubernetes clusters isn’t supported yet.