Services and kube-proxy: ClusterIP to LoadBalancer, endpoints, and traffic policy

A Service is a virtual IP plus an endpoint list, implemented as rules on every node. No process listens on a ClusterIP, and endpoints come from readiness.

Read the briefing
About 10 min to read 8 drills

What to remember

  1. ClusterIP is a rule, not a listener. The packet is DNAT'd to a ready endpoint. 'Service down' is usually 'no ready pods'.
  2. Endpoints follow readiness. Check the EndpointSlice before blaming the network.
  3. L4 balancing picks once, at connect time. Long-lived gRPC or HTTP/2 connections never rebalance — that is why they need L7 or client-side balancing.
  4. externalTrafficPolicy: Local preserves client IP and can blackhole. Only nodes running a pod serve traffic; the health check must agree.
  5. Headless services return pod IPs directly. Which is what StatefulSets and client-side load balancing want.

The big picture

A Service gives a set of pods one stable virtual IP and name; kube-proxy on every node turns that virtual IP into NAT rules that pick a Ready pod per connection. Nearly every "the Service doesn't work" incident is one of four things: the selector matches nothing, no matched pod is Ready, targetPort points at a port nobody listens on, or something drops packets between client and pod. Interviewers use this node to see whether you can separate those layers with evidence instead of restarting components.

The mental model

Picture three layers stacked on the wire. DNS maps a name to a ClusterIP that no interface owns. kube-proxy, on the node the client is on, DNATs the first packet of each connection to one pod IP and targetPort chosen from the EndpointSlice, and conntrack remembers that choice for the rest of the flow. Readiness probes decide who is in the EndpointSlice. Debug from the bottom up: pod IP and port first, then ClusterIP, then the name, then the external path.

In depth

What a Service is, and what the types add

A Service is an API object with a selector, a list of ports, and a ClusterIP allocated from the service CIDR (--service-cluster-ip-range). Each port entry has a port (what clients connect to on the ClusterIP), a targetPort (the number or name of the container port on the pod; it defaults to port), and a protocol. The ClusterIP is virtual: no pod or node interface owns it (IPVS mode binds it to a dummy kube-ipvs0 device purely so the kernel accepts the packets). That is why ping <clusterip> gets nothing back in iptables mode: only the declared protocol/port pairs have rules.

The types are layers, not alternatives:

  • ClusterIP is reachable from inside the cluster and is the base of everything else.
  • NodePort additionally opens one port from --service-node-port-range (default 30000-32767) on every node; kube-proxy DNATs node traffic on that port to the same endpoints.
  • LoadBalancer additionally asks a controller (cloud-controller-manager in a cloud; MetalLB or kube-vip on bare metal) for an external address. Most implementations send LB traffic to the NodePorts; some target pod IPs directly, and allocateLoadBalancerNodePorts: false then skips the node ports. EXTERNAL-IP <pending> forever means no controller is acting on the Service.
  • ExternalName is a CNAME in cluster DNS: no proxying, no endpoints.

A headless Service (clusterIP: None) has no virtual IP at all: DNS returns the Ready pod IPs and kube-proxy is not involved. kubectl get svc -o wide shows the selector; kubectl describe svc shows the endpoints and, for LoadBalancer, the HealthCheck NodePort. Keep the layering in mind when someone says "use NodePort so pods can reach it": pods reach ClusterIPs already. NodePort exists for traffic arriving from outside the pod network.

Endpoints: how backends get chosen

Backends are not stored in the Service. The EndpointSlice controller (in kube-controller-manager) watches Services that have a selector and the pods in the same namespace, and writes EndpointSlice objects labelled kubernetes.io/service-name=<svc>, up to 100 endpoints per slice by default. Each endpoint carries the pod IP, the resolved target ports, and conditions: ready mirrors the pod's Ready condition, while serving and terminating describe pods that are shutting down but still answering. This is the mechanism that connects readiness probes to traffic: a failing readiness probe flips ready to false and kube-proxy stops sending new connections there within a few seconds on a healthy control plane.

Three configurations produce a Service with no endpoints, and they look identical from a client: the selector matches no pod labels (a selector is an AND of every key/value pair, so tier=frontend does not match tier=front-end), no matching pod is Ready, or the Service has no selector at all, in which case you are expected to write EndpointSlices yourself, the pattern for pointing a Service at an external database. A targetPort that names a container port that does not exist behaves like the last case: addresses appear but no port does, so nothing is routable.

