1. What Kubernetes API server etcd latency looks like

Kubernetes API server etcd latency shows up as slow writes with deceptively healthy reads: kubectl get answers from the watch cache while creates, updates and deletes stall behind etcd. Controllers lag, leader elections flap, and the cluster drifts toward read-only behavior long before anything reports down.

Illustrative composite: a self-managed cluster starts answering kubectl get pods -A in eleven seconds. Someone restarts the API server pods; latency improves for ten minutes, then returns. Controller logs fill with client rate limiter deadline errors, node heartbeats arrive late, and two nodes flap NotReady. The API servers were never the fault. One etcd member sat on a disk whose fsync p99 had climbed past fifty milliseconds, so every Raft proposal waited on that member, writes queued in the API server, retries multiplied the load, and the restart only drained the queue briefly. Naming the slow layer before restarting anything is the discipline this guide teaches.

The symptom split matters. Mutating requests slow while reads stay fast points at etcd write latency, because reads can serve from the API server watch cache. All verbs slow including reads points at API server saturation, network trouble, or a watch cache that cannot keep up. Latency that plateaus exactly at a round number such as ten or thirty seconds points at a webhook timeout. HTTP 429 responses point at flow control rejecting work faster than the control plane can drain it. Each pattern names a different layer, and each layer has a different fix.

Scope before you dig. In a high-availability control plane, call /readyz?verbose on each API server directly, bypassing the load balancer. One degraded instance means a local problem: remove it from rotation and investigate that host. All instances degraded means a shared dependency, which almost always means etcd. The Kubernetes architecture guide maps how the API server, etcd, scheduler and controllers interact, which is the mental model every step below relies on.


2. How etcd latency becomes API server latency

Etcd latency becomes API server latency because every Kubernetes write is a Raft proposal that must fsync to the write-ahead log on a quorum of etcd members before etcd acknowledges it. Slow fsync on any quorum member slows every mutating API request, while cached reads hide the damage.

Follow one write. The API server authenticates and authorizes the request, runs admission, then sends a put to etcd. The etcd leader appends the entry to its WAL and fsyncs, replicates it to followers who fsync their WALs, and commits once a quorum has persisted it. The entry then applies to the bbolt backend, which commits with another fsync. A single kubectl apply therefore costs at least two disk flushes on a majority of control-plane nodes. When fsync p99 rises from three milliseconds to sixty, write throughput collapses roughly twenty-fold, and leases, heartbeats and endpoint updates queue behind the same proposals.

Reads behave differently, which is why the failure hides. The API server maintains a watch cache fed by a watch on etcd, and many list and get requests serve from that cache without touching etcd. A cluster can look responsive to kubectl get while every write crawls. The cache also explains the restart illusion: a restarted API server briefly serves from a fresh cache and an empty request queue, then degrades again as writes pile up behind the same slow etcd.

Slow disks also trigger leader elections. The default heartbeat interval is 100 milliseconds and the election timeout 1000 milliseconds. A leader that cannot flush its WAL stops sending timely heartbeats, followers start an election, in-flight writes fail with request timeouts, and the new leader inherits the same slow disk. Repeated elections in etcd logs beside high fsync latency confirm a storage problem rather than a network one.

One more mechanism completes the picture: apply latency inside etcd itself. After commit, each member applies entries to its state machine and backend. A member with a huge database or heavy compaction backlog applies slowly, so its raft index lags the leader even when its disk fsync looks acceptable. The API server reads through a linearizable read path that waits for the local member to catch up, which turns one lagging member into read latency as well. That is why per-member metrics, not cluster averages, decide the diagnosis.


3. First checks for etcd latency during an incident

Etcd latency triage starts with read-only checks that separate a hung API server from an overloaded one and a slow etcd from a saturated API server. Check liveness, readiness, inflight requests and etcd health in that order before changing anything.

Run the opening sequence:

bash
kubectl get --raw '/livez?verbose'
kubectl get --raw '/readyz?verbose'
kubectl get --raw '/metrics' | grep '^apiserver_current_inflight_requests'
kubectl get --raw '/metrics' | grep 'apiserver_request_total' | grep 'code="429"'

If /livez fails, the process is likely OOM-killed or deadlocked; check restart counts and kernel OOM logs on the host. If /livez passes but /readyz fails on the etcd sub-check, the API server is alive and its storage is not answering in time. High inflight mutating requests beside a failing etcd check confirm writes are queueing behind storage. Rising 429 counts mean flow control is shedding load, which protects the control plane but starves controllers.

