Skip to content

Run two replicas ​

One operator pod is a single point of failure for reconciling. When it goes, nothing is reconciled until the next one is ready. With more than one replica, the pods elect one leader through a Kubernetes Lease. Only the leader writes. The others wait, and one of them takes over when the leader goes.

This does not give you more write capacity. It shortens the pause.

With replicas: 1, which is the default, there is one pod, the Recreate strategy and no election. This page is for replicas: 2 or more.

Install the operator first: Install the CRDs and the operator.

The values ​

yaml
replicas: 2
leaderElection:        # the defaults, in seconds; retry < renew < lease
  leaseSecs: 15
  renewSecs: 10
  retrySecs: 2

replicas is the only value you need. The leaderElection block shows the defaults, and you can leave it out. The key is replicas, not replicaCount.

With more than one replica, the chart changes five things:

ObjectWhat changes
Deployment aap-operatorRollingUpdate, maxSurge: 1, maxUnavailable: 0. At one replica it is Recreate
PodDisruptionBudget aap-operatormaxUnavailable: 1. At one replica there is none, because a budget of 1 of 1 would block every drain
The operator's fileleaderElection.enabled: true, with the Lease's name and namespace and the three timers
The Role in the primary namespaceget and update on the Lease named aap-operator, and create on leases. No delete, and no list
The pass timeout4 s, unless tuning.reconcileTimeoutSecs says otherwise. With toolProbe.to set, toolProbe.timeoutSecs must be at most the pass timeout minus 5, and the chart refuses it otherwise (with the election on, toolProbe.timeoutSecs (...) needs to be at most tuning.reconcileTimeoutSecs - 5 (...)). The chart's defaults cannot satisfy both rules: with the default 4 s pass timeout it is always refused, because 4 minus 5 is negative. A render that passes (run): leaseSecs: 30, tuning.reconcileTimeoutSecs: 10, toolProbe.timeoutSecs: 5

The Lease is named aap-operator and lives in the primary namespace: the first of watchNamespaces. Every pod campaigns for the same one.

What each replica does &ZeroWidthSpace;

The leaderA follower
Reconciles and writesYesNo. Its passes write nothing
Keeps its caches of the watched objectsYesYes
Answers /readyzYesYes. It is ready, so all replicas show ready while one writes
Serves the registry on 8080YesYes, from its own caches
Counts reconcile passes in /metricsYesNo. On the walk for the metrics page it showed only aap_runtime_signals_total (Scrape metrics)

The registry stays up through a failover because each replica builds it from its own caches.

How the election works &ZeroWidthSpace;

Every retrySecs, a follower and the leader alike read the Lease and act on it. The leader renews at that pace, so one failed renewal is retried. renewSecs is not a period: it is the deadline after which a leader that could not write demotes itself. The rules are in aap-leader-kubernetes:

  • No Lease: create it, naming yourself in holderIdentity. Another pod may win the create (a 409): you are a follower.
  • It is yours: renew it. A 409 means someone took it: you are a follower at once.
  • It has no holder (holderIdentity is empty, because the last leader stopped cleanly): take it at once. Nobody waits for the old renewTime to pass.
  • It is someone else's and expired, that is renewTime plus leaseSecs is past, by your own clock: take it over, and add one to leaseTransitions.
  • Anything else: you are a follower.

A leader that has not written for renewSecs demotes itself. That is before any other pod may take over, because retry < renew < lease. The margin is leaseSecs - renewSecs, 5 s by default, and a pass is capped below it. On a clean stop the leader clears holderIdentity.

If A's pod is gone, the Deployment makes a new one. It joins as a follower, and it may win the election instead of B: the two followers race, and either can win.

These two follow leader-e2e.sh and the crate's README. The state diagram is the one the install page used to carry, which now links here.

Look at it &ZeroWidthSpace;

sh
kubectl -n aap-system get pod
kubectl -n agents get lease aap-operator -o jsonpath='{.spec.holderIdentity} {.spec.leaseDurationSeconds} {.spec.leaseTransitions}{"\n"}'

The second line names the leader's pod, 15, and how many times the Lease changed hands. Replace agents with your primary namespace. A healthy first line shows both pods 1/1: a follower is ready too, so ready does not say which one writes.

How long a failover takes &ZeroWidthSpace;

There are two ways a leader goes, and they differ by about 15 seconds.

  • A crash or a lost node. The pod leaves no word. The Lease keeps its name until it expires, leaseSecs after the last renewal, so nothing writes for about that long. Agents keep running, because each is a Deployment of its own. Only reconciling pauses. This is for a pod that is gone. A container that the kubelet restarts inside the same pod finds the Lease under its own name and renews it, so there is no failover (a comment in leader-e2e.sh says so; it was not run here).
  • A clean stop (SIGTERM, a drain, a rolling update). The leader clears holderIdentity and the next pod takes it on its next try.
  • Then the agents catch up. A replica that is not the leader asks again every 30 s whether it has become one (FOLLOWER_RECHECK, in crates/controller/src/operator.rs). So an agent that was applied while nobody wrote, a parked one, is reconciled by the new leader up to 30 s after the takeover. That is consistent with the parked agent in the table below being Ready 21 s after the takeover and not at once. No run isolated the cause: the recheck gives an upper bound of 30 s, not the figure.

What was measured, as dated records:

