Ingress Vs Service Vs Kube-proxy
Ingress: The entry gate
Service: Ensures constant address of the destination
Kube-proxy: Directs requests to proper destination
Analogy
Imagine a pizza ordering system:
Service: This is like the hotline number you dial to place your order. The hotline doesn’t change, even if the staff handling your call or the kitchens fulfilling your order change behind the scenes. It ensures you always know where to call, regardless of who’s working or which kitchen is active.
kube-proxy: It acts like the operator handling calls at the hotline. When you dial the hotline, the operator ensures your call is routed to the right kitchen (Pod) that’s available to fulfill your order. Even if one kitchen is closed, the operator automatically redirects your call to another.
Ingress: Ingress is like an online ordering platform that handles multiple types of orders. It can direct requests to different Services based on specific URLs or paths. Now, imagine you want not just pizza but also pasta and burgers. Instead of calling separate hotline numbers for each, you call a single multi-cuisine hotline. This hotline knows where to forward your call depending on what you’re ordering—pizza to the pizza kitchen, pasta to the pasta station, and burgers to the burger grill. For example, if someone orders a pizza for delivery at
/order/pizza
, the platform routes that to the pizza service. If they want to order sides from/order/sides
, Ingress directs them to the sides service. This setup provides a more refined entry system, especially useful when handling different parts of a large application.
Technical Breakdown
Kubernetes Service
Pods in Kubernetes are dynamic; they can start, stop, or move across nodes, and their IPs can change. A Service abstracts this complexity and ensures consistent access to these Pods. Here’s what it does technically:
Stable Access: Services give a stable IP address or DNS name to connect to, so applications or users don’t need to worry about the specific IPs of individual Pods, which may change over time as Pods are replaced.
Discovery and Load Balancing: Services can load-balance requests across multiple Pods, which is useful for scaling applications. This is especially important in cases like web servers, where incoming requests need to be distributed among several instances.
Types of Services:
ClusterIP: Only accessible within the cluster.
NodePort: Exposes a port on each node to external traffic.
LoadBalancer: Works with cloud providers to assign an external load balancer.
Example in Kubernetes: If you have three Pods running a backend for a web app, you could create a Service with a ClusterIP type to allow other services in the cluster to communicate with it or a LoadBalancer type to expose it to the internet. The Service ensures that any incoming requests can reach any of the three backend Pods as long as they match the Service’s selector labels.
kube-proxy
kube-proxy is the behind-the-scenes operator that makes the magic of Service routing happen. Every node in your Kubernetes cluster runs kube-proxy, which handles the actual traffic routing.
Key Responsibilities of kube-proxy:
Connection Management: kube-proxy continuously monitors the Kubernetes API for changes in Services or their associated Pods and updates its routing rules accordingly.
Traffic Routing: When a request is made to a Service, kube-proxy ensures it reaches one of the Pods associated with that Service.
Load Balancing: kube-proxy balances traffic across all healthy Pods behind a Service, ensuring efficient distribution of requests.
Routing Methods: kube-proxy uses either:
iptables: Linux firewall rules to route traffic efficiently.
IPVS (IP Virtual Server): A more advanced routing method for handling high traffic loads.
Example Scenario:
Suppose a user requests a web page served by your application. kube-proxy intercepts the request at the Service IP and forwards it to a healthy Pod. If a Pod becomes unhealthy or unavailable, kube-proxy stops sending traffic to it and redirects requests to other healthy Pods.
Ingress
An Ingress is a more advanced traffic management tool in Kubernetes. While Services handle traffic within the cluster or expose it externally, Ingress provides a unified entry point for managing HTTP and HTTPS traffic.
Features of Ingress:
Path-Based Routing: Ingress can route traffic based on URL paths. For example:
/api
traffic goes to the backend Service./web
traffic goes to the frontend Service.
Single Entry Point: Instead of exposing multiple Services externally, Ingress consolidates them into one external endpoint.
TLS Termination: Ingress can manage SSL/TLS certificates to handle secure HTTPS traffic directly.
External Integrations: Ingress relies on Ingress Controllers (e.g., NGINX, Traefik) to implement its functionality. These controllers act as reverse proxies, forwarding traffic to the appropriate Service.
Example Scenario:
Your cluster hosts a web app, an API, and a static file server. Using Ingress, you can define rules to route:
example.com/web
to the web app Service.example.com/api
to the API Service.example.com/files
to the file server Service.
This reduces the need to expose multiple Services and simplifies external access.
Key Differences
Feature | Service | kube-proxy | Ingress |
Purpose | Provides stable access to Pods | Routes traffic to correct Pods | Manages external traffic routing |
Scope | Cluster-wide | Node-level | Entry point for the cluster |
Function | Exposes an app to the network | Handles the actual traffic routing | Directs external traffic based on URLs |
Use Case | Load balancing, app exposure | Traffic forwarding, balancing | Advanced HTTP/S routing |
Example | Accessing backend Pods | Forwarding to an active Pod | Directing /api to one Service, /auth to another |
How They Work Together
A client sends a request (e.g.,
https://example.com/api
).Ingress processes the request and forwards it to the appropriate Service (e.g., API Service).
The Service receives the request and provides a stable endpoint for the underlying Pods.
kube-proxy takes over, routing the request to one of the healthy Pods in the API backend.
This modular design ensures:
Ingress: Efficient and consolidated external traffic management.
Service: Stability and abstraction for dynamic Pod environments.
kube-proxy: Seamless routing and load balancing to maintain application availability.
Together, they form the backbone of Kubernetes traffic management, ensuring scalability, reliability, and simplicity for modern applications.
Amazing Resources:
Follow me on linkedin: Md. Musfikur Rahman Sifar | LinkedIn
Subscribe to my newsletter
Read articles from Md. Musfikur Rahman Sifar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by