123DevOps··9 min read

Kubernetes networking in practice: CNI, kube-proxy, CoreDNS, NetworkPolicy, and Gateway API

How pods get IPs and talk to each other, what the CNI, kube-proxy, and CoreDNS do, how to write default-deny NetworkPolicies tested with wget, and why to move from Ingress NGINX to Gateway API.

Kubernetes

Networking is the part of Kubernetes that generates the most “it works from my pod but not from theirs” tickets. The cause almost always sits in one of four layers: the CNI that gives pods their IPs, kube-proxy that implements Services, CoreDNS that resolves names, or a NetworkPolicy that blocks traffic. In this guide, we walk through each of them on a kind cluster running Kubernetes 1.37 (one control plane and two workers). Every command and output below was run in that lab; the namespaces carry the c- prefix only as a lab convention.

The Kubernetes network model

Kubernetes defines simple rules and leaves the implementation to plugins:

  • every pod gets its own IP, shared by all of its containers;
  • any pod can talk to any other pod, on any node, without NAT;
  • node agents (such as the kubelet) can reach every pod on that node.

The result is a “flat” network: from the application’s point of view, each pod looks like a machine on the same LAN. Each node gets a slice of the pod CIDR:

kubectl get nodes -o custom-columns=NAME:.metadata.name,PODCIDR:.spec.podCIDR
NAME                     PODCIDR
blog-lab-control-plane   10.244.0.0/24
blog-lab-worker          10.244.2.0/24
blog-lab-worker2         10.244.1.0/24

The CNI (Container Network Interface) plugin creates the interfaces, assigns the IPs, and sets up routes between nodes. Kubernetes only calls the plugin when a pod is created or destroyed.

CNI: what connects the pods

CNI Highlights NetworkPolicy
kindnet kind’s default, simple, built for labs The version in this lab enforces it (tested below)
Cilium (v1.20.5) eBPF, CNCF graduated project, can replace kube-proxy, implements Gateway API Yes, plus its own L7 policies
Calico (v3.33.1) Maintained by Tigera (not a CNCF project), BGP routing or overlay Yes, plus its own policies

One thing that trips up many people: the API accepts a NetworkPolicy object even when the CNI does not enforce it. Without a CNI that implements policies, you create the rule, get created, and nothing changes. In the cloud, check whether your provider’s default CNI enforces NetworkPolicy or whether you need to enable an add-on.

kube-proxy and Services

A Service gets a virtual IP (ClusterIP) that doesn’t belong to any interface. kube-proxy, which runs on every node, translates that IP into pod IPs. It has several modes:

Mode Status in 1.37
iptables Current default
nftables GA since 1.33, recommended on Linux; a future release is expected to make it the default
ipvs Deprecated in 1.35; expected to be off by default in 1.40 and removed in 1.43
kernelspace Windows

To see your cluster’s mode, read its configuration (read-only):

kubectl -n kube-system get cm kube-proxy -o yaml | grep -E "mode:|clusterCIDR"
    clusterCIDR: 10.244.0.0/16
    mode: iptables

In iptables mode, each endpoint becomes a DNAT rule. In kind, nodes are Docker containers, so you can look directly:

docker exec blog-lab-worker iptables-save | grep "c-net-shop/web" | grep DNAT
-A KUBE-SEP-THV3NV4KIV2MH5M2 -p tcp -m comment --comment "c-net-shop/web" -m tcp -j DNAT --to-destination 10.244.1.9:80
-A KUBE-SEP-WCA3ECRSDCNUSLF3 -p tcp -m comment --comment "c-net-shop/web" -m tcp -j DNAT --to-destination 10.244.2.7:80

If you’re starting a new cluster, evaluate nftables (check support in your distribution and provider) and avoid adopting ipvs now.

CoreDNS and name resolution

CoreDNS (v1.15.0, CNCF graduated) answers for cluster names. The old kube-dns was deprecated in 1.37. Every pod gets a resolv.conf pointing to the kube-dns Service (the historical name was kept):

kubectl -n c-net-shop exec frontend -- cat /etc/resolv.conf
search c-net-shop.svc.cluster.local svc.cluster.local cluster.local
nameserver 10.96.0.10
options ndots:5

A Service’s full name is <service>.<namespace>.svc.cluster.local. Because of the search list, web is enough within the same namespace; from another namespace, use web.c-net-shop. ndots:5 makes names with fewer than five dots go through the search list before being tried as-is, which shows up in busybox’s nslookup as NXDOMAIN answers that aren’t real errors:

kubectl -n c-net-shop exec frontend -- nslookup web
** server can't find web.svc.cluster.local: NXDOMAIN
** server can't find web.cluster.local: NXDOMAIN
Name:	web.c-net-shop.svc.cluster.local
Address: 10.96.61.25

For heavily queried external domains, using the name with a trailing dot (api.example.com.) avoids these extra lookups.

NetworkPolicy in practice

The scenario

The c-net-shop namespace has a web Deployment (nginx, two replicas, Service on port 80), a frontend pod, and an intruder pod. The c-net-partner namespace has another frontend and an other pod. With no policy at all, everyone reaches web, because Kubernetes allows everything by default.

Default deny

The policy below selects every pod in the namespace (podSelector: {}) and declares both directions without any allow rule:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
  namespace: c-net-shop
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress
== intruder -> web
wget: bad address 'web'
== frontend nslookup
;; connection timed out; no servers could be reached
== partner/frontend -> web
wget: download timed out

Notice the bad address: the first symptom of an egress default deny is DNS breaking, not the HTTP connection.

Allowing DNS egress

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-dns-egress
  namespace: c-net-shop
