
π Hands-on Tutorial: Switching kube-proxy
to IPVS Mode in Kubernetes
If you’re running Kubernetes at scale, switching from iptables mode to IPVS can dramatically improve performance and scalability. IPVS (IP Virtual Server) is a kernel-based load balancer that offers better traffic handling than iptables.
πΉ Why Switch to IPVS?
β
Better Performance β Handles thousands of services efficiently.
β
Advanced Load Balancing β Supports algorithms like Least Connections, Round Robin, etc.
β
Faster Packet Processing β Uses the Linux kernel for direct packet forwarding.
Step 1: Check if IPVS Modules are Available
Before enabling IPVS mode, ensure your Linux system supports the required kernel modules.
Run the following command on each Kubernetes node:
lsmod | grep ip_vs
If no output appears, load the necessary modules manually:
modprobe ip_vs
modprobe ip_vs_rr
modprobe ip_vs_wrr
modprobe ip_vs_sh
Now verify again:
lsmod | grep ip_vs
To ensure modules persist after reboot, add them to /etc/modules-load.d/ipvs.conf
:
echo -e "ip_vs\nip_vs_rr\nip_vs_wrr\nip_vs_sh" | sudo tee /etc/modules-load.d/ipvs.conf
Step 2: Install ipvsadm
to Manage IPVS Rules
IPVS requires the ipvsadm
tool to monitor and manage load-balancing rules. Install it using:
sudo apt install -y ipvsadm # For Debian/Ubuntu
sudo yum install -y ipvsadm # For CentOS/RHEL
Check if it’s installed correctly:
ipvsadm -Ln
If no output appears, it means no IPVS rules are currently set.
Step 3: Modify kube-proxy
to Use IPVS Mode
Now, configure kube-proxy
to use IPVS instead of iptables
.
A. Edit the kube-proxy
ConfigMap
kubectl edit cm kube-proxy -n kube-system
Find this section:
mode: "iptables"
Change it to:
mode: "ipvs"
Save and exit.
Step 4: Restart kube-proxy
For the changes to take effect, restart the kube-proxy
pods:
kubectl delete pod -n kube-system -l k8s-app=kube-proxy
Verify if kube-proxy
is now running in IPVS mode:
kubectl logs -n kube-system -l k8s-app=kube-proxy | grep "Using ipvs"
Step 5: Verify IPVS Mode is Active
Run the following command:
ipvsadm -Ln
If you see load-balancing rules listed, congratulations! π Your Kubernetes cluster is now using IPVS mode!
Step 6: Test Service Load Balancing in IPVS Mode
Deploy a test service:
apiVersion: v1
kind: Service
metadata:
name: my-test-service
spec:
selector:
app: my-test-app
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
Apply the service:
kubectl apply -f my-service.yaml
Now, check the IPVS load balancing table again:
ipvsadm -Ln
You should see load-balancing rules pointing to your pod IPs instead of iptables
rules.
π― Summary: Why Use IPVS Mode?
β More efficient packet handling than iptables
β Supports multiple load-balancing algorithms
β Faster rule updates for large clusters
β Scales better with thousands of services
π₯ Next Steps
β
Test different IPVS scheduling algorithms (Least Connections, Round Robin, etc.).
β
Tune IPVS settings for even better performance.
β
Use kubectl get endpoints
to check pod routing dynamically.
#Kubernetes, #kube-proxy, #IPVS, #Networking, #CloudComputing, #DevOps, #LoadBalancing, #K8sNetworking, #ContainerOrchestration