skip to content

Services and Networking

How traffic reaches a pod: ClusterIP, NodePort and LoadBalancer Services, CoreDNS names, Ingress and Gateway API routing, NetworkPolicy, plus the kube-proxy and CNI datapaths. Interviewers start here because 'connection refused' is the standard exercise.

part ofKubernetesoverview, primer and where to startread it →
on this pageshow

questions

page 1 of 2

Kubernetes requires every pod to have its own IP address on a flat network. What exactly does that model require, and how do containers inside a single pod reach each other?

level: juniorimportance: must knowfreq 72%

answer

  1. IP per pod, no NAT, any node
  2. pause sandbox holds the netns
  3. containers share localhost + port space
  4. veth pair into node namespace
  5. pod IP is ephemeral — Services exist for that

basics

~20 s

Every pod gets its own IP. Any pod can reach any other pod's IP directly, on any node, with no NAT. Containers inside one pod share a single network namespace, so they talk over localhost and share one port space.

solid answer

~50 s

Kubernetes ships no pod networking itself; it defines a contract a plugin must satisfy. The contract: each pod gets a unique IP from a cluster-wide range; every pod can reach every other pod's IP on any node **without NAT**; a pod sees its own address as the same one others use to reach it; node agents can reach pods on their node. The pod, not the container, is the network unit. The runtime creates a sandbox (the `pause` container) that holds the network namespace, and every app container joins it. So containers in one pod share the IP, loopback and port space — they talk over `127.0.0.1`, and two of them cannot both bind `:8080`. Pod IPs are ephemeral: a rescheduled pod gets a new one, which is exactly why Services exist. `hostNetwork: true` opts a pod out — it uses the node's namespace and IP.

code

bash · 6 lines
bash
kubectl get pods -o wide
# NAME     READY  STATUS   IP           NODE
# api-0    1/1    Running  10.244.2.17  node-b

kubectl run probe --rm -it --image=nicolaka/netshoot --restart=Never -- \
  curl -s http://10.244.2.17:8080/healthz

go deeper

for a junior

State the four rules plainly and demonstrate the shared-namespace point: sidecars reach the app on localhost, and two containers cannot bind the same port.

for a middle

Add the mechanism — sandbox/pause container, veth pair, per-node IPAM slice of the cluster CIDR — and explain why no-NAT matters for peer-to-peer and identity.

for a senior

Tie the model to failure signatures you have debugged (same-node works, cross-node fails) and to what the model deliberately does not give you: isolation, encryption, IP stability.

for a principal

Frame it as an interface decision: Kubernetes chose a minimal contract so the datapath could be swapped, which is why plugin choice becomes an address-space, performance and upgrade decision rather than an application one.