Then ask etcd directly, from a control-plane node:

bash
ETCDCTL_API=3 etcdctl endpoint health --cluster   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key
ETCDCTL_API=3 etcdctl endpoint status --cluster -w table   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key

Endpoint health reports per-member commit latency in its success message; a member taking seconds to commit a proposal is your suspect. Endpoint status shows database size, leader identity and raft index per member. Record both outputs before intervening, because the comparison after your fix is how you prove the fix worked.


4. Measuring etcd latency with WAL fsync metrics

Etcd latency is measured at the disk with two histograms: etcddiskwalfsyncdurationseconds for write-ahead log flushes and etcddiskbackendcommitdurationseconds for bbolt commits. Sustained WAL fsync p99 above ten milliseconds on etcd storage predicts visible API server write latency.

Scrape the etcd metrics endpoint and compute quantiles in Prometheus:

bash
curl -s http://localhost:2379/metrics | grep '^etcd_disk_wal_fsync_duration_seconds'
curl -s http://localhost:2379/metrics | grep '^etcd_disk_backend_commit_duration_seconds'
promql
histogram_quantile(0.99, sum by (le, instance) (rate(etcd_disk_wal_fsync_duration_seconds_bucket[5m])))
histogram_quantile(0.99, sum by (le, instance) (rate(etcd_disk_backend_commit_duration_seconds_bucket[5m])))
histogram_quantile(0.99, sum by (le, verb, resource) (rate(apiserver_request_duration_seconds_bucket{verb!~"WATCH|CONNECT"}[5m])))

Read the three together. API server write p99 high with etcd fsync p99 high means storage. API server p99 high with fsync flat means the delay sits in admission, authorization or conversion webhooks. Backend commit latency high while WAL fsync stays low points at bbolt pressure from a large database or heavy compaction. Per-instance labels matter: one member with fsync ten times its peers is a single-host disk problem, and Raft makes the whole cluster pay for it.

Correlate with host evidence before concluding. Run iostat -x 1 5 on the etcd host and check await and utilization on the etcd volume, then check whether the disk is network-attached with burst credits that can exhaust. Cloud volumes with exhausted burst balance show exactly this pattern: fine for weeks, then fsync spikes under load. The PromQL guide for Kubernetes SREs covers the histogram patterns used here for throttling and pressure alerts.


5. Etcd database size, compaction and defragmentation

Etcd latency grows with database size because range requests walk more bbolt pages and compaction lags behind churn. A database near its quota raises a NOSPACE alarm and turns etcd read-only, so watch size against quota and compact on a schedule rather than during an incident.

Check size and alarms first:

bash
ETCDCTL_API=3 etcdctl endpoint status --cluster -w table   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key
ETCDCTL_API=3 etcdctl alarm list   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key

The default backend quota is 2 GiB, with 8 GiB the suggested ceiling for normal environments. Churn drives growth: clusters emitting tens of thousands of Events per hour, or storing multi-megabyte Helm release Secrets, accumulate revisions faster than compaction reclaims them. Compaction removes old revisions logically, but bbolt keeps the freed pages inside the database file until defragmentation returns space to the filesystem. Both the logical size and the file size therefore matter; endpoint status reports both.

Defragment one member at a time, starting with a follower, and never during peak load:

bash
ETCDCTL_API=3 etcdctl defrag --cluster   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key

Defragmentation rewrites the database file and briefly blocks that member, so watch fsync latency and leader stability as each member completes. If a NOSPACE alarm is active, compact and defragment first, then disarm the alarm; raising the quota without reclaiming space only postpones the same outage. Take a snapshot before maintenance using the workflow in the etcd backup and restore guide.

Prevent the growth instead of only cleaning it. Cap Event retention with the API server event TTL, keep Helm release Secrets out of etcd-heavy patterns where your tooling allows it, and audit the largest objects in the database with etcdctl range queries by prefix when size climbs unexpectedly. A single runaway controller writing status every second can add more revisions than the rest of the cluster combined, and compaction settings such as --auto-compaction-mode=periodic with a sane retention window keep that churn from becoming permanent bloat.


6. Quorum, leader elections and member health

