Hands-on Tutorial: Switching kube-proxy to IPVS Mode in Kubernetes

πŸš€ 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

About Anant 443 Articles
Senior technical writer

1 Trackbacks & Pingbacks

  1. Kubernetes Networking Secrets: How kube-proxy Really Works – KTCHost

Comments are closed.