publishNotReadyAddresses: true includes not-Ready pods; StatefulSets use it on their headless Service so peers can find each other before they pass readiness. The legacy Endpoints object is still maintained for compatibility but is truncated at 1,000 addresses, so read slices: kubectl get endpointslices -n shop -l kubernetes.io/service-name=web -o yaml. When a Service is misbehaving this object is the first evidence to collect. It tells you whether the control plane believes anyone is behind the door, and it separates "nobody is selected" from "somebody is selected but unreachable".

kube-proxy: the dataplane behind the virtual IP

kube-proxy runs on every node (usually a DaemonSet), watches Services and EndpointSlices, and programs the kernel so that packets to a ClusterIP or NodePort reach a pod. It never handles the packets itself.

In iptables mode it writes NAT rules. PREROUTING and OUTPUT jump to KUBE-SERVICES, which has one rule per Service port matching destination IP and port. That jumps to a per-Service KUBE-SVC-<hash> chain, which picks an endpoint with -m statistic --mode random --probability rules (1/n, then 1/(n-1), and so on), each jumping to a KUBE-SEP-<hash> chain that performs the DNAT to podIP:targetPort. Only the first packet of a connection walks these chains; conntrack records the translation and rewrites every later packet, and the replies, without consulting the rules again. Two consequences follow. A Service with no endpoints gets a REJECT rule, so a client sees an immediate connection refused rather than a hang; refused means kube-proxy is doing its job and nothing is behind the door. And balancing is per connection, not per request: a long-lived HTTP/2 or gRPC connection stays on one pod for its whole life.

The cost of iptables mode grows with Services x endpoints: every change regenerates the ruleset and applies it with iptables-restore, and each new connection walks KUBE-SERVICES linearly. At tens of thousands of endpoints, kubeproxy_sync_proxy_rules_duration_seconds climbs into seconds and new pods wait that long for traffic. IPVS mode keeps a kernel hash table of virtual servers (ClusterIP:port) and real servers (endpoints), updated incrementally and looked up in O(1), with schedulers such as rr, wrr, lc and sh; it still uses a small set of iptables and ipset rules for masquerading. There is also an nftables mode, and CNIs such as Cilium can replace kube-proxy with eBPF entirely, in which case there is no kube-proxy DaemonSet to restart. To see what a node is doing: iptables-save -t nat | grep <clusterip>, ipvsadm -Ln, conntrack -L -d <podip>.

Traffic policy, source IP, and affinity

externalTrafficPolicy decides what kube-proxy does with traffic that arrives from outside: NodePort and LoadBalancer traffic. With the default Cluster, a packet arriving at node A may be DNATed to a pod on node B. To make B's reply come back through A (otherwise the client would receive a packet from an address it never talked to and drop it), kube-proxy also SNATs the source to node A's address. Every pod is a candidate, so balancing is even, but the application sees a node IP instead of the client, and a connection may take an extra hop.

Local restricts kube-proxy to endpoints on the receiving node and skips the SNAT: the pod sees the real client IP and there is no second hop. The price is that a node with no local endpoint has nowhere to send the packet, so it is dropped. Kubernetes therefore allocates a healthCheckNodePort for such Services: an HTTP endpoint on every node that returns 200 only when the node has Ready local endpoints, which the load balancer is expected to probe so it stops sending to empty nodes. Balancing becomes per node rather than per pod (a node with three replicas and a node with one each receive half the traffic), and a rollout that removes a node's last replica briefly blackholes that node until the health check fails. internalTrafficPolicy: Local applies the same idea to ClusterIP traffic from inside the cluster; trafficDistribution: PreferClose is the softer, zone-aware variant.

sessionAffinity: ClientIP is the only affinity a Service offers. kube-proxy pins a client source IP to one endpoint for sessionAffinityConfig.clientIP.timeoutSeconds (default 10800 s, maximum 86400) using the iptables recent module or IPVS persistence. It is L4 and keyed on the address kube-proxy sees: if anything upstream rewrites the source (a proxying load balancer, a NAT gateway), every client shares one address and affinity collapses onto a single pod. Cookie-based stickiness belongs at the ingress layer.

Debugging a Service in order

