CNI Comparison
A comprehensive comparison of Kubernetes CNI plugins including Calico, Flannel, Weave, Cilium, and Antrea. Learn about features, performance, use cases, and how to choose the right CNI for your cluster.
The Container Network Interface (CNI) is a standard for configuring network interfaces in Linux containers. CNI plugins are responsible for providing network connectivity to pods in a Kubernetes cluster. They handle IP address allocation, routing, and network policy enforcement.
Choosing the right CNI plugin is critical for cluster performance, security, and operational complexity. Each CNI has different trade-offs in terms of features, performance, and ease of use.
- Performance: Throughput, latency, and resource usage
- Network Policy: Support for Kubernetes NetworkPolicy
- Feature Set: Encryption, service mesh integration, eBPF
- Operational Complexity: Installation, configuration, troubleshooting
- Ecosystem: Community support, documentation, integrations
Calico
Flannel
Weave Net
Cilium
Antrea
Calico is the most widely deployed CNI plugin in production Kubernetes clusters. It provides a comprehensive networking solution with advanced features including:
# Install Calico
kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.27/manifests/calico.yaml
# Verify Calico pods
kubectl get pods -n kube-system -l k8s-app=calico-node
# Calico NetworkPolicy
apiVersion: projectcalico.org/v3
kind: NetworkPolicy
metadata:
name: allow-frontend
namespace: default
spec:
selector: app == 'backend'
types:
- Ingress
ingress:
- action: Allow
protocol: TCP
source:
selector: app == 'frontend'
destination:
ports:
- 8080
# Calico eBPF mode (high performance)
# Enable in installation manifest
apiVersion: operator.tigera.io/v1
kind: Installation
metadata:
name: default
spec:
calicoNetwork:
linuxDataplane: BPF
# Calico BGP configuration
apiVersion: projectcalico.org/v3
kind: BGPPeer
metadata:
name: external-bgp
spec:
peerIP: 192.168.1.100
asNumber: 65000
- Full NetworkPolicy enforcement (including egress)
- BGP routing for direct pod-to-pod communication
- eBPF dataplane for high performance
- Rich feature set (wireguard encryption, service mesh)
- Strong community and documentation
Cilium represents the next generation of CNI plugins, leveraging eBPF (extended Berkeley Packet Filter) for high-performance networking and security. It provides deep observability and identity-based security.
# Install Cilium with Helm
helm repo add cilium https://helm.cilium.io/
helm repo update
helm install cilium cilium/cilium --namespace kube-system \
--set ipam.mode=kubernetes \
--set routingMode=native \
--set hubble.enabled=true \
--set hubble.relay.enabled=true \
--set hubble.ui.enabled=true
# Verify Cilium status
kubectl get pods -n kube-system -l k8s-app=cilium
cilium status
# Cilium NetworkPolicy (L7-aware)
apiVersion: cilium.io/v2
kind: CiliumNetworkPolicy
metadata:
name: allow-http
spec:
endpointSelector:
matchLabels:
app: backend
ingress:
- fromEndpoints:
- matchLabels:
app: frontend
toPorts:
- ports:
- port: "8080"
protocol: TCP
rules:
http:
- method: GET
path: "/api/users"
# Enable Hubble observability
cilium hubble enable
cilium hubble ui
# View network flows
hubble observe
hubble observe --from-label app=frontend
hubble observe --to-service kube-dns
- eBPF Performance: High throughput, low latency
- Identity-Based Security: Labels instead of IPs
- L7 Policies: HTTP, Kafka, DNS-aware policies
- Hubble Observability: Flow logs, service maps
- Service Mesh: Integrated service mesh capabilities
Flannel is the simplest CNI plugin, designed to be easy to install and operate. It uses overlay networking (VXLAN, host-gw, or UDP) to provide pod-to-pod communication.
# Install Flannel
kubectl apply -f https://github.com/flannel-io/flannel/releases/latest/download/kube-flannel.yml
# Verify Flannel pods
kubectl get pods -n kube-system -l app=flannel
# Flannel configuration (configmap)
apiVersion: v1
kind: ConfigMap
metadata:
name: kube-flannel-cfg
namespace: kube-system
data:
net-conf.json: |
{
"Network": "10.244.0.0/16",
"Backend": {
"Type": "vxlan"
}
}
# Alternative backend: host-gw (no overlay)
# "Backend": {
# "Type": "host-gw"
# }
# Check Flannel subnet allocation
kubectl exec -n kube-system -it -- cat /run/flannel/subnet.env
- Development and testing environments
- Small clusters with simple networking needs
- When network policy is not required
- Quick cluster setup and prototyping
- Resource-constrained environments
Antrea is a CNI plugin that uses Open vSwitch (OVS) as the networking data plane. It's the CNI of choice for VMware Tanzu and provides enterprise-grade networking features.
# Install Antrea
kubectl apply -f https://github.com/antrea-io/antrea/releases/latest/download/antrea.yml
# Verify Antrea pods
kubectl get pods -n kube-system -l app=antrea
# Antrea NetworkPolicy (Kubernetes API)
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: antrea-policy
spec:
podSelector:
matchLabels:
app: backend
ingress:
- from:
- podSelector:
matchLabels:
app: frontend
ports:
- port: 8080
# Antrea-specific features (traceflow)
apiVersion: antrea.io/v1alpha1
kind: Traceflow
metadata:
name: test-trace
spec:
source:
namespace: default
pod: frontend-pod
destination:
namespace: default
pod: backend-pod
packet:
ipHeader:
protocol: 6
ttl: 64
# Enable eBPF acceleration in Antrea
apiVersion: antrea.tanzu.vmware.com/v1alpha1
kind: AntreaConfig
metadata:
name: antrea-config
namespace: kube-system
spec:
features:
eBPF: true
Performance varies significantly between CNI plugins. Here's a general comparison of key metrics:
| Metric | Calico (eBPF) | Calico (iptables) | Cilium | Flannel (VXLAN) | Flannel (host-gw) | Weave |
|---|---|---|---|---|---|---|
| Throughput | Near Native | Good | Near Native | Good | Excellent | Good |
| Latency | Very Low | Low | Very Low | Medium | Very Low | Medium |
| Resource Usage | Medium | High | Medium | Low | Low | Medium |
| Network Policy | Full | Full | Advanced (L7) | None | None | Limited |
| Observability | Good | Good | Excellent | None | None | Basic |
| Complexity | Medium | Medium | High | Low | Low | Low |
For Production Clusters
For Security-Focused Workloads
For High Performance
For Development/Testing
For Cloud-Native Environments
For Service Mesh Integration
Choosing the right CNI plugin is one of the most important decisions for your Kubernetes cluster. Consider your requirements for performance, security, features, and operational complexity, and test thoroughly before deploying to production.