## What the model requires Kubernetes implements no pod networking of its own. It specifies a contract and requires whichever plugin you install to satisfy it. Four clauses: 1. Every pod gets its own IP address from a cluster-wide address space. 2. Every pod can reach every other pod's IP directly, on any node, **without network address translation (NAT)** — no rewriting of source or destination addresses along the path. 3. Agents on a node (kubelet, node daemons) can reach all pods on that node. 4. A pod sees its own IP as the same address other pods use to reach it. This is often called the "IP-per-pod flat network" model. "Flat" means one address space with no translation boundaries inside it, not that everything is on one L2 segment. ## Why no-NAT matters Contrast the classic single-host container setup, where containers share the host IP and are exposed by port mapping with source NAT. That forces a distributed port-allocation problem, breaks any protocol that carries addresses in the payload, and makes a service register itself under an address it cannot see. Under the Kubernetes model a pod is addressable exactly like a small VM: it binds whatever port it likes, tells peers the IP it sees on its own interface, and that address works cluster-wide. Peer-to-peer systems (Cassandra, Kafka, etcd), gossip protocols and mTLS identity all depend on this. ## The pod as a network unit — the sandbox When the kubelet asks the container runtime to start a pod, the runtime first creates a **sandbox**: a container whose only job is to hold the pod's namespaces alive. Historically this is the `pause` container. The network plugin is invoked once, against the sandbox's network namespace. Every application container in the pod is then started joined to that same namespace. Consequences you must be able to state: - All containers in a pod share one IP and one loopback interface — a sidecar can reach the app on `localhost:8080`. - They share one port space; two containers binding the same port is a startup crash, not an isolation boundary. - They see the same routing table and the same `/etc/resolv.conf`. - Because the plugin runs once for the sandbox, adding a sidecar costs no extra IP. This is precisely what makes the sidecar pattern (proxies, log shippers, adapters) work without any networking configuration. ## How a packet actually leaves The plugin typically creates a **veth pair**: one end becomes `eth0` inside the pod namespace, the other lands in the node's root namespace, attached to a bridge or addressed directly by a host route. The node then forwards to the destination node — either by wrapping the packet (encapsulation) or by a plain route the underlay knows about. Address assignment (IPAM) is usually per node: each node holds a slice of the cluster CIDR and hands out IPs from it, which keeps routing summarisable. ## What the model does not promise - **Not isolation.** Flat means every pod can reach every pod by default. Restricting that requires policy objects and a plugin that enforces them. - **Not encryption.** Pod-to-pod traffic is plaintext unless the plugin or a mesh adds it. - **Not stability.** A pod IP dies with the pod. Never store it, never configure a client with it. Services and DNS exist to give a stable name. - **Service ClusterIPs are not pod IPs.** They are virtual addresses that never live on an interface; they are translated to a pod IP before delivery. - **`hostNetwork: true` is the escape hatch.** The pod runs in the node's network namespace, uses the node IP, and competes for the node's ports. It is used for node-level agents and breaks the model deliberately. ## Recognising it in practice `kubectl get pods -o wide` shows the pod IP and node. From a debug pod, `curl <podIP>:<port>` should work regardless of which nodes the two pods sit on. The classic failure signature is *same-node traffic works, cross-node traffic hangs* — that points at the node-to-node part of the datapath (encapsulation or routing), not at the application.

  • If pods get real routable IPs, why do Services exist at all?
    Because pod IPs are ephemeral and plural. A pod that is rescheduled, scaled or rolled gets a new IP, so no client can hold one. A Service gives a stable virtual IP and DNS name in front of the current set of ready pod IPs, and spreads traffic across them. The flat network is what makes the Service's translation to a pod IP work from any node.
  • What changes for a pod that sets hostNetwork: true?
    It skips the pod network entirely and runs in the node's network namespace, so it has the node's IP and sees the node's interfaces. Any port it binds is a port on the node, which means real conflicts with other host processes and other such pods. It is appropriate for node-level agents like CNI daemons or metrics collectors, and it also changes DNS behaviour unless dnsPolicy is set to ClusterFirstWithHostNet.

A pod is a small VM with one NIC. The containers inside are processes on that VM: same IP, same localhost, same port space — and if two processes want port 8080, one of them loses.

saying these in an interview costs you the question

  • Saying containers in a pod each get their own IP and talk to each other over the pod network
  • Believing pod IPs are stable enough to configure clients or store in a database
  • Claiming Kubernetes itself implements pod networking, with no mention of a plugin
  • Assuming the flat network means pods are isolated by default — it means the opposite
  • Confusing a Service ClusterIP with a pod IP, or thinking traffic to a pod IP is load balanced

context

open as a page

How does a workload running in a Kubernetes cluster resolve another Service by name? Describe what component answers the query and the DNS name forms available.

level: juniorimportance: must knowfreq 70%

basics

~20 s

CoreDNS runs in the cluster and its Service address is written into every pod's /etc/resolv.conf. A Service resolves as <service>.<namespace>.svc.cluster.local to its ClusterIP. Inside the same namespace the bare name works; across namespaces use <service>.<namespace>.

open as a page

What does a Kubernetes Ingress object actually do, and why does creating one have no effect until something else is installed in the cluster?

level: juniorimportance: must knowfreq 72%

basics

~20 s

An Ingress is just declarative configuration: hostname and path rules mapping to Services, plus TLS. Kubernetes ships no code that acts on it. An ingress controller must be installed; it watches Ingress objects and programs a real proxy or load balancer to match.

open as a page

A Kubernetes Service of type ClusterIP gets an IP address that no network interface owns and that nothing answers ARP for. Explain what actually happens to a packet sent to that IP, and which component makes it work.

level: juniorimportance: must knowfreq 78%

basics

~20 s

