Service Routing: Ingress → Service → Pod
How a Kubernetes request travels from a user's browser through Ingress and Service to a healthy Pod and back.
1. Intent
Understand how Kubernetes decouples external traffic from ephemeral Pod IPs: Ingress handles Layer 7 HTTP routing, Service provides a stable virtual IP and load-balancing across endpoints, and Pods run the actual application containers.
2. Problem
Pods in Kubernetes are ephemeral—they get rescheduled, scaled up, or replaced during deployments, and each new Pod receives a new IP address. If clients or an external load balancer hardcoded Pod IPs, every rollout or crash would break traffic.
3. Solution
Kubernetes inserts two stable abstractions between external callers and Pods:
- Ingress terminates TLS and inspects HTTP host/path rules (e.g.
shop.example.com/cart), routing the request to the matching Service (web). - Service (
ClusterIP) owns a stable virtual IP and DNS name (web.default.svc.cluster.local). AnEndpointSlicecontinuously tracks only Ready Pods matching the Service's label selector (app: web), andkube-proxy(via iptables/IPVS/eBPF) distributes traffic to a healthy Pod.
4. Real-world analogy
5. Flow: watch it work
Kubernetes Request: User → Ingress → Service → Pod
Press Start or tap any step dot to trace the path.
▸All steps (6)
6. Structure
7. Code
// Declarative representation of a Service + Ingress routing pair
interface ServiceSpec {
name: string;
selector: Record<string, string>;
port: number;
targetPort: number;
}
interface IngressRule {
host: string;
path: string;
serviceName: string;
servicePort: number;
}
const webService: ServiceSpec = {
name: 'web',
selector: { app: 'web' },
port: 80,
targetPort: 8080,
};
const webIngress: IngressRule = {
host: 'shop.example.com',
path: '/cart',
serviceName: webService.name,
servicePort: webService.port,
};
console.log(
`Route https://${webIngress.host}${webIngress.path} -> ${webIngress.serviceName}:${webIngress.servicePort} -> Pod:${webService.targetPort}`,
);labs/k8s-service-routingApply the Service and Ingress manifests in a local kind or minikube cluster.
kubectl apply -f labs/k8s-service-routing/k8s/8. When to use / when to avoid
- You need HTTP/HTTPS host or path-based routing, TLS termination, or virtual hosting across multiple Services.
- You want a single external entry point instead of provisioning a cloud LoadBalancer per Service.
- Your backend Pods scale dynamically and need automatic endpoint discovery.
- You only need internal cluster-to-cluster communication (use a ClusterIP Service directly).
- You need non-HTTP TCP/UDP routing (consider Gateway API TCPRoute/UDPRoute or a LoadBalancer Service).
- You are starting a brand-new cluster that already standardizes on Kubernetes Gateway API.
9. How to implement
Label your Pods consistently
Ensure your Deployment's spec.template.metadata.labels includes app: web.
Create the ClusterIP Service
Match spec.selector to app: web, expose port: 80, and forward to the container's targetPort: 8080.
Configure readiness probes
Add a readinessProbe on the Pod so unready Pods are excluded from the Service's EndpointSlice.
Add the Ingress resource
Define the host and path rule pointing backend.service.name to web on port 80, then verify with kubectl describe ingress web-ingress.
10. Pros / Cons
- Decouples external URLs and TLS certificates from internal Pod IPs.
- One Ingress controller can route to dozens of Services behind a single public IP.
- Automatic zero-downtime endpoint updates during rolling deployments.
- Requires an Ingress controller (e.g. ingress-nginx, Traefik, Envoy) installed in the cluster.
- Ingress is L7 HTTP/HTTPS only; custom annotations vary between controllers.
11. Relations
Quick commands to inspect Pods, Services, and Endpoints during debugging.
Gateway API is the successor to Ingress with role-oriented resources (GatewayClass, Gateway, HTTPRoute) and native TCP/UDP support.
Service types control whether a Service is reachable only inside the cluster or directly on node/cloud IPs.
12. Check yourself
Check Yourself
1. A Deployment scales from 2 Pods to 3, and the new Pod's readinessProbe is failing. What does the Service do?
2. Which Kubernetes resource handles TLS termination and HTTP path routing like /cart → web:80?