# Kubernetes Networking: Service, DNS, NetworkPolicy and Gateway API

> How ClusterIP/NodePort and CoreDNS actually behave, restricting traffic with NetworkPolicy, and moving from Ingress to the Gateway API added in the 2025 exam revision

- URL: https://lcxlab.com/en/post/cka-networking
- Author: Miles Hsu
- Published: 2026-11-03
- Category: DevOps
- Series: Certified Kubernetes Administrator (CKA) #6
- Tags: CKA, Kubernetes
- License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/deed.en)

---

Services & Networking is 20% of the CKA, and the tasks fall roughly into four groups: exposing a Deployment with a Service, troubleshooting DNS, writing NetworkPolicies, and the Gateway API added in the 2025 revision. As before, this post works hands-on with the three-node cluster built in [Building a kubeadm Cluster (Part 2)](https://lcxlab.com/en/post/cka-kubeadm-cluster) (`k8s-cp1`, `k8s-w1`, `k8s-w2`, with Calico as the CNI).

Two posts worth reading first:

[Linux Networking Basics: Routing, DNS and Network Namespaces](https://lcxlab.com/en/post/linux-networking-basics)

[Kubernetes Networking: How Do Pods Talk to Each Other?](https://lcxlab.com/en/post/cni-plugins-for-kubernetes)

---

## The three address ranges in a cluster

First, let's sort out the three kinds of IPs in a kubeadm cluster; every task later relies on them:

| Range | Value in this cluster | Decided by | Assigned by |
|--|--|--|--|
| Node range | `192.168.122.0/24` | The libvirt `default` network | libvirt's DHCP |
| Pod range | `10.244.0.0/16` | `kubeadm init --pod-network-cidr` and Calico's `custom-resources.yaml` | The CNI (Calico IPAM) |
| Service range | `10.96.0.0/12` | kubeadm's default (`--service-cidr`) | kube-apiserver |

In the exam you often need to look these up first, for example "create a NetworkPolicy allowing traffic from the Pod range", or when troubleshooting "the Pod range overlaps the Node range". On `k8s-cp1`:

```bash
# Service range: in the kube-apiserver static Pod
sudo grep service-cluster-ip-range /etc/kubernetes/manifests/kube-apiserver.yaml

# Pod range: in the kube-controller-manager static Pod
sudo grep cluster-cidr /etc/kubernetes/manifests/kube-controller-manager.yaml

# The IP pool Calico actually uses
kubectl get ippools -o wide

# The Pod CIDR given to each node (Calico doesn't necessarily follow it, but controller-manager still writes it)
kubectl get nodes -o custom-columns=NAME:.metadata.name,PODCIDR:.spec.podCIDR,IP:.status.addresses[0].address
```

![172410](https://lcxlab.com/images/posts/cka-networking/172410.webp)

Newer Kubernetes versions can also show the Service range through the API:

```bash
kubectl get servicecidrs
```

### Ports used on the nodes

Another common task type is "some component can't be reached", which means knowing which port each component listens on. Compare with `ss` on cp1:

```bash
sudo ss -tlnp | grep -E 'kube|etcd'
```

| Node | Port | Component |
|--|--|--|
| Control plane | `6443` | kube-apiserver |
| Control plane | `2379-2380` | etcd (client / peer) |
| Control plane | `10257` | kube-controller-manager |
| Control plane | `10259` | kube-scheduler |
| All nodes | `10250` | kubelet API |
| All nodes | `10256` | kube-proxy health check |
| Workers | `30000-32767` | NodePort Services |

---

## Service

A Pod's IP changes when it is recreated, and a Deployment has several Pods, so we need a stable entry point that also load balances. That's a Service.

First, a Deployment to practice with:

```bash
kubectl create deployment web --image=nginx --replicas=3
kubectl get pods -l app=web -o wide     # three Pods spread across nodes, each with a 10.244.x.x IP
```

### ClusterIP: a stable entry point inside the cluster

```bash
kubectl expose deployment web --port=80 --target-port=80
kubectl get svc web
# NAME   TYPE        CLUSTER-IP     EXTERNAL-IP   PORT(S)
# web    ClusterIP   10.96.x.x      <none>        80/TCP
```

| Field | Meaning |
|--|--|
| `port` | The port the Service itself listens on; clients connect to `CLUSTER-IP:port` |
| `targetPort` | Which Pod port traffic goes to; must match what the container actually listens on |
| `selector` | Picks backend Pods by label; `expose` reuses the Deployment's `app=web` |

Test from another Pod in the cluster:

```bash
kubectl run tmp --rm -it --image=busybox:1.36 --restart=Never -- wget -qO- -T 2 http://web
```
>Check: you see the HTML of nginx's welcome page.

![172821](https://lcxlab.com/images/posts/cka-networking/172821.webp)

---

### From Service to Pod: EndpointSlice

The Service itself doesn't know where the Pods are. A controller keeps writing the IPs of Pods matching the `selector` into **EndpointSlices**:

```bash
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl describe svc web | grep -i endpoints

# Scale down to 1 and look again: the endpoints shrink too
kubectl scale deployment web --replicas=1
kubectl get endpointslices -l kubernetes.io/service-name=web
kubectl scale deployment web --replicas=3
```

>[!TIP] 📌 First troubleshooting step
>When a Service can't be reached, check whether its endpoints are empty first. Empty usually means the `selector` doesn't match the Pods' labels, or the Pods haven't passed their readinessProbe.

---

### kube-proxy: a ClusterIP is really iptables rules

A ClusterIP isn't on any network interface, so `ping` usually gets no reply, yet `wget` connects. The reason is that kube-proxy on every node uses iptables DNAT to send "packets for ClusterIP:port" to one of the Pod IPs, the same thing as the DNAT rule written by hand in [Linux Networking Basics](https://lcxlab.com/en/post/linux-networking-basics#5-letting-outside-traffic-in-dnat-port-forwarding). kube-proxy hooks `KUBE-SERVICES` into both the `PREROUTING` and `OUTPUT` chains, so packets arriving from outside and packets sent by the node itself are both redirected to Pods.

First check kube-proxy's mode:

```bash
kubectl -n kube-system get cm kube-proxy -o yaml | grep 'mode:'
# mode: iptables
```

Look at the rules on any node:

```bash
CLUSTER_IP=$(kubectl get svc web -o jsonpath='{.spec.clusterIP}')

# 1. The entry point for all Services
sudo iptables -t nat -L KUBE-SERVICES -n | grep "$CLUSTER_IP"
# KUBE-SVC-XXXXXXXX  tcp  --  0.0.0.0/0  10.96.x.x  /* default/web cluster IP */ tcp dpt:80

# 2. Load balancing for this Service: the statistic module picks an endpoint by probability
sudo iptables -t nat -L KUBE-SVC-XXXXXXXX -n

# 3. One DNAT to Pod IP:80 per endpoint
sudo iptables -t nat -L KUBE-SEP-YYYYYYYY -n
```

![174410](https://lcxlab.com/images/posts/cka-networking/174410.webp)

`KUBE-SVC-*` contains rules with `probability 0.33333` and `0.50000`: with three Pods, the first rule matches 1/3 of the time, what's left picks the second with probability 1/2, and the rest go to the third. The result is an even split.

>[!NOTE] Modes other than iptables
>kube-proxy also supports `ipvs` and `nftables` modes, and CNIs like Cilium can replace kube-proxy entirely. The concept is the same: turn a virtual IP into one of the Pod IPs; only where it's implemented differs.

### NodePort: connecting from outside the cluster

```bash
kubectl expose deployment web --name=web-np --type=NodePort --port=80
kubectl get svc web-np
# web-np   NodePort   10.96.x.x   <none>   80:3xxxx/TCP
```

`80:3xxxx` means that besides ClusterIP:80, port `3xxxx` on every node also forwards to the backend Pods. Test from the Fedora host: **any of the three node IPs works**, even a node with no web Pod on it:

```bash
NODE_PORT=$(kubectl get svc web-np -o jsonpath='{.spec.ports[0].nodePort}')
curl http://<k8s-w1 IP>:$NODE_PORT
curl http://<k8s-cp1 IP>:$NODE_PORT
```

The exam often asks for a specific NodePort value, and `kubectl expose` has no option for it. `kubectl create service nodeport` does have `--node-port`, but its selector is always `app=<service name>` (see the WARNING below), so it won't match when the Service name differs from the Pods' `app` label. The most reliable way is to generate YAML with `expose` and add `nodePort`:

```bash
kubectl expose deployment web --name=web-np2 --type=NodePort --port=80 \
  --dry-run=client -o yaml > web-np2.yaml
# add nodePort: 30080 under ports
kubectl apply -f web-np2.yaml

# If the Service name the task asks for happens to equal the Pods' app label, one line does it
# (this post already has a Service named web, so this is for illustration; running it gives AlreadyExists):
# kubectl create service nodeport web --tcp=80:80 --node-port=30080
```

```yaml
spec:
  type: NodePort
  selector:
    app: web
  ports:
  - port: 80
    targetPort: 80
    nodePort: 30080     # must be within 30000-32767
```

### LoadBalancer, Headless and ExternalName

| Type | Behavior | On a kubeadm practice cluster |
|--|--|--|
| `LoadBalancer` | A NodePort plus the IP of an external load balancer | With no cloud provider, `EXTERNAL-IP` stays `<pending>`, but the NodePort still works. On-prem you need something like MetalLB to get an IP |
| Headless (`clusterIP: None`) | No ClusterIP is assigned; DNS returns all Pod IPs directly | Used with StatefulSets to give each Pod a stable DNS name |
| `ExternalName` | DNS returns a CNAME pointing to a name outside the cluster | Doesn't go through kube-proxy; pure DNS |

```bash
kubectl expose deployment web --name=web-lb --type=LoadBalancer --port=80
kubectl get svc web-lb       # EXTERNAL-IP <pending>

kubectl create service clusterip web-headless --clusterip=None --tcp=80:80
kubectl create service externalname ext-docs --external-name=kubernetes.io
```

>[!WARNING] ❗The selector of `kubectl create service`
>`kubectl create service clusterip` generates the selector `app=<service name>` (`app=web-headless` above), which doesn't match the web Pods. To target an existing Deployment, `kubectl expose` or editing the YAML yourself is safer.

---

## DNS: CoreDNS

Connecting to Services by IP is still inconvenient. Kubernetes' built-in DNS lets Pods connect using names like `web`. kubeadm init already installed CoreDNS.

### Where CoreDNS lives

```bash
kubectl -n kube-system get deploy coredns
kubectl -n kube-system get svc kube-dns       # the Service is named kube-dns, usually at 10.96.0.10
kubectl -n kube-system get cm coredns -o yaml # the Corefile
```

kubeadm's default Corefile looks like this; the comments mark the lines most relevant to the exam:

```text
.:53 {
    errors
    health {
       lameduck 5s
    }
    ready
    kubernetes cluster.local in-addr.arpa ip6.arpa {   # answers names under cluster.local
       pods insecure                                    # lets Pod A records be queried
       fallthrough in-addr.arpa ip6.arpa
       ttl 30
    }
    prometheus :9153
    forward . /etc/resolv.conf {                        # other names go to the node's DNS
       max_concurrent 1000
    }
    cache 30 {
       disable success cluster.local                    # don't cache in-cluster names
       disable denial cluster.local
    }
    loop                                                # detects forwarding loops
    reload                                              # reloads automatically when the ConfigMap changes
    loadbalance
}
```

`forward . /etc/resolv.conf` reads the `/etc/resolv.conf` inside the CoreDNS Pod, whose contents come from kubelet's `resolvConf` setting on the node. On Ubuntu nodes, `/etc/resolv.conf` points to systemd-resolved's `127.0.0.53` (see [systemd-resolved and 127.0.0.53](https://lcxlab.com/en/post/linux-networking-basics#systemd-resolved-and-1270053)). Handed to CoreDNS unchanged, `127.0.0.53` inside a Pod means the Pod itself, so queries loop back into CoreDNS, and when the `loop` plugin detects this it puts CoreDNS straight into CrashLoopBackOff.

So when kubeadm detects systemd-resolved, it makes kubelet read the file that lists the real upstream DNS instead:

```bash
# on any node
sudo grep resolvConf /var/lib/kubelet/config.yaml
# resolvConf: /run/systemd/resolve/resolv.conf
```

### DNS names for Services and Pods

| Target | Name format | Example |
|--|--|--|
| Service | `<svc>.<namespace>.svc.cluster.local` | `web.default.svc.cluster.local` |
| StatefulSet Pod behind a headless Service | `<pod>.<svc>.<namespace>.svc.cluster.local` | `db-0.db.prod.svc.cluster.local` |
| Pod | `<IP with dots replaced by dashes>.<namespace>.pod.cluster.local` | `10-244-1-5.default.pod.cluster.local` |

```bash
kubectl create namespace team-a
kubectl -n team-a create deployment api --image=nginx
kubectl -n team-a expose deployment api --port=80

kubectl run dnstest --image=busybox:1.28 --restart=Never -- sleep 3600
kubectl wait --for=condition=Ready pod/dnstest --timeout=60s   # wait for the container before exec
kubectl exec dnstest -- nslookup web                           # same namespace, the short name is enough
kubectl exec dnstest -- nslookup api                           # fails: api is in team-a
kubectl exec dnstest -- nslookup api.team-a                    # works
kubectl exec dnstest -- nslookup api.team-a.svc.cluster.local  # full name
```

>Newer busybox versions often give odd `nslookup` output inside Kubernetes. The official DNS debugging docs have always used `busybox:1.28`, so this post does too.

>[!WARNING] ❗Don't name a namespace after a real top-level domain
>If a namespace happens to be a public top-level domain (such as `dev`, `app` or `io`), `nslookup api.dev` may resolve the real `api.dev` on the internet rather than the Service in the cluster. busybox 1.28's resolver first tries a name containing a dot as a fully qualified domain and stops applying search once it gets an answer; `.dev` is a real domain run by Google, and `api.dev` really exists. That's why this post uses `team-a`. If you hit this, write the full name `api.dev.svc.cluster.local`.

### A Pod's resolv.conf: search and ndots

Why does the short name `web` resolve while `api` needs `api.team-a`? Look at the settings inside the Pod:

```bash
kubectl exec dnstest -- cat /etc/resolv.conf
# search default.svc.cluster.local svc.cluster.local cluster.local
# nameserver 10.96.0.10
# options ndots:5
```

- `nameserver 10.96.0.10`: kube-dns's ClusterIP
- `search`: looking up `web` tries `web.default.svc.cluster.local`, `web.svc.cluster.local`... in order, and the first one hits; `api.team-a` is expanded to `api.team-a.svc.cluster.local`, which hits
- `ndots:5`: names with fewer than 5 dots get the search domains applied first. So when a Pod looks up `kubernetes.io`, it actually asks for `kubernetes.io.default.svc.cluster.local` and friends a few times in vain first

These fields are explained in [Linux Networking Basics: /etc/resolv.conf](https://lcxlab.com/en/post/linux-networking-basics#etcresolvconf-which-dns-server-to-ask). A Pod's DNS behavior can be tuned with `spec.dnsPolicy` and `spec.dnsConfig`; the default, `ClusterFirst`, produces the settings above.

### DNS troubleshooting order

```bash
# 1. Are the CoreDNS Pods healthy?
kubectl -n kube-system get pods -l k8s-app=kube-dns
kubectl -n kube-system logs -l k8s-app=kube-dns

# 2. Does the kube-dns Service have endpoints?
kubectl -n kube-system get endpointslices -l kubernetes.io/service-name=kube-dns

# 3. Query from inside a Pod
kubectl exec dnstest -- nslookup kubernetes.default

# 4. Names outside the cluster don't resolve → check the Corefile's forward and the node's resolv.conf
sudo grep resolvConf /var/lib/kubelet/config.yaml
```

After you change the Corefile, CoreDNS's `reload` plugin picks it up automatically; to apply it immediately you can also `kubectl -n kube-system rollout restart deploy coredns`.

---

## ==NetworkPolicy==

By default, **every Pod in the cluster can connect to every other Pod**, regardless of namespace. A NetworkPolicy selects a group of Pods by label and gives them an allowlist of "only these sources / destinations".

>[!WARNING] ❗Prerequisite: the CNI must support it
>NetworkPolicies are enforced by the CNI. That's why [Building a kubeadm Cluster (Part 2)](https://lcxlab.com/en/post/cka-kubeadm-cluster) chose Calico over Flannel: on Flannel, applying a policy gives no error but has no effect at all.

### Setting up

```bash
kubectl create namespace netpol
kubectl -n netpol run db --image=nginx --labels=app=db --port=80 --expose
kubectl -n netpol run backend --image=busybox:1.36 --labels=role=backend -- sleep 3600
kubectl -n netpol run other --image=busybox:1.36 --labels=role=other -- sleep 3600

# Before any policy, both can connect
kubectl -n netpol exec backend -- wget -qO- -T 2 db
kubectl -n netpol exec other -- wget -qO- -T 2 db
```

### 1. Deny all ingress by default

`podSelector: {}` selects every Pod in the namespace; `policyTypes` includes `Ingress` but no rules are written, which means deny everything:

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-ingress
  namespace: netpol
spec:
  podSelector: {}
  policyTypes:
  - Ingress
```

```bash
kubectl apply -f default-deny-ingress.yaml
kubectl -n netpol exec backend -- wget -qO- -T 2 db   # timeout
```

### 2. Allow only backend to reach db on port 80

NetworkPolicies are **additive**: when several policies select the same Pod, what's allowed is the union of all of them. So one more allowlist is all it takes:

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: db-allow-backend
  namespace: netpol
spec:
  podSelector:
    matchLabels:
      app: db
  policyTypes:
  - Ingress
  ingress:
  - from:
    - podSelector:
        matchLabels:
          role: backend
    ports:
    - protocol: TCP
      port: 80
```

```bash
kubectl apply -f db-allow-backend.yaml
kubectl -n netpol exec backend -- wget -qO- -T 2 db   # works
kubectl -n netpol exec other -- wget -qO- -T 2 db      # timeout
```

### 3. Allowing other namespaces: the AND vs. OR trap

Under `from`, one `-` more or less changes the meaning completely. This is where people go wrong most often in the exam:

```yaml
# OR: "any Pod" from the team-a namespace, or Pods with role=backend in this namespace
ingress:
- from:
  - namespaceSelector:
      matchLabels:
        kubernetes.io/metadata.name: team-a
  - podSelector:
      matchLabels:
        role: backend
```

```yaml
# AND: only Pods that are in the team-a namespace and have role=backend
ingress:
- from:
  - namespaceSelector:
      matchLabels:
        kubernetes.io/metadata.name: team-a
    podSelector:
      matchLabels:
        role: backend
```

`kubernetes.io/metadata.name` is a label every namespace gets automatically; you don't add it yourself. Confirm with `kubectl get ns --show-labels`.

`kubectl describe` shows how Kubernetes interprets the rules you wrote. Always check it after writing one:

```bash
kubectl -n netpol describe networkpolicy db-allow-backend
```

### 4. Egress: don't forget DNS

When restricting egress, the most common mistake is forgetting to allow DNS, which makes every connection by name fail:

```yaml
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: backend-egress
  namespace: netpol
spec:
  podSelector:
    matchLabels:
      role: backend
  policyTypes:
  - Egress
  egress:
  - to:                              # only db on port 80
    - podSelector:
        matchLabels:
          app: db
    ports:
    - protocol: TCP
      port: 80
  - to:                              # plus CoreDNS in kube-system
    - namespaceSelector:
        matchLabels:
          kubernetes.io/metadata.name: kube-system
      podSelector:
        matchLabels:
          k8s-app: kube-dns
    ports:
    - protocol: UDP
      port: 53
    - protocol: TCP
      port: 53
```

```bash
kubectl apply -f backend-egress.yaml
kubectl -n netpol exec backend -- wget -qO- -T 2 db              # works
kubectl -n netpol exec backend -- wget -qO- -T 2 http://web.default  # timeout
```

>[!NOTE] Rules apply to Pods, not Services
>A NetworkPolicy looks at the Pod IP and `targetPort` after DNAT, not the Service's ClusterIP and `port`. If the Service port is 8080 and the Pod listens on 80, the policy must say 80.

---

## From Ingress to Gateway API

A NodePort can expose a service outside the cluster, but one port above 30000 per service isn't practical. In reality you put an L7 reverse proxy in front that routes to different Services by host and path.

### Ingress

Ingress is Kubernetes' original approach: one resource holds the host, path and backend:

```yaml
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: web
spec:
  ingressClassName: nginx
  rules:
  - host: web.lab.local
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: web
            port:
              number: 80
```

The problem with Ingress is that the spec is too simple. Features like routing by header, weighted splitting and path rewriting all rely on each controller's own annotations, so switching controllers means rewriting them. The most widely used one, ingress-nginx, was also retired in March 2026.

### The Gateway API resource model

The Gateway API splits Ingress into several resources divided by role:

| Resource | Owned by | Contents |
|--|--|--|
| `GatewayClass` | The infrastructure provider | Which implementation to use (Envoy, NGINX, Cilium...), much like a StorageClass |
| `Gateway` | The cluster admin | Which listeners to open (port, protocol, TLS certificates) and which namespaces may attach to it |
| `HTTPRoute` | The application developer | Host, path and header matching rules, and which Services to send traffic to with what weights |

The Gateway API itself is also just CRDs plus a spec; you still need to install an implementation for anything to happen.

### Installing on the kubeadm cluster

Our cluster already runs Calico through tigera-operator, and recent Calico versions ship a Gateway API implementation based on Envoy Gateway (Calico Ingress Gateway). Creating a `GatewayAPI` resource installs both the CRDs and the controller:

```bash
kubectl apply -f - <<EOF
apiVersion: operator.tigera.io/v1
kind: GatewayAPI
metadata:
  name: default
EOF

kubectl get crd | grep gateway.networking.k8s.io    # the Gateway API CRDs
kubectl get gatewayclass                             # should show tigera-gateway-class
```

<!-- TODO: screenshot of kubectl get gatewayclass -->

>[!WARNING] ❗With a default deny in place
>If there is a cluster-wide default-deny NetworkPolicy, the Gateway's namespace needs its own allowance, or the Envoy proxy won't start.

>[!TIP] 💡 If you don't use Calico
>You can also install [Envoy Gateway](https://gateway.envoyproxy.io/docs/tasks/quickstart/) or [NGINX Gateway Fabric](https://docs.nginx.com/nginx-gateway-fabric/) directly. Both come with the Gateway API CRDs and a GatewayClass, and the Gateway and HTTPRoute that follow are written exactly the same way; only `gatewayClassName` differs. That's precisely the problem the Gateway API set out to solve.

### Creating a Gateway and an HTTPRoute

```yaml
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
  name: web-gw
spec:
  gatewayClassName: tigera-gateway-class
  listeners:
  - name: http
    protocol: HTTP
    port: 80
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
  name: web
spec:
  parentRefs:
  - name: web-gw
  hostnames:
  - web.lab.local
  rules:
  - matches:
    - path:
        type: PathPrefix
        value: /
    backendRefs:
    - name: web
      port: 80
```

```bash
kubectl apply -f web-gateway.yaml
kubectl get gateway web-gw                   # PROGRAMMED should be True
kubectl describe httproute web               # Accepted and ResolvedRefs under Conditions should be True
```

Once the Gateway is created, the controller creates a set of Envoy Pods and a `LoadBalancer` Service **in the Gateway's namespace** (here `default`). As before, the practice cluster has no load balancer and `EXTERNAL-IP` stays `<pending>`, so test through its NodePort:

```bash
kubectl get svc -A | grep -i envoy            # find the Gateway's Service and its 80:3xxxx
curl -H "Host: web.lab.local" http://<any node IP>:<NodePort>
```
>Check: you see the nginx welcome page; without the Host header, or with another host, you get a 404.

### Weighted splitting (canary)

Splitting that Ingress can only do with annotations is just a `weight` on `backendRefs` in an HTTPRoute:

```bash
kubectl create deployment web-v2 --image=httpd
kubectl expose deployment web-v2 --port=80
```

```yaml
  rules:
  - backendRefs:
    - name: web
      port: 80
      weight: 90
    - name: web-v2
      port: 80
      weight: 10
```

```bash
for i in $(seq 1 20); do curl -s -H "Host: web.lab.local" http://<node IP>:<NodePort> | grep -o '<title>.*</title>\|It works!'; done
```
>Check: about 2 of the 20 responses are httpd's `It works!`.

>[!NOTE] Migrating from Ingress
>The exam may give you an Ingress and ask you to rewrite it as a Gateway + HTTPRoute. The mapping is: `ingressClassName` → `gatewayClassName`, `rules[].host` → `hostnames`, `paths[]` → `rules[].matches[].path`, `backend.service` → `backendRefs`. SIG Network also provides the [ingress2gateway](https://github.com/kubernetes-sigs/ingress2gateway) tool for automatic conversion.

---

## Cleanup

```bash
kubectl delete ns netpol team-a
kubectl delete deploy web web-v2
kubectl delete svc web web-np web-np2 web-lb web-headless ext-docs web-v2
kubectl delete pod dnstest
kubectl delete httproute web
kubectl delete gateway web-gw
```

---

## Summary

- A cluster has three address ranges: Node, Pod and Service, configured in libvirt, the CNI / controller-manager and kube-apiserver respectively. The Pod and Node ranges must not overlap.
- A Service selects Pods with a selector and the result is written to EndpointSlices; a ClusterIP is iptables DNAT rules written by kube-proxy, and a NodePort opens one more port on every node.
- CoreDNS answers for `cluster.local`, and Pods rely on `search` and `ndots:5` to make short names work; names outside the cluster go to the node's DNS, and on Ubuntu watch out for systemd-resolved.
- NetworkPolicies need CNI support and are additive allowlists; mind the AND / OR syntax under `from`, and remember to allow DNS when restricting egress.
- The Gateway API splits Ingress into GatewayClass, Gateway and HTTPRoute; traffic splitting and header matching are standard fields, with no more reliance on annotations.

The next post moves on to storage: PV, PVC and StorageClass.

---

References:

[1] Service - https://kubernetes.io/docs/concepts/services-networking/service/

[2] Virtual IPs and Service Proxies - https://kubernetes.io/docs/reference/networking/virtual-ips/

[3] DNS for Services and Pods - https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/

[4] Debugging DNS Resolution - https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/

[5] Network Policies - https://kubernetes.io/docs/concepts/services-networking/network-policies/

[6] Ports and Protocols - https://kubernetes.io/docs/reference/networking/ports-and-protocols/

[7] Gateway API - https://gateway-api.sigs.k8s.io/

[8] Ingress NGINX Retirement - https://kubernetes.io/blog/2025/11/11/ingress-nginx-retirement/

[9] Calico Ingress Gateway - https://docs.tigera.io/calico/latest/networking/gateway-api/

[10] Create an ingress gateway (Calico) - https://docs.tigera.io/calico/latest/networking/ingress-gateway/create-ingress-gateway