A ClusterIP is a virtual IP with no machine behind it. kube-proxy runs on every node and programs kernel rules that rewrite the destination of packets aimed at that IP to one of the Service's backing pod IPs (DNAT). A backend is chosen once per new connection; connection tracking rewrites the replies back.

open as a page

Why does a Kubernetes LoadBalancer Service show EXTERNAL-IP <pending> in kubectl get svc, and which component is supposed to replace it?

level: juniorimportance: must knowfreq 76%

basics

~20 s

A type=LoadBalancer Service only records a request. The cloud-controller-manager's service controller, or another load-balancer implementation such as MetalLB, must create the balancer and write its address into status. <pending> means nothing has done that yet.

open as a page

A team applies a Kubernetes NetworkPolicy object restricting traffic to their pods, but every connection they expected to block still succeeds. What are the two most likely explanations, and what does applying such a policy actually change?

level: juniorimportance: must knowfreq 68%

basics

~20 s

Either the cluster's CNI plugin does not enforce NetworkPolicy at all (the API object is accepted and silently ignored), or the policy's podSelector does not match the pods they think it does. A policy that does select a pod switches that pod from allow-all to deny-all for the directions the policy lists, permitting only what its rules allow.

open as a page

In a Kubernetes Service manifest, what is the difference between the port, targetPort and nodePort fields, and what does it mean when targetPort is a name instead of a number?

level: juniorimportance: must knowfreq 68%

basics

~20 s

port is the port the Service itself listens on (on its virtual IP). targetPort is the port on the backing pods that traffic is sent to. nodePort is the port opened on every node for NodePort/LoadBalancer Services. A named targetPort resolves to a containerPort with that name.

open as a page

A Kubernetes Service manifest can set spec.type to ClusterIP, NodePort, LoadBalancer or ExternalName. What does each type give you, and how do they relate to one another?

level: juniorimportance: must knowfreq 78%

basics

~20 s

ClusterIP gives a stable cluster-internal virtual IP (the default). NodePort adds a fixed port on every node. LoadBalancer adds an external cloud load balancer. ExternalName is only a DNS CNAME to an external host: no virtual IP, no proxying.

open as a page

A Kubernetes pod's /etc/resolv.conf contains a search list and the line 'options ndots:5'. Explain what each does, and why together they can make lookups of external names slow and generate large amounts of DNS traffic.

level: middleimportance: must knowfreq 44%

basics

~20 s

The search list is appended to short names so bare Service names resolve. ndots:5 means any name with fewer than five dots is tried against every search suffix first. An external name like api.example.com has two dots, so it produces several failed cluster lookups before the real one.

open as a page

The Kubernetes Gateway API defines GatewayClass, Gateway and HTTPRoute as separate resources. What does each represent, and which team normally owns each?

level: middleimportance: must knowfreq 52%

basics

~20 s

GatewayClass names an implementation, like StorageClass does for volumes. Gateway is a concrete listener with ports, hostnames and TLS, created by the cluster operator. HTTPRoute holds path and header matches plus backend Services, written by app teams and attached to a Gateway.

open as a page

What shortcomings of the Kubernetes Ingress resource is the Gateway API designed to fix?

level: middleimportance: must knowfreq 50%

basics

~20 s

Ingress can only express host and path rules, so everything else — rewrites, canary weights, header matching, timeouts — became vendor annotations that are untyped and unportable. It also has no role separation and only supports HTTP. Gateway API makes those first-class, typed, and role-split.

open as a page

Why does a gRPC client calling a Kubernetes ClusterIP Service pin its calls to one pod, and how does a headless Service fix that?

level: middleimportance: must knowfreq 71%

basics

~20 s

kube-proxy picks a backend once per connection, and gRPC sends every call over one long-lived HTTP/2 connection, so one pod gets all of them. A headless Service returns every ready pod's IP, letting the client balance calls itself.

open as a page

A Kubernetes Ingress rule requires a pathType. Explain the difference between Prefix, Exact and ImplementationSpecific, and how a request URL is matched against them.

level: middleimportance: must knowfreq 48%

basics

~20 s

Exact matches the whole URL path, case-sensitive, with no trailing-slash tolerance. Prefix matches on complete path segments split by /, so /foo matches /foo and /foo/bar but never /foobar. ImplementationSpecific hands matching to the controller, which may allow regexes. Exact wins over Prefix, longest prefix first.