Debug from the inside out, and let each result eliminate a layer.

  1. The spec. kubectl get svc web -n shop -o yaml: read selector, ports[].port, ports[].targetPort, type. Is targetPort a number the process listens on, or a name that exists in the container's ports?
  2. The pods. kubectl get pods -n shop -l app=web -o wide --show-labels: do the labels match every key in the selector, and is READY 1/1? A pod at 0/1 is Running but absent from the endpoints.
  3. The endpoints. kubectl get endpointslices -n shop -l kubernetes.io/service-name=web: are the pod IPs there, with ready: true and the port present? If not, the fault is above this line (labels, readiness, or targetPort) and no amount of node debugging will help.
  4. The pod itself. From a debug pod (kubectl debug -it <pod> --image=busybox or a netshoot pod): curl -sS -m 3 http://<pod-ip>:<targetPort>/healthz. If this fails, the application is broken, not the Service.
  5. The ClusterIP. curl http://<cluster-ip>:<port>/. Pod works but ClusterIP does not: check kube-proxy on the client's node (kubectl -n kube-system logs ds/kube-proxy, iptables-save | grep <cluster-ip>) and NetworkPolicy. Policies are evaluated against pod IPs after DNAT, so a rule that allows the ClusterIP allows nothing.
  6. The name. curl http://web.shop.svc.cluster.local/ last; resolution is a separate subsystem.

Read the failure shape as evidence. Refused instantly means a REJECT rule (no endpoints) or the pod's kernel (wrong targetPort). A hang means packets are being dropped: NetworkPolicy, an MTU black hole, kube-proxy not syncing, or a pod on a node that is gone. Works from some nodes only points at the CNI overlay. Some requests fail points at one endpoint that passes readiness but cannot serve, so curl each pod IP. EXTERNAL-IP pending means no LB controller owns the Service. Keep the sequence in this order and you will never again restart kube-proxy to fix a label typo.

Exposing Services on cloud and bare metal

On a cloud, type: LoadBalancer is handled by the cloud-controller-manager: it creates a provider load balancer, registers the nodes (or, in some modes, the pod IPs), configures health checks against the NodePort or healthCheckNodePort, and writes the address into status.loadBalancer.ingress. Provider behaviour such as internal vs external, idle timeouts, proxy protocol and cross-zone balancing is driven by annotations, so read your provider's list before assuming defaults. loadBalancerSourceRanges restricts client CIDRs where the provider supports it; loadBalancerClass lets several implementations coexist in one cluster.

On bare metal nothing implements LoadBalancer until you install something. MetalLB in Layer 2 mode has one node answer ARP for the address, so all traffic enters through that node and failover is a leader change that takes seconds; with externalTrafficPolicy: Local it announces only from nodes that have endpoints. In BGP mode every node with endpoints advertises the address to the upstream routers and receives ECMP traffic directly, which is what latency-sensitive fleets want because it removes both the single entry node and the SNAT hop. kube-vip offers a similar VIP with ARP or BGP. Whatever the implementation, the Service semantics (NodePorts, traffic policy, health-check port) are unchanged, which is why the debugging sequence above does not change either.

Myths and facts

Myth: A ClusterIP belongs to some pod or node, so you can ping it to check the Service.

Fact: It is a virtual address with NAT rules only for the declared protocol/port pairs; ping gets no answer in iptables mode, and that says nothing about the Service's health.

Myth: Connection refused from a ClusterIP means kube-proxy is broken.

Fact: Refused is kube-proxy working: the REJECT rule for a Service with no endpoints, or the pod's kernel refusing on a wrong targetPort. A broken dataplane produces hangs, not refusals.

Myth: externalTrafficPolicy: Local is simply better because it keeps the client IP.

Fact: It drops traffic on nodes without endpoints unless the load balancer honours healthCheckNodePort, balances per node instead of per pod, and briefly blackholes a node whose last replica leaves during a rollout.

Myth: A Service load-balances requests across pods.

Fact: It balances connections at L4 on the first packet; a long-lived HTTP/2 or gRPC connection stays on one pod. Request-level balancing needs an L7 proxy, a mesh, or client-side balancing.

Myth: Restarting kube-proxy fixes a Service with empty endpoints.

Fact: Endpoints are computed by the EndpointSlice controller in the control plane from labels and readiness; kube-proxy only consumes them. Fix the selector or the readiness probe.

Myth: A NetworkPolicy must allow traffic to the Service's ClusterIP.

