Kube-Proxy vs Container Network Interface (CNI) Explained
A

Lead Engineer @ Packetware

Kube-Proxy vs Container Network Interface (CNI) Explained

Calico:

Purpose: Calico is a Container Network Interface (CNI) plugin. It provides networking and network security for Kubernetes clusters. It focuses primarily on routing traffic between pods across nodes and implementing network policies.

Key Features of Calico:

1. Pod Networking:

  • Calico manages the pod-to-pod communication by setting up routes between pods, across nodes, and within the pod network. It typically uses BGP (Border Gateway Protocol) to dynamically route packets between nodes.
  • Each node gets a specific Pod CIDR, and Calico ensures that pods on different nodes can communicate seamlessly by managing the underlying network routes.

2. Network Policies:

  • Calico enforces Kubernetes NetworkPolicies, which allow fine-grained control over which pods can communicate with each other and with external endpoints. It can enforce both Ingress and Egress traffic rules.
  • You can create rules that limit or block traffic to/from certain pods based on labels, namespaces, or other criteria.

3. Flexible Networking:

  • Supports a variety of networking modes such as IP-in-IP, BGP, or VXLAN.
  • Works with both IPv4 and IPv6.

4. IP Address Management:

  • Assigns IP addresses to pods and manages routes for them within the cluster.

5. Optional NAT:

  • Calico can be configured with or without NAT (Network Address Translation), depending on your needs for external access to pods.

6. Service Routing:

  • Does not handle Kubernetes services directly (e.g., ClusterIP or NodePort). It only handles routes for pod-to-pod communication, while kube-proxy takes care of service-based routing.

kube-proxy:

Purpose: kube-proxy is a service networking component in Kubernetes that routes service traffic within a cluster. It is responsible for ensuring that network traffic is properly forwarded to the right pod backends that serve a given Kubernetes Service (e.g., ClusterIP, NodePort, LoadBalancer).

Key Features of kube-proxy:

1. Service Traffic Routing:

  • kube-proxy manages the networking for Kubernetes Services (e.g., ClusterIP, NodePort, LoadBalancer) by programming rules to forward traffic to the correct pod backends.
  • It handles service discovery by exposing services using a virtual IP (ClusterIP), and routing the traffic to the associated pods through iptables (or IPVS in newer setups).

2. Traffic Load Balancing:

  • kube-proxy uses iptables or IPVS to perform load balancing of incoming traffic between all the healthy pod backends of a service.
  • This ensures that traffic is distributed evenly across multiple pods that serve the same service.

3. Service IP Management:

  • kube-proxy is responsible for maintaining a set of rules that map ClusterIPs to the corresponding pod backends. When traffic is sent to a ClusterIP, it forwards it to the correct pod(s).

4. NodePort and External Traffic:

  • kube-proxy enables NodePort services, which allow external clients to access a Kubernetes service by exposing a port on the node’s IP.
  • For external traffic, kube-proxy ensures traffic is routed from the node to the appropriate pod via NodePort.

Table Overview

Aspect Calico kube-proxy
Primary Function Handles pod-to-pod networking and enforces network policies Manages service traffic routing and load-balancing (ClusterIP, NodePort)
Service Management Does not handle services directly (services are managed by kube-proxy) Handles ClusterIP, NodePort, LoadBalancer services
Pod Network Provides BGP, VXLAN, or other modes to route pod traffic Does not manage pod networking directly; relies on CNI plugins like Calico
Network Policies Enforces Kubernetes NetworkPolicies for controlling traffic flow between pods and external networks Does not handle network policies
Traffic Forwarding Handles L3 routing (e.g., BGP, IP-in-IP) for pod-to-pod communication Handles L4 load balancing and forwarding of service traffic to pods using iptables or IPVS
Load Balancing Does not perform load balancing directly Load balances traffic across multiple pods in a service
Overlay/Underlay Supports overlay networks (IP-in-IP, VXLAN) and underlay routing via BGP Not involved in overlay/underlay networking
Pod IP Management Assigns and manages pod IPs and routes Does not manage pod IPs; relies on CNI plugins