Etcd latency spikes during leader elections because writes pause while members elect a leader and the new leader replays its log. Repeated elections mean a member cannot keep up, usually from disk latency, CPU starvation or network delay between members.

Read the evidence in etcd logs and member status:

bash
ETCDCTL_API=3 etcdctl member list -w table   --cacert=/etc/kubernetes/pki/etcd/ca.crt   --cert=/etc/kubernetes/pki/etcd/healthcheck-client.crt   --key=/etc/kubernetes/pki/etcd/healthcheck-client.key
kubectl logs -n kube-system etcd-<node> --tail=300 | grep -Ei 'election|leader|slow|timeout'

A healthy three-member cluster tolerates one member loss. Latency trouble starts earlier: a follower whose disk lags falls behind the leader's raft index, applies entries slowly, and forces the leader to wait or to send snapshots. The etcdserverslowapplyduration_seconds and proposal failure metrics expose this. If one member is chronically behind, treat its host as faulty: check disk await, CPU steal from noisy neighbors, and peer round-trip time before blaming etcd itself.

Do not tune election timeouts as a first response. Raising --election-timeout and --heartbeat-interval tolerates slower disks but delays real failure detection, and every member must use consistent values. Fix the disk or the network first; timeout tuning is the last lever for cross-datacenter members where round-trip time is genuinely high, and even there the honest answer is usually to keep etcd members in one low-latency failure domain.


7. API server latency from admission webhooks

API server latency from admission webhooks looks like etcd trouble but leaves etcd metrics flat: mutating requests for specific resources plateau at the webhook timeout while other writes stay fast. Per-webhook admission duration metrics name the culprit directly, so check them early.

Check webhook latency before touching etcd:

bash
kubectl get --raw '/metrics' | grep '^apiserver_admission_webhook_admission_duration_seconds'
kubectl get mutatingwebhookconfigurations,validatingwebhookconfigurations
promql
histogram_quantile(0.99, sum by (le, name, type) (rate(apiserver_admission_webhook_admission_duration_seconds_bucket[5m])))

A webhook whose p99 sits at its configured timeout is either down, overloaded, or waiting on a dependency. With failurePolicy: Fail, every matching write waits for the full timeout and then fails, which reads as cluster-wide slowness for that resource type. Check the webhook's own pods, endpoints and logs; a webhook Service with no ready endpoints produces exactly this plateau.

Fix at the webhook layer. Scale or repair the webhook deployment, shorten timeouts to values the webhook can actually meet, and scope webhook rules to the resources that need them instead of matching everything. Review failurePolicy choices deliberately: Fail protects policy enforcement but couples API availability to webhook health, while Ignore trades enforcement for availability. Record the decision per webhook; discovering it during an incident is too late.

A scoped webhook configuration keeps the blast radius small:

yaml
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
metadata:
  name: policy-checks
webhooks:
  - name: validate.example.com
    admissionReviewVersions:
      - v1
    sideEffects: None
    failurePolicy: Fail
    timeoutSeconds: 3
    rules:
      - apiGroups:
          - apps
        apiVersions:
          - v1
        operations:
          - CREATE
          - UPDATE
        resources:
          - deployments
    clientConfig:
      service:
        name: policy-webhook
        namespace: platform
        path: /validate

Three seconds is already generous for a policy check that should answer from memory. A webhook needing ten seconds is telling you it does synchronous work that belongs in a controller, not in the admission path of every write.


8. Watch load and list pressure on the API server

API server latency also rises from watch and list pressure: clients that list large collections repeatedly, watches that restart constantly, and controllers with broken informers force the API server to serialize huge responses and churn its watch cache. The fix is client behavior, not etcd tuning.

Identify the pressure from request metrics:

bash
kubectl get --raw '/metrics' | grep '^apiserver_request_total' | head -50
kubectl get --raw '/metrics' | grep '^apiserver_longrunning_requests'
promql
sum by (verb, resource, user_agent) (rate(apiserver_request_total[5m]))
histogram_quantile(0.99, sum by (le, verb, resource) (rate(apiserver_request_duration_seconds_bucket{verb="LIST"}[5m])))

High LIST rates from one user agent usually mean a controller polling instead of watching, a script running kubectl get in a loop, or an informer resyncing because its watch keeps failing. Large objects amplify the cost: listing thousands of Secrets or Events serializes megabytes per call. Events deserve special suspicion because high-churn clusters generate them constantly and many tools list them cluster-wide.