Fact: Policies are evaluated against pod IPs after kube-proxy's DNAT; allow the backend pods with a podSelector. An ipBlock for the ClusterIP allows nothing.

How pros do it

  • Use named ports (targetPort: http) and put the readiness probe on the same port the Service targets, so a port change is a one-place edit and a mismatch fails visibly.
  • Debug from the inside out: pod IP and targetPort, then ClusterIP, then DNS name, then the external path; never touch node components before the EndpointSlice has been read.
  • Alert on Services that are expected to have backends but have zero ready endpoints; it is the earliest signal of a selector or readiness regression.
  • Treat a Service selector change as a migration: run the new Deployment alongside the old, then switch the selector. Deployment selectors are immutable and Helm applies Services before Deployments.
  • Use externalTrafficPolicy: Local only when the application needs the client IP or the hop latency matters, and only with a load balancer that probes healthCheckNodePort; otherwise keep Cluster.
  • Move to IPVS, nftables or an eBPF dataplane before Services x endpoints reaches the tens of thousands, and graph kubeproxy_sync_proxy_rules_duration_seconds so you see the cliff coming.
  • Do not rely on ClientIP session affinity behind anything that rewrites the source address; use cookie affinity at the ingress layer instead.

Questions people ask

Service is up, pods are Running, nothing can reach it. Where do you look?

Endpoints first. Read the EndpointSlice: empty means the selector does not match the pod labels or no pod is Ready; populated means compare targetPort with what the process listens on, then curl the pod IP directly before the ClusterIP. Say the order out loud and never start by restarting kube-proxy — it only programs rules from what the slice says.

I get connection refused from the Service instantly. Is kube-proxy down?

No — refused means something answered. Either kube-proxy's REJECT rule for a Service with no endpoints, or the pod's kernel resetting a SYN on a port nobody listens on (wrong targetPort). If kube-proxy had no rules the packet would go nowhere and you would see a hang, so refused-versus-hang is your first piece of evidence.

How do I preserve the client IP behind a LoadBalancer Service, and what does it cost?

externalTrafficPolicy: Local. Under the default Cluster policy a packet landing on node A may be DNATed to a pod on node B and SNATed to A so the reply returns symmetrically, which hides the client; Local forwards only to local pods with no SNAT. The cost: nodes without a pod drop traffic unless the balancer probes healthCheckNodePort, and balancing becomes per node rather than per pod.

Why does my gRPC service send everything to one pod?

Because kube-proxy balances connections, not requests. It picks a backend on the first packet and conntrack keeps the flow there, and gRPC multiplexes every call over one long-lived HTTP/2 connection. Fix it at L7: a headless Service with client-side balancing, an ingress or mesh that speaks HTTP/2 to the backends, or a max connection age on the server.

What happens to in-flight connections when a pod leaves the endpoints during a rollout?

Established TCP flows keep their conntrack entry and stay on the old pod until they close or the pod exits; only new connections move. That is why graceful termination and a preStop delay matter: the pod must keep serving for a few seconds after it leaves the slice. For UDP, kube-proxy flushes stale conntrack entries so clients are not stuck on a dead pod.

iptables or IPVS — does it matter, and how do I tell?

It matters at scale. iptables mode rewrites the whole NAT ruleset on every endpoint change and matches linearly, so sync time grows with Services × endpoints; IPVS (or nftables, or an eBPF CNI) keeps hash tables updated incrementally. Check the kube-proxy ConfigMap mode: or run ipvsadm -Ln on a node; if the CNI replaces kube-proxy there may be no DaemonSet at all.

Why is EXTERNAL-IP stuck at pending?

Nothing implements type LoadBalancer: no cloud-controller-manager for this provider, or no MetalLB or kube-vip on bare metal. The Service still works as a NodePort in the meantime; on a cloud, read the controller's events and IAM before assuming the API is slow.

Do I need a NodePort so another pod can reach my Service?

No. Every pod can reach every ClusterIP; NodePort only opens a port on each node for traffic arriving from outside the pod network. Inside the cluster it adds nothing but exposure.

Further reading

Drills · 8

Answer in your head, or out loud, before you reveal. Mark each one: "Again" brings it back, "Got it" counts on your desk.

1 Pick the strongest answer

