How Deployment, Service, and Ingress Work Together in Kubernetes
When you deploy an application in Kubernetes, three key components work together to expose your API to users:
-
Deployment → Creates and manages your Pods
-
Service → Provides stable network access to the Pods
-
Ingress → Provides external access (HTTP/HTTPS) to the Service
Understanding how these three connect is essential for deploying any microservice.
1. Deployment → Creates Pods
A Deployment manages your application Pods:
-
Ensures the right number of replicas
-
Performs rolling updates
-
Restarts Pods if they crash
Example:
Each Pod has its own IP, which changes when pods restart.
That’s why we cannot access Pods directly — the IPs are not stable.
2. Service → Stable Access to Pods
A Service (usually ClusterIP) sits in front of the Pods:
-
Provides a fixed stable IP inside the cluster
-
Load-balances requests to the Pods
-
Selects Pods using labels
Example:
Any Pod with this label becomes part of the service.
3. Ingress → External Access via HTTP/HTTPS
A Service is only accessible inside the cluster.
If you need external access, you create an Ingress resource.
Ingress:
-
Maps URLs/domains → to services
-
Works through an Ingress Controller (nginx, traefik, AWS ALB)
-
Supports TLS/SSL
Example:
Full Connectivity Flow (Simple Diagram)
🔁 Step-by-Step Request Flow
1️⃣ A user calls:
2️⃣ Ingress receives the request
Matches a rule:
3️⃣ Ingress forwards to Service
This is internal routing.
4️⃣ Service load balances to Pods
Based on labels.
5️⃣ Pod handles the request
Returns response → Service → Ingress → Client.
🧩 How They Connect in YAML
Deployment → Pods
Service selects Pods
Ingress sends traffic to Service
This label-chain is how they connect.
Text Diagram of Logical Mapping
If labels don’t match → service will have 0 pods → no traffic.
Why Kubernetes Uses All 3 Layers?
| Component | Purpose |
|---|---|
| Deployment | Run & manage your application containers |
| Service | Stable network endpoint inside cluster + load balancing |
| Ingress | Public HTTP/HTTPS access + routing + |
No comments:
Post a Comment