open as a page

How do you terminate TLS for a hostname at a Kubernetes Ingress, and what exactly must the referenced Secret contain?

level: middleimportance: must knowfreq 52%

basics

~20 s

Add a spec.tls entry listing the hosts and a secretName. The Secret must be type kubernetes.io/tls in the same namespace as the Ingress, with keys tls.crt (leaf plus intermediate chain) and tls.key. The controller loads it and serves that certificate by SNI.

open as a page

Kubernetes' kube-proxy component can run in iptables mode or IPVS mode. Compare how each implements Service load balancing, and explain what actually changes as the number of Services and endpoints grows.

level: middleimportance: must knowfreq 62%

basics

~20 s

iptables mode builds a linear chain of NAT rules per Service and picks a backend with random-probability jumps; rule count grows with Services times endpoints, and every change means re-syncing a large ruleset. IPVS mode uses the kernel's L4 load balancer with hash-table lookups, so matching is near constant time, updates are incremental, and real schedulers (round-robin, least-connection, source-hash) are available.

open as a page

The Kubernetes NetworkPolicy API has no deny rule and no rule priorities. Given that, how do you make a namespace deny-by-default, and why can you not later add a policy that carves out an exception to an existing broad allow?

level: middleimportance: must knowfreq 64%

basics

~20 s

Apply a policy with an empty podSelector (selecting every pod in the namespace) and empty ingress and egress rule lists. Selecting a pod with no allowances denies everything for those directions. Exceptions are impossible because policies are purely additive - their allowances union, and nothing subtracts - so you must narrow the broad policy itself.

open as a page

In a Kubernetes NetworkPolicy, explain the difference between listing podSelector and namespaceSelector as two separate items in a from list versus combining them in a single item, and when you would reach for ipBlock instead.

level: middleimportance: must knowfreq 56%

basics

~20 s

Separate list items are OR'd - each is an independent peer. Selectors inside one item are AND'd, so podSelector plus namespaceSelector in the same item means pods with those labels only in namespaces with those labels. ipBlock matches CIDR ranges and is for non-pod peers such as external services; it cannot be combined with the label selectors in one item.

open as a page

A Kubernetes Service exists and its cluster DNS name resolves, but every connection to it fails and the Service has no backend addresses at all. How does a Service decide which pods back it, and how would you work out why the backend list is empty?

level: middleimportance: must knowfreq 62%

basics

~20 s

A controller watches pods matching the Service's label selector in the same namespace and publishes the ready ones as the Service's backend addresses. An empty list means no pod matches the selector, matching pods are not Ready, or the pods are in another namespace.

open as a page

With externalTrafficPolicy: Local on a Kubernetes LoadBalancer Service, how does the external load balancer learn which nodes can actually serve traffic?

level: middleimportance: must knowfreq 58%

basics

~20 s

Through spec.healthCheckNodePort. kube-proxy on every node answers HTTP there: 200 when the node has a ready local pod for the Service and kube-proxy is healthy, 503 otherwise. The load balancer health-checks that port and stops sending to 503 nodes.

open as a page

On a 16-node Kubernetes cluster, how do you decide how long a pod's preStop sleep must be so every endpoint consumer has stopped routing to it, and fit that inside terminationGracePeriodSeconds?

level: seniorimportance: must knowfreq 60%

basics

~20 s

Measure, under rollout load, how long each EndpointSlice consumer takes to stop routing to a deleted pod: kube-proxy on every node, the ingress controller, any cloud load balancer. Sleep longer than the slowest p99, then fit sleep plus drain inside terminationGracePeriodSeconds.

open as a page

During a rolling update of a Kubernetes Deployment, clients see a burst of connection-refused and reset errors even though the app implements graceful shutdown on SIGTERM. Walk through why this happens and how you would eliminate it.

level: seniorimportance: must knowfreq 58%

basics

~20 s

Pod deletion and endpoint removal are concurrent, not ordered. The kubelet can send SIGTERM and the app can stop listening before every node's kube-proxy has removed that pod from its rules, so in-flight traffic still arrives. Fix it by making the container keep serving briefly after deletion starts - a preStop sleep or a delayed shutdown - so proxies converge before the socket closes.

open as a page