"Service is up, pods are Running and Ready, nothing can reach it." Service api declares port: 80 and targetPort: 8080; kubectl get endpointslices -l kubernetes.io/service-name=api lists the pod IPs. From a debug pod, curl http://<pod-ip>:3000/healthz returns 200, but curl http://api:80/healthz is refused instantly. Where is the bug?

  1. targetPort does not match the port the process listens on: kube-proxy DNATs the connection to <pod-ip>:8080, nothing listens there, and the pod's kernel answers the SYN with a reset. The Service layer worked (DNS resolved, kube-proxy translated the address); the refusal comes from the pod's own TCP stack because the target port is closed.
  2. The pods are not Ready yet, so kube-proxy rejects connections until the readiness probe passes. The EndpointSlice lists the pod IPs, which means they are Ready; not-Ready pods would be absent from the slice and the refusal would then come from kube-proxy's no-endpoints rule instead.
  3. The Service needs type: NodePort before another pod can reach it. ClusterIP is reachable from every pod in the cluster; NodePort only adds a per-node port for traffic that arrives from outside the pod network.
  4. kube-proxy is not running on the node, so the ClusterIP has no rules and the kernel refuses the connection. Without rules the SYN would be routed to a virtual address nobody owns and hang until timeout; an instant refusal means a rule matched and something actively rejected it.
In short

targetPort points at a port nobody listens on, so the pod's own kernel refuses the connection; make targetPort match the listening port.

Why

A Service has three layers: the name resolves to a ClusterIP, kube-proxy DNATs the ClusterIP and port to a pod IP and targetPort, and a process on the pod must listen on that targetPort. Here the first two layers demonstrably worked, so the refusal is the pod's kernel resetting a SYN to a closed port. The interview signal is separating the layers with the evidence given (pod curl works, endpoints populated, refusal is instant) instead of restarting components.

The common mistake

Hearing 'connection refused' and reaching for kube-proxy or a restart. Refused means something answered — the pod's kernel or kube-proxy's REJECT rule; a broken dataplane makes connections hang, it does not fail fast.

Read the docs

2 Read the output

What does that curl print, and what does it tell you?

$ kubectl get svc web -n shop -o wide
NAME   TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)   AGE   SELECTOR
web    ClusterIP   10.96.41.17   <none>        80/TCP    3d    app=web,tier=frontend

$ kubectl get pods -n shop -l app=web --show-labels
NAME                   READY   STATUS    RESTARTS   AGE   LABELS
web-7d9c6b8f5d-2xk9p   1/1     Running   0          20m   app=web,pod-template-hash=7d9c6b8f5d,tier=front-end
web-7d9c6b8f5d-q7hml   1/1     Running   0          20m   app=web,pod-template-hash=7d9c6b8f5d,tier=front-end

$ kubectl get endpointslices -n shop -l kubernetes.io/service-name=web
NAME        ADDRESSTYPE   PORTS   ENDPOINTS   AGE
web-k8xq2   IPv4          80      <unset>     3d

# kube-proxy runs in iptables mode. From a pod in namespace shop:
$ curl -sS -m 5 http://web/
  1. Could not resolve host: web (exit code 6): a Service with no endpoints has no DNS record. CoreDNS answers with the ClusterIP regardless of endpoints; only headless Services resolve to pod IPs, and this one has a ClusterIP.
  2. An immediate Failed to connect to web port 80 ... Connection refused (exit code 7): the selector requires tier=frontend but the pods carry tier=front-end, so the EndpointSlice is empty and kube-proxy's rule for a Service with no endpoints rejects the connection. A Service whose slices hold no endpoints gets an explicit REJECT rule in the KUBE-SERVICES chain, so clients fail fast rather than hanging.
  3. The web page: the selector matches on app=web and additional labels are ignored. A selector is an AND of every key/value pair; each key must match exactly, and frontend is not front-end.
  4. Connection timed out after 5000 milliseconds (exit code 28): with no endpoints there is no DNAT target, so the SYN is silently dropped. kube-proxy programs a REJECT (ICMP port unreachable) for empty Services precisely so callers fail fast; a hang points at packet loss from policy, MTU or a dead node, not at empty endpoints.
In short

curl fails at once with Connection refused: the pod labels do not match the selector, the endpoints are empty, and kube-proxy rejects the connection.

Why

The evidence is all in the artifact: the selector has two keys, the pods satisfy one of them, and the EndpointSlice shows <unset> endpoints. In iptables mode kube-proxy installs a REJECT rule for a Service with no endpoints, so the client receives a TCP reset immediately (curl exit 7) instead of waiting for the 5 s timeout. DNS is unaffected because the record points at the ClusterIP, which exists regardless of backends. The signal interviewers want is reading the slice before theorising and knowing that "refused" is a fast-fail feature, not a broken dataplane.

