Learn Labs
Networking

Services & the Gateway API

ClusterIP, EndpointSlices, DNS, NodePorts, Gateways, and HTTPRoutes

Every pod gets its own IP, and any pod can reach any other by IP, across nodes, without NAT. That's the Kubernetes network model; the CNI plugin (kindnet here) implements it. But pod IPs change with every replacement, so nothing should use them directly.

Services

kubectl -n shop get svc,endpointslices
NAME                 TYPE        CLUSTER-IP     PORT(S)
service/redis        ClusterIP   None           6379/TCP        # headless
service/shop-nginx   NodePort    10.96.48.169   80:30080/TCP    # the Gateway's NGINX
service/web          ClusterIP   10.96.95.206   8000/TCP

NAME                                              PORTS   ENDPOINTS
endpointslice.discovery.k8s.io/web-c2lh9          8000    10.244.3.40,10.244.1.31,10.244.3.41
endpointslice.discovery.k8s.io/redis-bt5nr        6379    10.244.1.33
TypeWhat you get
ClusterIPA virtual IP inside the cluster; kube-proxy's rules on every node spread connections over the ready endpoints
Headless (clusterIP: None)No virtual IP; DNS returns the pod IPs. StatefulSets use it for stable names like redis-0.redis
NodePortClusterIP, plus a port (30000-32767) open on every node
LoadBalancerNodePort, plus a cloud load balancer in front (in kind: nothing, unless you add cloud-provider-kind or MetalLB)

EndpointSlices are the live list of ready pod addresses for a Service. Only ready pods are listed: that's how readiness probes and node failures take pods out of rotation.

DNS

CoreDNS gives every Service a name: web.shop.svc.cluster.local, or just web from inside the shop namespace and web.shop from elsewhere. The app reaches Redis as redis, and the labs' toolbox reaches the app as web.shop:8000.

Getting traffic in: the Gateway API

HTTPRoute/api/visitscurl :8180NodePort 30080any nodeGateway NGINXshop-nginx podweb podzone-aweb podzone-bweb podzone-credis-0StatefulSet + PVC

The Gateway API splits the old Ingress object into roles:

apiVersion: gateway.networking.k8s.io/v1kind: Gatewaythe entry point; owned by the platform teammetadata: { name: shop }spec:gatewayClassName: nginxwhich implementation (NGINX Gateway Fabric)listeners:- { name: http, port: 80, protocol: HTTP, allowedRoutes: { namespaces: { from: Same } } }---kind: HTTPRoutethe routing rules; owned by the app teammetadata: { name: web }spec:parentRefs: [{ name: shop }]attach to that Gatewayrules:- matches: [{ path: { type: PathPrefix, value: / } }]backendRefs: [{ name: web, port: 8000 }]
kubectl -n shop get gateway,httproute
NAME                                     CLASS   ADDRESS        PROGRAMMED
gateway.gateway.networking.k8s.io/shop   nginx   10.96.48.169   True

For each Gateway, NGINX Gateway Fabric's control plane (namespace nginx-gateway) provisions an NGINX Deployment and Service in the Gateway's namespace (shop-nginx) and writes its configuration from the routes. The bootstrap made that Service a NodePort (30080), which kind maps to localhost:8180.

HTTPRoutes can also split traffic by weight (canary releases), match headers, rewrite paths, and route across namespaces where the Gateway allows it. TLS is a listener on the Gateway with a Secret holding the certificate (usually from cert-manager).

Lab

  1. kubectl -n labs exec deploy/toolbox -- nslookup web.shop.svc.cluster.local, then the same for redis.shop.svc.cluster.local. Why do the answers differ in kind? (Busybox's nslookup doesn't apply search domains, so short names like web.shop fail with it; curl resolves them fine.)
  2. Add a second HTTPRoute rule sending /v2 to a second Deployment, with a 90/10 weight split on /.
  3. Scale web to 0 and request through the Gateway. What status code, from whom?

On this page