spec:
  podSelector: {}
  policyTypes:
  - Egress
  egress:
  - to:
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - protocol: UDP
      port: 53
    - protocol: TCP
      port: 53

The kubernetes.io/metadata.name label is set automatically on every namespace, so you don’t depend on hand-made labels.

Allowing a specific app and namespace

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: web-allow-frontend
  namespace: c-net-shop
spec:
  podSelector:
    matchLabels:
      app: web
  policyTypes:
  - Ingress
  ingress:
  - from:
    # frontend in the same namespace
    - podSelector:
        matchLabels:
          app: frontend
    # frontend in the c-net-partner namespace (namespace AND pod in the same item)
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: c-net-partner
      podSelector:
        matchLabels:
          app: frontend
    ports:
    - protocol: TCP
      port: 80
---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: frontend-egress-web
  namespace: c-net-shop
spec:
  podSelector:
    matchLabels:
      app: frontend
  policyTypes:
  - Egress
  egress:
  - to:
    - podSelector:
        matchLabels:
          app: web
    ports:
    - protocol: TCP
      port: 80

Watch the indentation of the second from item: namespaceSelector and podSelector in the same item mean “frontend pods in that namespace” (AND). If you put a dash before podSelector, it becomes “any pod in that namespace OR any frontend in the current namespace” (OR), a classic mistake that opens up more than intended. Also remember the connection must be allowed on both sides: the frontend egress in c-net-shop and the web ingress.

Testing with wget

kubectl -n c-net-shop exec frontend -- wget -qO- -T 3 http://web
kubectl -n c-net-shop exec intruder -- wget -qO- -T 3 http://web
kubectl -n c-net-partner exec frontend -- wget -qO- -T 3 http://web.c-net-shop
kubectl -n c-net-partner exec other -- wget -qO- -T 3 http://web.c-net-shop
== shop/frontend -> web
<title>Welcome to nginx!</title>
== shop/intruder -> web
wget: download timed out
== partner/frontend -> web
<title>Welcome to nginx!</title>
== partner/other -> web
wget: download timed out

Before the policies, all four tests returned the nginx page. Now only the two frontend pods get through, and intruder already resolves the name (DNS is allowed) but times out on port 80.

Exposing HTTP: from Ingress NGINX to Gateway API

The Kubernetes project retired Ingress NGINX (kubernetes/ingress-nginx). The retirement was announced in November 2025, maintenance ended in March 2026, and the repository is archived. Existing installs keep working, but they no longer get fixes or CVE patches. To find out whether you still run it:

kubectl get pods -A --selector app.kubernetes.io/name=ingress-nginx

The recommended path is Gateway API (v1.7.0 at the time of writing; check the current version). It separates roles: the GatewayClass comes from the implementation (Cilium, Envoy Gateway, Istio, NGINX Gateway Fabric, Traefik, among others), the Gateway is the entry point owned by the platform team, and the HTTPRoute belongs to the application team:

kubectl apply -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.7.0/standard-install.yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: public
  namespace: c-net-shop
spec:
  gatewayClassName: cilium        # name of the installed implementation's GatewayClass
  listeners:
  - name: http
    protocol: HTTP
    port: 80
    hostname: "shop.example.com"
    allowedRoutes:
      namespaces:
        from: Same
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web
  namespace: c-net-shop
spec:
  parentRefs:
  - name: public
  hostnames: ["shop.example.com"]
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: web
      port: 80

This snippet was not applied in the lab, which has no Gateway API implementation installed. With the default deny above, also remember to allow ingress from the gateway’s data plane pods. To convert existing Ingresses, the official tool is ingress2gateway (kubernetes-sigs/ingress2gateway), which reads your resources and generates equivalent Gateway and HTTPRoutes, for example with ingress2gateway print --providers=ingress-nginx. Check the flags in the current version’s README and review NGINX-specific annotations, which don’t always have a direct translation. If your edge is an API gateway, also see the Kong guide.

Network troubleshooting

Work from the bottom up: endpoints, DNS, policies, and finally the node.

Symptom Command What to look for
Service doesn’t respond kubectl get endpointslices -l kubernetes.io/service-name=<svc> Empty ENDPOINTS: wrong selector or pods not Ready
bad address nslookup and cat /etc/resolv.conf in the pod DNS egress blocked or CoreDNS down
Timeout between pods kubectl get networkpolicy -n <ns> and describe Missing policy on one side
Works via pod IP, not via the Service iptables-save or nft list ruleset on the node kube-proxy problem or wrong port on the Service

A Service with the wrong selector is the most common case, and the EndpointSlice gives it away immediately:

NAME               ADDRESSTYPE   PORTS     ENDPOINTS   AGE
web-wrong-m6m7j    IPv4          <unset>   <unset>     0s

kubectl describe networkpolicy shows the policy as the server understood it, which helps catch the AND/OR mistake. For conntrack, MTU, and intermittent latency issues, see deep infrastructure troubleshooting and the Kubernetes troubleshooting and debugging guide. To understand Services in detail, read the introduction to Services.

Checklist

  • The chosen CNI enforces NetworkPolicy (tested, not assumed)
  • kube-proxy mode is known; ipvs is out of new plans
  • Ingress and egress default deny per namespace, with DNS allowed
  • Policies reviewed for the AND/OR mistake between namespaceSelector and podSelector
  • Ingress NGINX inventoried and the Gateway API migration planned
  • Troubleshooting runbook that starts with EndpointSlices and DNS

In Kubernetes networking, almost nothing is magic: it’s one IP per pod, one DNAT rule per endpoint, and a policy you tested with wget before trusting it.

Get updates on new posts and stay in the loop!