RecordA holder killed with SIGKILLA parked agentA holder stopped with SIGTERM
CI, 2026-11-27, run 45932723504 at 2c16326, job leader-e2e 140288981731, kind v1.35.8the Lease moved 14 s after the kill, not before 10 s, leaseTransitions 0 to 1an agent applied meanwhile was Ready 21 s after the takeoverthe Lease passed to another pod 1 s after the SIGTERM, leaseTransitions 1 to 2
CI and a local run, 2026-11-19, as CLAUDE.md records them (K7b; CI runs 44458607529 and 44460925046)15 to 16 s21 s0 to 1 s
This page's walk, 2026-11-27, kind v1.35.8, the operator at sha-2c1632615 s after the dead holder's last renewal (04:11:58 to 04:12:13)its Deployment was there within 16 s of the takeoverholderIdentity was clear 0.1 s after kubectl delete pod returned, leaseTransitions unchanged

The CI script reads the clock in whole seconds, so each figure is good to about a second. In the 2026-11-27 CI log and on the walk, the new leader was the Deployment's replacement pod and not the surviving one. That is a race between two followers: CLAUDE.md records a run where the survivor won.

Why leaseTransitions differs in the SIGTERM column. CI read it after another pod had taken the released Lease (1 to 2). The walk read it 0.1 s after the release, before anyone had taken it, so it had not moved. Clearing holderIdentity does not add one. The next takeover does.

On the walk, in each of the 12 samples taken in the 13 s after the kill (about one a second), the new agent had no Deployment. The follower saw the event and wrote nothing, as it should.

How to make a real crash &ZeroWidthSpace;

kubectl delete pod is not a crash. The pod still gets its SIGTERM and releases the Lease. On the walk, kubectl delete pod --grace-period=0 --force also moved the Lease within 1 s. To kill the process without a word, as leader-e2e.sh does on kind, SIGKILL it from the node (crictl inspect for its pid, then kill -9), and then force-delete the pod so the kubelet does not restart the container in place.

A rolling update &ZeroWidthSpace;

One helm upgrade that changed logLevel on two replicas, read on the walk: it took about 6 s by the sampling loop. The new pod became ready before an old one stopped (that is maxSurge: 1), the pods were replaced one at a time, and the Lease changed hands once (leaseTransitions 3 to 4), without waiting for an expiry.

What this does not give you &ZeroWidthSpace;

  • One writer, not two. The Lease is the mechanism, and the crate's tests and the cluster suite hold it. A pass that began before the leader lost the Lease can still write until it ends. So the overlap is bounded by the pass timeout, which the chart keeps below leaseSecs - renewSecs. It is not zero.
  • Clocks. The times are written from the local clock and compared with it. Two replicas whose clocks differ by more than the margin can overlap. That is yours to avoid, as with every Kubernetes leader election.
  • Spread. The chart sets no anti-affinity of its own, so two replicas can land on one node and go together. The value affinity is passed to the pod if you want them apart.

What the chart refuses &ZeroWidthSpace;

Each row was run with helm template, with replicas: 2 and one change:

ChangeExitThe chart says
replicaCount: 21the operator's replica count is replicas, not replicaCount``
retrySecs: 10 (not below renewSecs)1leaderElection needs retrySecs < renewSecs < leaseSecs, each at least 1
renewSecs: 15 (not below leaseSecs)1the same sentence
tuning.reconcileTimeoutSecs: 61tuning.reconcileTimeoutSecs must be below leaseSecs - renewSecs while replicas > 1: the margin between the renew deadline and the earliest takeover, or a pass could write after losing the lease
replicas: 01replicas must be a whole number of at least 1, got 0

Every refusal prints templates/servicemonitor.yaml:1:4 as its location. Ignore it. The control is the values block above, which renders and passes kubeconform. With one replica, the leaderElection keys are not read: retrySecs: 99 at one replica renders, exit 0.

What proves it &ZeroWidthSpace;

CI jobWorkflowWhat it runs
leader-e2eoperator-image.ymlTwo replicas in kind. A killed holder is replaced only after the lease and never before 10 s. The survivor writes nothing meanwhile and serves the registry every second. A parked agent is reconciled by the new holder. A stopped holder releases the Lease. The leases rule is asked of the real API server (resourceNames narrows get and update, and no delete). No secret is in any log. push needs it
operator-e2eoperator.ymlThe election's own cases against a real API server: a 409 on a stale resourceVersion, a killed holder replaced
render-check.shthe chart jobThe rolling update, the budget, the election keys and the refusals, each broken on purpose

Verified 2026-11-27 with gh run view: on main at commit 2c16326, run 45932723504 of operator-image.yml, with leader-e2e among its jobs, ended in success. Its log, the figures in the table above, says the Lease moved 14 s after the kill and was released 1 s after the SIGTERM.

Run for this page, on 2026-11-27: the values block rendered with helm template, alone and with the install page's, and kubeconform, strict, found 8 and 11 objects valid. The walk above ran on a kind cluster, Kubernetes v1.35.8, named for it and deleted afterwards.

What is unverified &ZeroWidthSpace;

  • Two writers never overlap. leader-e2e holds the timing: no takeover inside the lease and a release at once. It does not hold that two pods never write together (leader-e2e.sh).
  • The PodDisruptionBudget under a real drain. The object is rendered and exists. No job drains a node with it.
  • A partition between the replicas and the API server. A killed pod is not one.
  • More than two replicas, and the operator's per-pass decision to write or not. The e2e infers it from the Lease and from a write that only a holder makes. It is not logged.