The common mistake

Assuming an empty Service hangs, or that DNS breaks. The ClusterIP record exists regardless of backends, and kube-proxy installs an explicit REJECT for empty Services so callers fail fast; a hang points at packet loss, not at empty endpoints.

Read the docs

3 Answer out loud

Walk me through what happens to a TCP SYN from a pod to a ClusterIP with kube-proxy in iptables mode. Then, from the client side only, how do you tell 'no endpoints' from 'broken dataplane'? Two to five sentences, as if a staff engineer were timing you.

In short

A strong answer says kube-proxy DNATs the first packet to a pod IP and conntrack keeps the flow there; refused means no endpoints, a hang means dropped packets.

What a strong answer does
  • mechanism: KUBE-SERVICES to KUBE-SVC to KUBE-SEP with probabilistic selection, DNAT to podIP:targetPort, conntrack for the rest of the flow and the reply path, and the consequence that balancing is per connection.
  • diagnosis: Refused equals the REJECT rule for no endpoints or a reset from the pod on a wrong targetPort; a hang equals drops from NetworkPolicy, MTU, kube-proxy not syncing or a dead node; names the ordered checks: labels, readiness, slice, curl pod IP, then ClusterIP.
  • communication: Leads with the packet path in order, then the two failure shapes with what each proves, no filler.
Why

Interviewers listen for the DNAT-plus-conntrack picture (which also explains why gRPC sticks to one pod) and for using the failure shape as evidence: refused means an active rejection by kube-proxy or the pod, a hang means a drop somewhere in the path. Candidates who reach for "restart kube-proxy" reveal they treat the Service as a black box.

The common mistake

Describing kube-proxy as a userspace proxy that packets pass through, or answering 'I would restart kube-proxy'. kube-proxy only programs rules; the kernel forwards, and a wrong Service is fixed in the API, not on the node.

Read the docs

4 Find what's broken

All three pods are Running and 1/1 Ready, curl http://<pod-ip>:8080/ works, and curl http://api.shop/ from another pod is refused instantly. Which line, and what do you change?

apiVersion: v1
kind: Service
metadata:
  name: api
  namespace: shop
spec:
  type: ClusterIP
  selector:
    app: api
  ports:
    - name: http
      port: 80
      targetPort: http
      protocol: TCP
  sessionAffinity: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api
  namespace: shop
spec:
  replicas: 3
  selector:
    matchLabels:
      app: api
  template:
    metadata:
      labels:
        app: api
    spec:
      containers:
        - name: api
          image: registry.example.com/api:2.3.1
          ports:
            - name: web
              containerPort: 8080
          readinessProbe:
            httpGet:
              path: /healthz
              port: web
            periodSeconds: 5
In short

Line 13 is wrong: targetPort: http names a container port that does not exist; use targetPort: web or 8080.

What's broken
  • Line 13: targetPort: http refers to a container port name, but the container's port is named web. The EndpointSlice controller cannot resolve the name, so the slice carries the pod addresses without a port for http, and kube-proxy has no endpoints for the Service port.
Why

A named targetPort is resolved per pod against spec.containers[].ports[].name when the EndpointSlice controller builds the slice; a name that matches nothing produces endpoints with no port, which kube-proxy treats as no backends and rejects. type: ClusterIP (line 7) is the default and correct for in-cluster access, sessionAffinity: None (line 15) is the default, and the readiness probe on port: web (line 41) correctly names the container port, which is exactly why the pods are Ready. The interview signal is checking that the Service's targetPort resolves against the container's declared ports before suspecting the network.

Read the docs

5 Scenario: what do you do next?

It is 14:32. A Helm upgrade of the orders chart in namespace shop ran at 14:27 to "standardise labels" by adding tier: backend. Alert: the ingress 5xx ratio for orders.example.com is 100%. kubectl get pods -n shop -l app=orders shows 4/4 Running and 1/1 Ready. All nodes are Ready. The ingress controller log for a failing request says no endpoints available for service "shop/orders" and returns 503.

