Skip to Content
Mengty Learns
Kubernetes

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.

explanationintermediateTested with kubernetes 1.35.10Updated Nov 26, 2026

1. Intent

TL;DR

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.

Direct Pod IP addressing breaks whenever Kubernetes reschedules or replaces a Pod.

3. Solution

Kubernetes inserts two stable abstractions between external callers and Pods:

  1. Ingress terminates TLS and inspects HTTP host/path rules (e.g. shop.example.com/cart), routing the request to the matching Service (web).
  2. Service (ClusterIP) owns a stable virtual IP and DNS name (web.default.svc.cluster.local). An EndpointSlice continuously tracks only Ready Pods matching the Service's label selector (app: web), and kube-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

Overview of Kubernetes Request: User → Ingress → Service → Pod. 6 steps.
Overview6 steps in this flow

Press Start or tap any step dot to trace the path.

▸All steps (6)

6. Structure

Ingress routes by HTTP host/path; Service selects Pods by label and maps port 80 to targetPort 8080.

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}`,
);
Run it: labs/k8s-service-routing

Apply 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

When to use
  • 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.
When to avoid
  • 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

Pros
  • 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.
Cons
  • 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

Kubectl Cheatsheet

Quick commands to inspect Pods, Services, and Endpoints during debugging.

Ingress vs Gateway API

Gateway API is the successor to Ingress with role-oriented resources (GatewayClass, Gateway, HTTPRoute) and native TCP/UDP support.

ClusterIP vs NodePort vs LoadBalancer

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?

Sources