Network plugins implement the Container Network Interface (CNI) in Kubernetes, providing the crucial ability for pods to communicate with each other across nodes. They're responsible for the "plumbing" that enables network connectivity in your cluster.

Core responsibilities of network plugins:

  1. Pod Networking:

    • Assign IP addresses to pods
    • Create virtual interfaces for containers
    • Establish routes between pods across different nodes
    • Implement the Kubernetes networking model
  2. Network Policy Enforcement (in many plugins):

    • Implement Kubernetes NetworkPolicy resources
    • Provide pod-level firewalling
    • Control ingress/egress traffic at the pod level
  3. Cross-Node Communication:

    • Create overlay networks or configure underlay networks
    • Handle encapsulation/decapsulation of packets
    • Manage routing tables and rules

The Kubernetes networking model requires that:

Popular network plugins:

  1. Calico:

    • Uses BGP routing or VXLANs (configurable)
    • Strong focus on security with rich network policy features
    • Good performance with minimal overlay overhead in BGP mode
    • Scales to very large deployments
  2. Cilium:

    • Uses eBPF for high-performance networking
    • Advanced security with Layer 7 filtering (HTTP/gRPC/etc.)
    • Built-in observability features
    • Layer 4 load balancing
  3. Flannel:

    • Simpler implementation, easy to set up
    • Uses overlay networks (typically VXLAN)
    • Good for getting started, fewer advanced features
  4. Weave Net:

    • Creates a virtual network that connects containers across nodes
    • Handles network partitions well
    • Includes encryption options
  5. AWS VPC CNI (Amazon EKS):

    • Gives pods IPs directly from the VPC
    • Native AWS networking performance
    • No overlay overhead
  6. Azure CNI (AKS):

    • Similar to AWS CNI but for Azure
  7. Antrea:

    • Based on Open vSwitch
    • Good integration with VMware environments

How network plugins work:

  1. Installation: The plugin is deployed as a DaemonSet (runs on every node)

  2. Configuration: The kubelet is configured to use a specific CNI plugin

  3. Pod Creation: When a pod is created, kubelet asks the CNI plugin to set up networking

  4. Address Allocation: The plugin assigns an IP from its managed pool

  5. Interface Creation: Virtual interfaces are created and connected

  6. Routing: Routes are established to enable cross-node communication

Example: How traffic flows between pods on different nodes with an overlay network:

Pod A (10.244.1.2) on Node 1 → Pod B (10.244.2.3) on Node 2

1. Pod A sends packet to 10.244.2.3
2. Packet hits Node 1's routing table
3. CNI plugin encapsulates packet (e.g., VXLAN)
4. Encapsulated packet sent to Node 2's physical IP
5. Node 2 receives and decapsulates packet
6. Packet delivered to Pod B's network namespace

Network plugins essentially create a flat network where all pods can reach each other, regardless of which node they're on. The specific implementation details vary significantly between plugins, with different performance, security, and feature trade-offs.