Nahum LitvinKubernetes, containers and sandboxes, from the production side
AWS5 min read

The Service nobody called: etcd writes with zero traffic

A Service nobody calls can still be one of the biggest writers in your etcd.

header

A ClusterIP Service that selects hundreds of pods costs etcd writes even if nobody ever calls it: every pod that starts or stops rewrites its Endpoints and EndpointSlices. On EKS, every NetworkPolicy that selects the same pods adds its own PolicyEndpoints objects, rewritten on the same churn, so 7 policies on one set of pods mean 7 copies of the pod list. Neither carries a request. If your etcd is filling up, rank writers by bytes, then check those two first.

AWS was right

An AWS support engineer told me our EKS etcd was getting close to its size limit, and that etcd was where to look. The standard EKS control plane allows 8 GB of etcd; the provisioned XL tier and up allow 16 GB. I didn't buy it. I blamed one API server instance and spent a day building the case. Then I checked the other instance, and the case fell apart. AWS was right: the answer was in etcd, not in either API server.

A bigger tier buys room. It doesn't tell you who is filling it.

Who writes the most

Counting writes per resource points at the wrong thing. Pod status updates and events win by count, and they're small. What fills etcd is bytes: a big object rewritten often.

sum by (resource) (rate(apiserver_request_total{verb=~"POST|PUT|PATCH|DELETE"}[5m]))

Multiply that by the average object size from apiserver_watch_events_sizes (its _sum over _count) for the same resource. It's an estimate of write bytes, not a measurement, but it changes the ranking. Two kinds of object came out near the top: PolicyEndpoints, and the Endpoints and EndpointSlices of one Service.

flowchart TB
  P[one pod starts or stops]
  subgraph svc [Service selecting every pod]
    direction LR
    E[Endpoints rewritten] --- S[EndpointSlices rewritten]
  end
  subgraph np [7 NetworkPolicies on the same pods]
    direction LR
    PE[PolicyEndpoints rewritten, per policy, per chunk]
  end
  P --> svc
  P --> np
  class E,S,PE bug

One pod change, many big objects rewritten. None of them carried a request.

The Service nobody called

A Service with a selector gets an Endpoints object and EndpointSlices that list its ready pods, up to 100 endpoints per slice by default. When a pod comes or goes, the control plane rewrites them. With hundreds of pods behind the selector and steady churn, that is a stream of large writes, all day.

Ours came along with a Helm chart. The callers find pods through their own discovery and dial pod IPs, so nothing used the ClusterIP. I wanted proof, not a code read:

conntrack -L -d <ClusterIP>

on every node. Zero entries everywhere. kube-dns, on the same nodes, showed plenty, so the check worked.

Then a reversible test before the delete: remove the Service's selector in one cluster and watch. Endpoint writes there went to zero.

My first try lasted about a minute, and it looked like I broke something. An error graph jumped right after the patch. I put the selector back, then read the raw logs: every error was from before the patch. The graph used rate[1m], and the window carried an earlier burst into the samples after my change. The second test ran for several minutes, errors stayed flat, and the Service went away.

The policies

On EKS, the VPC CNI network policy controller turns each NetworkPolicy into PolicyEndpoints objects that list the selected pods, split into chunks (the open-source controller's --endpoint-chunk-size defaults to 200). Every pod change rewrites the chunks of every policy that selects it. We had a default-deny and six allow policies on the same pods. Seven policies, seven copies of the same pod list.

One Egress policy with the union of the six allows lets through the same traffic. A pod selected by any Egress policy is isolated, and gets the union of the allows of every policy that selects it. Same rules, one copy of the list.

The rollout had its own trap. Our deploy tool applies a render in a fixed order: modify, delete, create. A one-step switch would delete the old policies before the new one existed. So it was two steps: add the merged policy next to the old seven, then remove the old seven, one cluster at a time.

Three numbers that lie

  • A flat line. If a write rate sits on the same exact number for days, that is a client rate limit, not demand. Updates are queueing behind it.
  • A full database. apiserver_storage_size_bytes is the file, free pages included, and it only shrinks on defrag. AWS checks the size limit against bytes in use, etcd_mvcc_db_total_size_in_use_in_bytes, which EKS publishes in CloudWatch. They can be far apart.
  • A before and after. If traffic moves between clusters during the day, one cluster's before/after mostly measures where the traffic went. Sum all of them.

I also assumed I could ask for a defrag. On EKS you can't trigger one yourself; AWS runs it as part of its own etcd maintenance.

What I kept

Before I add a Service now, I ask who will call its ClusterIP. Before I add a NetworkPolicy, I check whether an existing one on the same pods can take the rule. The fixes were a deleted Service and a YAML merge. Finding them took a day of being wrong in front of AWS support.

Nahum Litvin, Lead Platform Engineer.

Comments