Reduce the load at the source. Fix controllers to use informers with proper resync periods, add field and label selectors to lists, paginate large lists with limit and continue, and prefer watches over polling in automation. On the server side, the watch cache already shields etcd from most reads; when LIST latency rises with flat etcd metrics, the cost is serialization and cache churn inside the API server, which more API server replicas and memory address better than any etcd change. The Kubernetes observability stack guide covers wiring these metrics into dashboards and alerts.


9. Inflight saturation, 429s and retry storms

Etcd latency and API server saturation feed each other: slow writes hold inflight slots, queues fill, the API server returns 429s, and clients retry into the same bottleneck. Breaking the loop means shedding non-critical load and fixing the slow layer, not raising limits blindly.

Watch the saturation signals together:

bash
kubectl get --raw '/metrics' | grep '^apiserver_current_inflight_requests'
kubectl get --raw '/metrics' | grep 'apiserver_flowcontrol_current_inqueue_requests'
kubectl get --raw '/metrics' | grep 'apiserver_flowcontrol_rejected_requests_total'

API Priority and Fairness classifies requests into priority levels so leader election, node heartbeats and system controllers keep capacity while bulk traffic queues or rejects. When rejections concentrate in low priority levels, flow control is doing its job and the real fault is downstream slowness or a misbehaving client. When system-level requests also reject, the control plane is genuinely undersized or etcd is too slow for the offered write rate.

Client behavior decides whether saturation recovers. Well-behaved clients back off on 429 with jitter; scripts and operators that retry immediately convert a slowdown into a storm. Audit the top requesters by user agent during the incident, throttle or pause non-critical automation, and let queues drain. Raising --max-requests-inflight without fixing etcd only moves the queue into etcd and deepens the latency it was protecting against.

Watch for the controller-specific version of this loop. A controller whose reconcile writes fail with timeouts requeues with backoff, but a fleet of controllers failing together requeues in near-unison and produces a synchronized retry wave every backoff interval. Leader-election leases make it worse: slow lease renewals trigger elections, the new leader replays its full reconcile queue, and write load spikes again. Staggering resync periods and honoring server-provided retry hints break the synchronization that keeps the loop alive.


10. Managed Kubernetes: etcd latency without etcd access

Etcd latency on managed Kubernetes such as EKS, GKE and AKS is invisible at the etcd layer because the provider operates the control plane. Diagnose from the API server side with request duration, 429 rates and webhook metrics, then escalate with that evidence when the slow layer is provider-owned.

You still own several layers. Admission webhooks, operators with polling loops, oversized objects, and clients ignoring 429 backoff all live in your account. Work the same sequence: split reads from writes, check webhook duration, find top requesters, and confirm whether latency correlates with your deployments or with nothing you changed. Managed control planes also scale API server capacity with cluster size, so a cluster that outgrew its control-plane tier shows saturation that only a provider-side change fixes.

Escalate with data, not adjectives. Capture timestamps, apiserverrequestduration_seconds quantiles by verb, 429 rates, affected resources, and whether reads stayed fast while writes stalled. That packet separates a provider etcd problem from a customer webhook problem in one exchange. The production monitoring and alerting guide covers building the alerts that catch this pattern before users report it.


11. Fixing etcd latency at the storage layer

Etcd latency fixes belong at the storage layer first: move etcd to fast local NVMe or provisioned-IOPS volumes, isolate it from noisy neighbors, and keep database size controlled with compaction and defragmentation. Configuration tuning cannot compensate for a disk that cannot fsync in single-digit milliseconds.

Apply the fixes in order of evidence. One slow member: replace or repair that host's disk and let the member rejoin, watching raft index catch-up. All members slow on network storage: migrate etcd data directories to local NVMe or high-IOPS volumes with consistent performance, not burstable classes. Database oversized: compact, defragment member by member, and reduce churn from Events and oversized Secrets. CPU-starved members: reserve CPU for etcd and move co-located workloads off control-plane nodes.

Validate each fix with the same metrics that found the problem: WAL fsync p99 back in low single-digit milliseconds, backend commit latency stable, API server write p99 recovered, inflight queues draining, and no leader elections outside maintenance. Keep a pre-change snapshot and the endpoint status output so the before-and-after comparison is documented rather than remembered. Storage changes on control-plane nodes follow the node maintenance patterns in the kubeadm cluster administration guide.

