Skip to main content

Chapter 2.7 - kube-proxy

Learning Objectives

By the end of this chapter, you will be able to:

  • Understand the role of kube-proxy
  • Explain how kube-proxy manages Services
  • Understand proxy modes
  • Identify load balancing

What is kube-proxy?

kube-proxy is a network component that runs on every node. It maintains the network rules that enable communication with Services from inside and outside the cluster.


Roles of kube-proxy

1. Service Management

kube-proxy monitors Services and their Endpoints:

2. Load Balancing

Distributes traffic among backend Pods:

3. Network Rules

Maintains iptables or ipvs rules for:

  • Routing to Services
  • NAT (Network Address Translation)
  • Load balancing

Proxy Modes

1. userspace (Deprecated)

Old mode, low performance.

2. iptables (Default)

Uses iptables for routing:

Advantages:

  • Performant
  • No user process
  • Native Linux

Uses IPVS (IP Virtual Server) from the Linux kernel:

Advantages:

  • More performant than iptables
  • Better load balancing
  • Supports more algorithms

How it Works with a Service

Example: ClusterIP Service

apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- port: 80
targetPort: 8080

What happens:

  1. Service created -> kube-proxy detects the change
  2. Endpoints discovered -> kube-proxy finds backend Pods
  3. Rules created -> iptables/ipvs configured
  4. Traffic routed -> Requests to the Service are distributed

Load Balancing

Supported Algorithms

  • Round Robin: Fair distribution
  • Least Connection: Fewer active connections
  • Source IP Hash: Same Pod for same source

Example: Round Robin


Service Types

ClusterIP

kube-proxy creates rules to route internal traffic.

NodePort

kube-proxy opens a port on each node and routes to the Pods.

LoadBalancer

kube-proxy configures routing, the cloud provider creates the external load balancer.


Useful Commands

# View iptables rules (on the node)
sudo iptables -t nat -L -n

# View ipvs rules (if ipvs mode)
sudo ipvsadm -ln

# View Service Endpoints
kubectl get endpoints <service-name>

# View Service details
kubectl describe service <service-name>

Summary

In this chapter, you learned:

kube-proxy: Manages networking and load balancing
Services: Traffic routing to backend Pods
Modes: iptables (default) or ipvs (production)
Load Balancing: Traffic distribution among Pods
Network rules: Maintaining routing rules


Next Steps

Now that you understand kube-proxy:

Chapter 2.8: Container Runtime
Chapter 2.9: Inter-Component Communication


Chapter created: December 2024