After applying a Kubernetes NetworkPolicy that denies all egress by default in a namespace, pods start failing with name-resolution errors and long hangs even for destinations you explicitly allowed. Explain the cause and the correct remedy.

level: seniorimportance: must knowfreq 54%

basics

~20 s

Egress default-deny also blocks DNS. Pods cannot reach the cluster DNS service on UDP and TCP port 53, so every hostname lookup times out before the allowed connection is ever attempted. Add an egress rule permitting port 53 to the DNS pods in the kube-system namespace, matching both UDP and TCP.

open as a page

An IoT telemetry ingest gateway behind a Kubernetes LoadBalancer Service with externalTrafficPolicy: Local has some pods saturated while others idle. Why, and how would you fix it?

level: seniorimportance: must knowfreq 52%

basics

~20 s

The load balancer spreads load per node, and each node then splits its share only among its own local pods. With pods unevenly spread, pods on crowded nodes starve while lone pods overload. Spread the replicas one per node, or use a load balancer that weights nodes.

open as a page

Why does a Kubernetes EndpointSlice still list a deleted pod's IP, and is that pod still getting new Service traffic?

level: juniorimportance: should knowfreq 42%

basics

~20 s

A deleted pod stays in its Service's EndpointSlice until the pod object is gone, but it is marked terminating: true and ready: false. Consumers such as kube-proxy send new connections only to ready endpoints once they process that change.

open as a page

How do you limit a Kubernetes LoadBalancer Service to specific client IP ranges, and what must hold for that limit to work?

level: juniorimportance: should knowfreq 44%

basics

~20 s

List the allowed CIDRs in the Service's spec.loadBalancerSourceRanges. The load balancer's own firewall enforces them where the provider supports it, and kube-proxy adds a filter. Both only work if the real client address arrives, and neither protects the NodePort.

open as a page

Describe the Container Network Interface (CNI) contract used by Kubernetes: which component invokes the plugin, at what point in pod startup, what input it receives, and what it must return.

level: middleimportance: should knowfreq 48%

basics

~20 s

When the CRI runtime creates a pod sandbox it runs a CNI plugin binary from /opt/cni/bin, using the JSON config in /etc/cni/net.d. It passes the command (ADD/DEL/CHECK) and the sandbox network namespace via environment variables plus config on stdin, and expects a JSON result with the assigned interface, IPs and routes on stdout.

open as a page

What DNS records does a Kubernetes Service created with clusterIP: None produce, and how do StatefulSet pods obtain stable individual DNS names from it?

level: middleimportance: should knowfreq 45%

basics

~20 s

With clusterIP: None there is no virtual address: the Service name resolves to the addresses of all ready backing pods. Paired with a StatefulSet through its serviceName, each pod also gets its own stable name, <pod>.<service>.<namespace>.svc.cluster.local.

open as a page

What do the Kubernetes pod spec fields dnsPolicy and dnsConfig control, and what are the available dnsPolicy values?

level: middleimportance: should knowfreq 34%

basics

~20 s

dnsPolicy chooses which resolver configuration a pod gets: ClusterFirst (the default, cluster DNS), ClusterFirstWithHostNet (cluster DNS for pods sharing the node network namespace), Default (inherit the node's resolver settings), or None (supply everything yourself). dnsConfig adds or replaces nameservers, search domains and resolver options.

open as a page

Why can a terminating Kubernetes pod, already not ready in its Service's EndpointSlice, keep receiving requests over keep-alive connections, and how do you drain them?

level: middleimportance: should knowfreq 48%

basics

~20 s

EndpointSlice readiness only steers new connections; established keep-alive, HTTP/2 and gRPC connections keep reaching the same pod. The application must drain them after SIGTERM: stop accepting, signal close or GOAWAY, finish in-flight work, then exit.

open as a page

Using the Kubernetes Gateway API, how would you send 10% of production traffic to a canary version of a service while also allowing testers to reach that canary deterministically by sending a specific request header?

level: middleimportance: should knowfreq 38%

basics

~20 s

One HTTPRoute with two rules. The first rule matches the tester header and sends 100% to the canary Service. The second, catch-all rule lists both Services in backendRefs with weights 90 and 10. Header matches take precedence over the plain path rule.

open as a page

showing 1–30 of 51