The kube-proxy is a network proxy that runs on each node in your Kubernetes cluster, implementing part of the Kubernetes Service concept. It's responsible for maintaining network rules that allow network communication to your Pods from inside or outside the cluster.
Main responsibilities of kube-proxy:
Service Abstraction Implementation:
- Enables the Kubernetes Service concept to work by directing traffic to the appropriate backend Pods
- Makes Services accessible within the cluster and (when configured) from outside
Network Rule Management:
- Maintains network rules on nodes (using iptables, ipvs, or userspace proxying)
- Updates rules when Services and Endpoints change
- Handles port forwarding for Services
Operational modes of kube-proxy:
IPTables mode (default):
- Uses Linux kernel iptables for packet filtering and NAT
- Rules randomly select a backend Pod (for load balancing)
- More efficient than userspace mode, but limited debugging capabilities
- Good for clusters up to a few thousand Services
IPVS mode (introduced in Kubernetes 1.11):
- Uses Linux kernel IP Virtual Server for better performance and more load balancing algorithms
- Scales better than iptables mode for large clusters
- Requires the IPVS kernel modules to be installed
Userspace mode (legacy):
- Runs a simple proxy server in userspace (not kernel)
- Less efficient but easier to debug
- Rarely used in modern deployments
What kube-proxy doesn't do:
- It's not an API gateway or advanced load balancer
- It doesn't provide sophisticated traffic routing features (use Ingress controllers for that)
- It doesn't handle east-west service mesh features like mutual TLS or fine-grained traffic control
Example scenario: When you create a Service of type ClusterIP with 3 backend Pods, kube-proxy on each node sets up rules that ensure any traffic to the Service's IP:port gets properly distributed to one of the 3 Pods. This works regardless of which node the request originates from or which nodes the Pods are running on.
Visualization:
┌─────────────┐
│ kube-proxy │ <-- Runs on every node
└─────────────┘
│
▼
┌───────────────┐ ┌─────────────┐ ┌───────────────┐
│ Client Pod │ ──────> │ Service IP │ ──────> │ Backend Pods │
│ (any node) │ │ (virtual) │ │ (any nodes) │
└───────────────┘ └─────────────┘ └───────────────┘
In essence, kube-proxy is what makes Services work in Kubernetes by providing the networking magic that allows virtual IP addresses to consistently route to the appropriate set of Pods, regardless of where those Pods are running in the cluster.