After the fix, load-test the write path deliberately. Apply a burst of ConfigMap updates in a scratch namespace and watch fsync and write p99 hold steady, then repeat during a node drain so heartbeat and endpoint churn add realistic pressure. A control plane that only performs when idle has not been fixed; it has been rested. Record the burst results as the new baseline so the next latency incident starts from evidence instead of memory.


12. Etcd latency troubleshooting matrix and checklist

Etcd latency troubleshooting follows the request path: API server duration by verb, etcd fsync and commit histograms, member health, then webhooks and client load. The layer whose metrics move first owns the incident, and restarting API servers only hides queue buildup for a few minutes.

Symptom Likely layer First check
Writes slow, reads fast etcd write path etcddiskwalfsyncduration_seconds p99
All verbs slow API server saturation or network apiservercurrentinflight_requests, per-instance readyz
Latency plateaus at timeout value Admission webhook apiserveradmissionwebhookadmissionduration_seconds
429 responses rising Flow control shedding load apiserverflowcontrolrejectedrequeststotal by priority level
Leader elections repeating Slow member disk or peer network etcd logs, etcdctl endpoint health
Writes rejected, NOSPACE alarm Database quota reached etcdctl alarm list, endpoint status size
LIST latency high, etcd flat Client list pressure apiserverrequesttotal by verb and user agent
One API server degraded Local host problem Direct /readyz?verbose per instance

Final checklist:

  • API server write p99 and etcd fsync p99 alerted with per-instance labels.
  • etcd runs on fast, non-burstable storage isolated from noisy neighbors.
  • Database size tracked against quota with scheduled compaction and defragmentation.
  • Webhook timeouts and failure policies reviewed, with per-webhook latency dashboards.
  • Top API requesters audited for polling loops and 429 backoff behavior.
  • Flow control rejections monitored by priority level, with system levels protected.
  • Incident runbook starts with readyz per instance and etcd endpoint health, not restarts.
  • Managed clusters escalate with verb-level latency and 429 evidence packets.

Frequently Asked Questions

Why is kubectl get fast while kubectl apply hangs?

Reads often serve from the API server watch cache, while writes must commit through etcd Raft proposals with WAL fsync on a quorum. Slow etcd storage therefore stalls creates and updates while gets look healthy. Compare API server write p99 against etcddiskwalfsyncduration_seconds to confirm.

What etcd WAL fsync latency is too high?

Sustained WAL fsync p99 above roughly ten milliseconds predicts visible API server write latency, and values in the tens of milliseconds collapse write throughput. Healthy etcd storage on local NVMe or provisioned-IOPS volumes keeps fsync p99 in low single-digit milliseconds under normal load.

How do I check etcd health from a control-plane node?

Run etcdctl endpoint health --cluster and etcdctl endpoint status --cluster -w table with the etcd CA and healthcheck client certificates. Health output shows per-member commit latency, and status shows database size, leader identity and raft index for each member.

Can an admission webhook cause API server latency that looks like etcd trouble?

Yes. A slow or down webhook with failurePolicy: Fail makes matching writes wait for the full timeout, which plateaus latency at a round number while etcd metrics stay flat. Check apiserveradmissionwebhookadmissionduration_seconds per webhook before changing etcd.

What does a NOSPACE alarm mean for etcd latency?

A NOSPACE alarm means the etcd database reached its backend quota, so etcd turns read-only and writes fail. Compact old revisions, defragment members one at a time to return space, then disarm the alarm. Raising the quota without reclaiming space only postpones the outage.

Why do API server restarts only fix etcd latency briefly?

A restarted API server starts with an empty request queue and a fresh watch cache, so latency looks better until writes queue behind the same slow etcd again. Restarting treats the queue, not the storage. Fix fsync latency, database size or member health at the etcd layer.

How do I diagnose etcd latency on EKS, GKE or AKS?

Managed providers hide etcd, so diagnose from the API server side: split read and write latency, check webhook duration, 429 rates and top requesters. If writes stall while your webhooks and clients are clean, escalate to the provider with verb-level latency evidence and timestamps.

⚡ KUBERNETES SCENARIO INTERVIEW PREP

Preparing for Senior Platform & SRE Interviews

Practice real-world cluster triage, RBAC debugging, and pod scheduling scenarios in our Kubernetes scenario interview questions hub.

Explore Interview Scenarios →