Step 1. The incident commander wants a status in two minutes. What is your first command?

  1. kubectl get endpointslices -n shop -l kubernetes.io/service-name=orders and kubectl get svc orders -n shop -o yaml, to confirm the Service has no backends and read its selector. The ingress controller is quoting API state (no endpoints). Confirming the slice and reading the selector against the pod labels turns a symptom into a mechanism in one round trip.
  2. Restart the ingress controller pods. The controller is reporting the truth from the API: the Service has no endpoints. Restarting it cannot create endpoints.
  3. kubectl rollout restart deployment/orders -n shop The pods are Running and Ready; restarting them changes nothing about why the Service does not select them and adds churn during an outage.
  4. kubectl top pods -n shop Utilisation is irrelevant to a 503 that the controller attributes to an empty endpoint set.

Step 2. The EndpointSlice has no endpoints. The Service selector is now {app: orders, tier: backend}. The pods carry app=orders,pod-template-hash=... and no tier label. helm history orders -n shop shows the upgrade FAILED: cannot patch "orders" with kind Deployment: spec.selector: field is immutable. Helm applied the Service change before the Deployment patch was rejected. What is your mitigation?

  1. Delete the Deployment and re-create it with the new selector so the upgrade can complete. That is the root-cause fix, not the mitigation: it takes every pod down until new ones are Ready, extending the outage, and can be done safely later with a second Deployment running alongside.
  2. kubectl label pod -n shop -l app=orders tier=backend on the running pods. It repopulates the slice, but the ReplicaSet template still lacks the label, so any rescheduled pod drops out again and live state now diverges from the chart. Rollback is just as fast and leaves the system consistent.
  3. Roll the release back now (helm rollback orders -n shop) or patch the Service selector back to {app: orders}; the four Ready pods re-enter the slice within seconds. Handle the label standardisation afterwards. Mitigate first: the existing pods are healthy, only the selector is wrong, and restoring it is a one-line change with an immediate effect. Root-causing the chart can wait until the 5xx ratio is zero.
  4. Restart kube-proxy on every node so it picks up the endpoints. kube-proxy programs whatever endpoints the API has, and there are none; the fault is in the selector, upstream of the dataplane.

Step 3. Rollback completes at 14:36; the slice lists four endpoints and the 5xx ratio is back to zero. For the postmortem, which action item do you propose?

  1. Replace Helm with plain kubectl apply so partial upgrades cannot happen. kubectl apply -f dir/ applies files in order too and would hit the same immutable-selector rejection after the Service had already changed; the tooling is not the mechanism.
  2. A CI check on the rendered chart that fails when a Service selector changes without matching pod template labels, a documented selector-migration procedure (new Deployment alongside, then switch), and an alert on Services with zero ready endpoints. Mechanisms at the source (CI), a safe path for the legitimate change (migration procedure), and earlier detection (alert). Each removes a way for this class of failure to recur.
  3. Ask the team to never change labels on running services. A reminder, not a mechanism; label changes are sometimes necessary and the goal is to make them safe.
In short

Check the EndpointSlice and selector first, roll the release back to restore the selector, then add a CI check and an alert.

Why

Three mechanisms explain the outage: a Service selector is an AND over labels, Deployment spec.selector is immutable so the pod labels never changed, and Helm applies Services before Deployments so a failed upgrade can leave a half-applied release. The interview signal is reading the EndpointSlice before acting, restoring service with the smallest reversible change, and proposing mechanisms (CI check, migration procedure, alert) rather than reminders in the postmortem.

Read the docs

6 Pick the strongest answer

You run a fleet of JSON-RPC nodes for a blockchain network as a Deployment on bare-metal Kubernetes, fronted by a type: LoadBalancer Service whose L4 balancer distributes across nodes and health-checks them. Two complaints: the per-client rate limiter inside the RPC pods sees every request arriving from one of a handful of node addresses, and p99 latency is measurably higher than when a benchmark client hits a pod IP directly. What single Service change addresses both, and what does it cost?

  1. Set hostNetwork: true on the RPC pods so they bypass kube-proxy. Traffic that arrives through the Service still traverses kube-proxy's rules and SNAT; hostNetwork merely removes network isolation and port flexibility from the pods.
  2. sessionAffinity: ClientIP, so each client sticks to one pod and its address is preserved. Affinity changes which backend is chosen; it does nothing about the SNAT that replaces the client address when the connection hops to another node under Cluster policy.
  3. externalTrafficPolicy: Local: kube-proxy then only DNATs to pods on the node that received the packet and skips the SNAT, so pods see the real client IP and the extra node hop disappears; the balancer must honour healthCheckNodePort so nodes without RPC pods are skipped, and balancing becomes per node rather than per pod. Both symptoms are the Cluster policy: SNAT hides the client and the cross-node hop adds latency. Local removes both at the price of per-node balancing and reliance on the health-check port.
  4. Change the Service to type: NodePort so clients connect straight to the nodes. NodePort traffic is subject to the same externalTrafficPolicy; with the default Cluster policy it is still SNATed whenever it is forwarded to a pod on another node.
