Kubernetes Labs · Lab 2 of 9
Services, DNS and the Gateway API: Getting Traffic to Pods
Put two apps behind ClusterIP Services, resolve them with cluster DNS, open a NodePort, then install Envoy Gateway and route /api and / to different Services with the Gateway API, the successor to Ingress.
- Environment
- Kubernetes
- Level
- Beginner
- Time
- About 50 min
- Cost
- Free
You will build
curl localhost:8080/api/orders reaching the api pods and curl localhost:8080/ reaching the web pods through a
Gateway, plus a working mental model of Services, EndpointSlices and DNS.
Before you start
Pods come and go and their IPs change, so clients never talk to pods directly. A Service gives a set of pods one stable name and IP. It finds its pods with a label selector, and Kubernetes keeps an EndpointSlice listing the IPs of the pods that are ready. kube-proxy on every node turns the Service IP into connections to those pods, and CoreDNS answers the name.
Service types
- ClusterIP (default): reachable only inside the cluster. Most Services are this.
- NodePort: also opens the same port (30000–32767) on every node. Simple, but you manage ports and node IPs.
- LoadBalancer: asks the cloud for a load balancer in front of the nodes (the cloud labs use this).
- Headless (
clusterIP: None): no virtual IP, DNS returns pod IPs; used by StatefulSets (lab 3).
Gateway API instead of Ingress
HTTP routing by host and path used to be done with Ingress. The most used controller, ingress-nginx, was retired in 2026 and its repository archived. The Gateway API is the official successor: it splits the job into a GatewayClass (which controller), a Gateway (the listener, owned by the platform team) and HTTPRoutes (the rules, owned by app teams). Every major cloud and proxy implements it. This lab uses Envoy Gateway.
Every output below was captured from a real run on kind 0.33 with Kubernetes 1.37. Pod names, IP addresses, ages and cluster ports are generated, so yours will differ; everything else should match.
Project structure
services-and-gateway/ ├── apps.yaml # namespace shop, Deployments web and api, ClusterIP Services ├── nodeport.yaml # Service web-nodeport on node port 30081 ├── gateway.yaml # EnvoyProxy (NodePort 30080), GatewayClass envoy, Gateway shop └── routes.yaml # HTTPRoutes: /api → api, / → web
Steps
-
1Two apps and their Services
Both apps run the same small web server;
WHOAMI_NAMEmakes each answer with its own name. Each Service selects its pods by label and forwards port 80 to the container port namedhttp.apps.yaml apiVersion: v1 kind: Namespace metadata: name: shop --- apiVersion: apps/v1 kind: Deployment metadata: name: web namespace: shop spec: replicas: 2 selector: matchLabels: app: web template: metadata: labels: app: web spec: containers: - name: whoami image: traefik/whoami:v1.11.0 env: - name: WHOAMI_NAME value: web ports: - name: http containerPort: 80 --- apiVersion: apps/v1 kind: Deployment metadata: name: api namespace: shop spec: replicas: 2 selector: matchLabels: app: api template: metadata: labels: app: api spec: containers: - name: whoami image: traefik/whoami:v1.11.0 env: - name: WHOAMI_NAME value: api ports: - name: http containerPort: 80 --- apiVersion: v1 kind: Service metadata: name: web namespace: shop spec: selector: app: web ports: - name: http port: 80 targetPort: http --- apiVersion: v1 kind: Service metadata: name: api namespace: shop spec: selector: app: api ports: - name: http port: 80 targetPort: http -
2Apply and inspect Services and EndpointSlices
Each Service got a stable ClusterIP. Its EndpointSlice lists the pod IPs behind it; they match the pod list. If a pod dies or fails readiness, its IP leaves the slice and no traffic goes to it.
Run kubectl apply -f apps.yaml kubectl -n shop rollout status deployment/web deployment/api kubectl -n shop get svc kubectl -n shop get endpointslices kubectl -n shop get pods -o wideExpected output
namespace/shop created deployment.apps/web created deployment.apps/api created service/web created service/api created ... deployment "web" successfully rolled out deployment "api" successfully rolled out NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE api ClusterIP 10.96.161.7 <none> 80/TCP 0s web ClusterIP 10.96.34.69 <none> 80/TCP 0s NAME ADDRESSTYPE PORTS ENDPOINTS AGE api-hj66r IPv4 80 10.244.2.13,10.244.1.8 10s web-sqs4t IPv4 80 10.244.1.9,10.244.2.12 10s NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES api-77ccc9bd6b-4s27c 1/1 Running 0 0s 10.244.2.13 lab-k8s-local-worker2 <none> <none> api-77ccc9bd6b-nvzt4 1/1 Running 0 0s 10.244.1.8 lab-k8s-local-worker <none> <none> web-645bdc8c9d-jxpcx 1/1 Running 0 0s 10.244.1.9 lab-k8s-local-worker <none> <none> web-645bdc8c9d-zlt45 1/1 Running 0 0s 10.244.2.12 lab-k8s-local-worker2 <none> <none>
Hint
If an EndpointSlice shows fewer IPs than pods, a pod isn't ready yet; run the command again.
-
3Resolve a Service name with cluster DNS
Every Service gets the DNS name
<service>.<namespace>.svc.cluster.local. Inside the same namespace the short namewebworks too. This runs a throwaway busybox pod that is deleted when it finishes.Run kubectl -n shop run dns-test --rm -i --restart=Never --image=busybox:1.38.0 -- nslookup web.shop.svc.cluster.localExpected output
Server: 10.96.0.10 Address: 10.96.0.10:53 Name: web.shop.svc.cluster.local Address: 10.96.34.69 pod "dns-test" deleted from shop namespace
Check:The address is the ClusterIP of
webfrom the previous step;10.96.0.10is CoreDNS's own Service.Hint
kubectl may also print a note that the session is recorded in container logs, or that it fell back to streaming logs. Both are harmless.
-
4Watch the Service balance requests
Run kubectl -n shop run curl-test --rm -i --restart=Never --image=busybox:1.38.0 -- sh -c 'for i in 1 2 3 4 5 6; do wget -qO- http://web | grep Hostname; done'Expected output
Hostname: web-645bdc8c9d-jxpcx Hostname: web-645bdc8c9d-jxpcx Hostname: web-645bdc8c9d-jxpcx Hostname: web-645bdc8c9d-zlt45 Hostname: web-645bdc8c9d-zlt45 Hostname: web-645bdc8c9d-jxpcx pod "curl-test" deleted from shop namespace
Check:Both web pods appear. kube-proxy picks a pod per connection, so the split is random, not round-robin.
-
5Open a NodePort
A NodePort Service opens port 30081 on every node. kind maps it to
localhost:8081(seekind-config.yaml), so the request goes your computer → node port → kube-proxy → a web pod.nodeport.yaml # Opens port 30081 on every node. kind maps it to localhost:8081 (kind-config.yaml). apiVersion: v1 kind: Service metadata: name: web-nodeport namespace: shop spec: type: NodePort selector: app: web ports: - name: http port: 80 targetPort: http nodePort: 30081 -
6Call the NodePort from your computer
Run kubectl apply -f nodeport.yaml kubectl -n shop get svc web-nodeport for i in 1 2 3 4; do curl -s localhost:8081 | grep Hostname; doneExpected output
service/web-nodeport created NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE web-nodeport NodePort 10.96.134.228 <none> 80:30081/TCP 0s Hostname: web-645bdc8c9d-zlt45 Hostname: web-645bdc8c9d-zlt45 Hostname: web-645bdc8c9d-jxpcx Hostname: web-645bdc8c9d-jxpcx
-
7Install Envoy Gateway
The release manifest installs the Gateway API resource types (CRDs) and the Envoy Gateway controller.
--server-sideis needed because some CRDs are too large for a normal apply.Run kubectl apply --server-side -f https://github.com/envoyproxy/gateway/releases/download/v1.10.0/install.yaml kubectl -n envoy-gateway-system wait deployment/envoy-gateway --for=condition=Available --timeout=5m kubectl get crds | grep gateway.networking.k8s.ioExpected output
... job.batch/eg-gateway-helm-certgen serverside-applied mutatingwebhookconfiguration.admissionregistration.k8s.io/envoy-gateway-topology-injector.envoy-gateway-system serverside-applied deployment.apps/envoy-gateway condition met backendtlspolicies.gateway.networking.k8s.io Namespaced v1(storage),v1alpha3 2026-11-26T19:16:29Z gatewayclasses.gateway.networking.k8s.io Cluster v1(storage),v1beta1 2026-11-26T19:16:29Z gateways.gateway.networking.k8s.io Namespaced v1(storage),v1beta1 2026-11-26T19:16:29Z grpcroutes.gateway.networking.k8s.io Namespaced v1(storage) 2026-11-26T19:16:29Z httproutes.gateway.networking.k8s.io Namespaced v1(storage),v1beta1 2026-11-26T19:16:29Z ...
-
8Create the GatewayClass and the Gateway
The GatewayClass says Envoy Gateway handles Gateways of class
envoy. The Gateway is a listener on HTTP port 80; Envoy Gateway runs an Envoy proxy for it. On a cloud cluster that proxy would get a cloud load balancer. kind has none, so the EnvoyProxy settings make it a NodePort on 30080 (mapped tolocalhost:8080).externalTrafficPolicy: Clustermatters on kind: the host port enters through the control-plane node, which runs no Envoy pod. With the defaultLocal, a node only accepts traffic for pods running on that node, so requests would hang.Localkeeps the client's IP and saves a hop, which is why clouds use it with load balancers that health-check each node.gateway.yaml # Envoy Gateway runs the data plane (Envoy) as a Service. On kind there is no cloud load balancer, # so this EnvoyProxy makes it a NodePort on 30080, which kind maps to localhost:8080. apiVersion: gateway.envoyproxy.io/v1alpha1 kind: EnvoyProxy metadata: name: kind-nodeport namespace: envoy-gateway-system spec: provider: type: Kubernetes kubernetes: envoyService: type: NodePort # kind maps host ports through the control-plane node, which runs no Envoy pod. # Cluster lets any node forward to Envoy (the default, Local, only answers on nodes running it). externalTrafficPolicy: Cluster patch: type: StrategicMerge value: spec: ports: - port: 80 nodePort: 30080 --- apiVersion: gateway.networking.k8s.io/v1 kind: GatewayClass metadata: name: envoy spec: controllerName: gateway.envoyproxy.io/gatewayclass-controller parametersRef: group: gateway.envoyproxy.io kind: EnvoyProxy name: kind-nodeport namespace: envoy-gateway-system --- apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: shop namespace: shop spec: gatewayClassName: envoy listeners: - name: http protocol: HTTP port: 80 -
9Apply the Gateway
Run kubectl apply -f gateway.yaml kubectl -n shop wait gateway/shop --for=condition=Programmed --timeout=180s kubectl -n shop get gateway kubectl -n envoy-gateway-system get svc -l gateway.envoyproxy.io/owning-gateway-name=shopExpected output
envoyproxy.gateway.envoyproxy.io/kind-nodeport created gatewayclass.gateway.networking.k8s.io/envoy created gateway.gateway.networking.k8s.io/shop created gateway.gateway.networking.k8s.io/shop condition met NAME CLASS ADDRESS PROGRAMMED AGE shop envoy 172.21.0.2 True 11s NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE envoy-shop-shop-0b6553f4 NodePort 10.96.22.11 <none> 80:30080/TCP 10s
Check:PROGRAMMEDisTrueand the Envoy Service shows80:30080. -
10Route by path with HTTPRoutes
Each HTTPRoute attaches to the Gateway with
parentRefsand sends matching requests to a Service. The most specific match wins, so/api…goes to api and everything else to web.routes.yaml apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: api namespace: shop spec: parentRefs: - name: shop rules: - matches: - path: type: PathPrefix value: /api backendRefs: - name: api port: 80 --- apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: web namespace: shop spec: parentRefs: - name: shop rules: - matches: - path: type: PathPrefix value: / backendRefs: - name: web port: 80 -
11Send requests through the Gateway
The two paths from your computer into the cluster, side by side:
Two ways in from your computer: a NodePort straight to a Service, or a Gateway that routes by path Run kubectl apply -f routes.yaml curl -s localhost:8080/ | head -2 curl -s localhost:8080/api/orders | head -2 for i in 1 2 3 4; do curl -s localhost:8080/api/orders | grep Hostname; done kubectl -n shop get httproute api -o jsonpath='{range .status.parents[0].conditions[*]}{.type}={.status}{"\n"}{end}'Expected output
httproute.gateway.networking.k8s.io/api created httproute.gateway.networking.k8s.io/web created Name: web Hostname: web-645bdc8c9d-zlt45 Name: api Hostname: api-77ccc9bd6b-4s27c Hostname: api-77ccc9bd6b-nvzt4 Hostname: api-77ccc9bd6b-nvzt4 Hostname: api-77ccc9bd6b-nvzt4 Hostname: api-77ccc9bd6b-4s27c Accepted=True ResolvedRefs=True
Check:/answersName: web,/api/ordersanswersName: api, and the route isAcceptedwithResolvedRefs.Hint
Use
/api/orders, not/api: this demo server answers its own JSON API on exactly/api. -
12Clean up
Delete the namespace (apps, Services, Gateway and routes), then the GatewayClass and Envoy Gateway. The NotFound lines are expected: the namespace delete already removed the Gateway, and the one-time certificate Job had finished.
Run kubectl delete namespace shop kubectl delete -f gateway.yaml kubectl delete -f https://github.com/envoyproxy/gateway/releases/download/v1.10.0/install.yamlExpected output
namespace "shop" deleted envoyproxy.gateway.envoyproxy.io "kind-nodeport" deleted from envoy-gateway-system namespace gatewayclass.gateway.networking.k8s.io "envoy" deleted Error from server (NotFound): error when deleting "gateway.yaml": gateways.gateway.networking.k8s.io "shop" not found ... mutatingwebhookconfiguration.admissionregistration.k8s.io "envoy-gateway-topology-injector.envoy-gateway-system" deleted Error from server (NotFound): error when deleting "envoy-gateway-install.yaml": jobs.batch "eg-gateway-helm-certgen" not found
In production
The objects are the same in production; what changes is where traffic enters and how it is secured.
What changes
| In this lab | In production |
|---|---|
| NodePort + kind port mapping | A cloud load balancer (Service type LoadBalancer, or the cloud's own Gateway class) |
| HTTP on port 80 | HTTPS only, certificates from cert-manager or the cloud, HTTP redirected to HTTPS |
| One Gateway in the app namespace | A shared Gateway owned by the platform team; app teams attach HTTPRoutes from their namespaces |
externalTrafficPolicy: Cluster |
Local behind a cloud load balancer to keep client IPs and avoid an extra hop |
| Any pod can call any Service | NetworkPolicies limit who can call what (lab 9) |
| One replica of the gateway proxy | At least two proxy replicas across zones, with a PodDisruptionBudget |
Choosing an entry point
Use a ClusterIP Service for everything internal. Expose HTTP(S) through one Gateway per environment rather than a LoadBalancer per app: one public IP, one place for TLS, and per-team routes. Keep NodePort for special cases such as a cloud load balancer that can only target nodes. Ingress still works and many clusters run it; plan a move to the Gateway API for anything new, especially where ingress-nginx is still in use.
Production checklist
- Every Service selects pods by stable labels and targets named container ports
- Public traffic enters through a Gateway (or Ingress) with TLS; nothing else is exposed
- Gateway proxies run two or more replicas across zones with resource requests and a PodDisruptionBudget
- Readiness probes on every backend, so EndpointSlices only contain pods that can serve
- Timeouts and retries are set on routes deliberately, not left to defaults
- Access logs and request metrics from the gateway go to your monitoring
- Clusters still on ingress-nginx have a migration plan to the Gateway API or a maintained controller
Learn the concepts
- Services · Kubernetes Tutorial
- DNS and Service Discovery · Kubernetes Tutorial
- Ingress and the Gateway API · Kubernetes Tutorial
- Kubernetes in Production · Course
Preparing for the CKA or CKS exam? Practice tests and mock exams →