kube-proxy Role
kube-proxy is a network proxy component that runs on each node in a Kubernetes cluster and manages network rules to route virtual IPs (Cluster IP) provided by Services to actual Pods.
In other words, it's a network manager that connects Services and Pods.
1. Service -> Pod Routing #
It creates essential network rules to forward requests coming to a Service's ClusterIP to the actual Pod IP.
- iptables mode
- ipvs mode
It generates routing rules using one of the two methods above.
Pod Endpoint Change Detection and Automatic Rule Updates #
When a new Pod is created, it's added to the routing targets, and when it dies, it's immediately removed from the routing targets.
If it's not in a Ready state, it's excluded from traffic delivery targets.
In other words, kube-proxy also keeps the list of Pods behind a Service up-to-date.
NodePort Implementation #
A NodePort Service opens a specific port on all nodes.
kube-proxy also opens this port and forwards requests coming to that port to the appropriate Pod.
Load Balancing #
When there are multiple Pods behind it, it distributes traffic evenly.
- Round robin ipvs
- Random iptables
- Session-based option ipvs
This means that without kube-proxy, a Service would be an empty shell with just an IP, unable to deliver traffic to Pods.
kube-proxy = Network routing manager that connects Services to actual Pods Definition: Node-level network proxy Key roles:
- Service virtual IP → Pod actual IP routing
- Rule updates based on endpoint (Pod) changes
- NodePort handling
- Traffic load balancing