In short

Set externalTrafficPolicy: Local; pods see the real client IP and lose the extra hop, but balancing becomes per node and the LB must probe healthCheckNodePort.

Why

Under the default Cluster policy a packet that lands on node A may be DNATed to a pod on node B, and kube-proxy SNATs it to node A so the reply returns symmetrically; the pod sees node A and the connection pays a second hop. Local confines forwarding to local endpoints with no SNAT, which restores the client IP and removes the hop, but a node without endpoints drops traffic unless the balancer probes healthCheckNodePort, and load is split per node, so co-locate replicas evenly with topology spread. The interview signal is naming the cost of the fix, not just the fix.

Read the docs

7 Quick recall

Behind a type: LoadBalancer Service your application logs show node IPs instead of client IPs. What is the one-field Service change that fixes it?

In short

Set externalTrafficPolicy: Local.

Accepted

Local · local · externalTrafficPolicy: Local

Why

Local restricts kube-proxy to endpoints on the receiving node and skips the SNAT that Cluster needs for cross-node hops, so the pod sees the original client address; the Service gets a healthCheckNodePort so the load balancer can avoid nodes without endpoints.

8 Pick the strongest answer

A cluster has about 9,000 Services and 70,000 endpoints with kube-proxy in iptables mode. During large rollouts, pods that are already Ready take 20-40 s to start receiving traffic, every node's kube-proxy burns a full core, and kubeproxy_sync_proxy_rules_duration_seconds p99 is 25 s. Nothing is wrong with the pods or CoreDNS. What is the mechanism, and which change addresses it?

  1. The Service CIDR is nearly exhausted, so ClusterIP allocation slows down the rollout. IP allocation is a control-plane operation independent of kube-proxy's rule sync, and the Services already have their ClusterIPs before the rollout starts.
  2. The node conntrack table is full, so new flows are dropped until old entries expire. A full conntrack table drops packets and logs nf_conntrack: table full; it does not make rule synchronisation take 25 s or scale with endpoint count.
  3. CoreDNS caches records for 30 s, so clients keep resolving to the old pods until the TTL expires. Clients resolve the ClusterIP, which does not change during a rollout; endpoint selection happens in kube-proxy's DNAT rules, not in DNS.
  4. Every endpoint change makes kube-proxy regenerate and iptables-restore a NAT ruleset whose size grows with Services x endpoints, and each new connection walks the KUBE-SERVICES chain linearly; moving to IPVS (or an nftables or eBPF dataplane) replaces the chains with kernel hash tables that are updated incrementally and looked up in O(1). Rule sync cost and lookup cost both scale with the ruleset in iptables mode; the fix is a dataplane whose update and lookup costs do not.
  5. The readiness probe periodSeconds is too long; shortening it makes pods receive traffic sooner. The pods are already Ready in the API; the delay is between the EndpointSlice update and the node's rules reflecting it, which is kube-proxy's sync latency.
In short

kube-proxy in iptables mode rewrites a huge rule set on every endpoint change; move to IPVS (or nftables or eBPF) with hash-table lookups.

Why

In iptables mode kube-proxy treats the NAT table as a document it rewrites: on each change it renders every KUBE-SVC and KUBE-SEP chain and applies them atomically with iptables-restore, so sync time is proportional to Services x endpoints, and the first packet of every connection is matched against the KUBE-SERVICES chain rule by rule. IPVS holds virtual and real servers in hash tables, adds or removes a single real server per change, and looks up in constant time; nftables and eBPF dataplanes make the same trade. The interview signal is connecting a measured symptom (sync duration) to the data structure behind it and naming the change with its migration cost.

Read the docs

Next lesson Storage: PV/PVC/StorageClass, CSI, access modes, expansion, reclaim policies
Drill · Services and kube-proxy
0:00

Loading…