kube-proxy is a network proxy that runs on each node in your cluster. Its primary role is to maintain network rules on nodes. These network rules allow network communication to your Pods.
When you create a Kubernetes Service, it gets a virtual IP (ClusterIP). kube-proxy is responsible for implementing this virtual IP by routing traffic destined for the Service to one of its backing Pods.
Imagine you've deployed a web application in your Kubernetes cluster. You have three pods running your application, and you want to expose them as a single service. You create a Kubernetes Service named my-web-app
with a virtual IP address (e.g., 10.100.100.10) and port 80.
Without kube-proxy, the user's request would never reach the pods, as the virtual IP address of the Service wouldn't be mapped to the actual pod IPs.
kube-proxy is responsible for distributing network traffic to the pods that back a Kubernetes Service. This distribution is a form of load balancing. Therefore, it does perform a layer 4 load balancing function.