# What Is the Purpose of the Container Network Interface (CNI) in Kubernetes?

> Discover the purpose of Container Network Interface (CNI) in Kubernetes. Learn how CNI assigns IPs to pods and enables network connectivity, simplifying container orchestration.

- Repository: [Anil Kumar/DevOps-Interview-Guide](https://github.com/litu54/DevOps-Interview-Guide)
- Tags: deep-dive
- Published: 2026-08-10

---

**The Container Network Interface (CNI) provides the networking layer that assigns unique IP addresses to pods and establishes connectivity between them, abstracting the underlying network infrastructure so Kubernetes can focus on container orchestration.**

The Container Network Interface (CNI) in Kubernetes serves as the fundamental plumbing that gives every pod its own network identity and connectivity. According to the `litu54/DevOps-Interview-Guide` repository, when the kubelet creates a pod, it invokes a CNI plugin to handle the low-level networking details. This architecture allows Kubernetes to remain agnostic about the underlying network implementation while ensuring seamless communication across the cluster.

## How the Container Network Interface (CNI) Functions in Kubernetes

When a pod is scheduled, the kubelet delegates network setup to the configured CNI plugin. As documented in [`Arrise_Solutions/DevOps_Engineer.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/Arrise_Solutions/DevOps_Engineer.md) at line 13, this process involves three critical operations that transform isolated containers into networked entities capable of communicating with other pods and services.

### IP Address Allocation and Network Namespace Attachment

The first responsibility of the CNI plugin is to **allocate an IP address** from a configured CIDR range or directly from the cloud provider's VPC subnet. The plugin then attaches this IP to the pod's dedicated network namespace, ensuring each pod receives a unique network identity. This mechanism, referenced in the interview guide, prevents IP conflicts and enables granular network tracking.

### Route Configuration and Policy Enforcement

After assigning the IP, the CNI plugin establishes the necessary **network routes and policies** to facilitate communication. As noted in [`ZS_Associates/DevOps_Engineer.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/ZS_Associates/DevOps_Engineer.md) at line 9, this includes configuring routing tables so pods can reach other pods, Kubernetes services, and external endpoints. The plugin simultaneously enforces isolation rules through network policies and security groups, maintaining segmentation between workloads.

### Infrastructure Integration Through Plugins

The CNI specification supports multiple plugin implementations that integrate with diverse underlying infrastructures. According to [`Amazon/DevOps_Consultant_1.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/Amazon/DevOps_Consultant_1.md) at line 14, whether the cluster runs on AWS, on-premises, or hybrid environments, the specific CNI plugin—such as Calico, Flannel, AWS VPC CNI, or Cilium—determines whether pods use the same CIDR as the VPC or a separate overlay network. This flexibility allows organizations to align Kubernetes networking with their existing infrastructure requirements.

## Common CNI Plugin Implementations

Different CNI plugins offer varying capabilities, from basic connectivity to advanced network policy enforcement. The following examples demonstrate how two popular plugins deploy within a cluster.

### AWS VPC CNI for EKS

The AWS VPC CNI plugin assigns IP addresses directly from the Amazon VPC, enabling pods to communicate with AWS resources using first-class VPC networking. Deploy this plugin as a DaemonSet:

```yaml

# aws-vpc-cni.yaml

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: aws-node
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: aws-node
  template:
    metadata:
      labels:
        k8s-app: aws-node
    spec:
      serviceAccountName: aws-node
      containers:
      - name: aws-node
        image: amazon/k8s-cni:latest
        env:
        - name: AWS_VPC_K8S_CNI_LOGLEVEL
          value: DEBUG
        - name: AWS_VPC_K8S_CNI_VETHPREFIX
          value: eth0
        securityContext:
          privileged: true

```

### Calico for Network Policy Enforcement

Calico provides both networking and network policy capabilities, often using an overlay network with IPIP encapsulation. Configure the IP pool and deploy the node agent:

```yaml

# calico-config.yaml

apiVersion: projectcalico.org/v3
kind: IPPool
metadata:
  name: default-ipv4-ippool
spec:
  cidr: 192.168.0.0/16
  ipipMode: Always
  natOutgoing: true
  disabled: false
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: calico-node
  namespace: kube-system
spec:
  selector:
    matchLabels:
      k8s-app: calico-node
  template:
    metadata:
      labels:
        k8s-app: calico-node
    spec:
      serviceAccountName: calico-node
      containers:
      - name: calico-node
        image: calico/node:v3.26.0
        env:
        - name: FELIX_INTERFACEPREFIX
          value: eth
        securityContext:
          privileged: true

```

## Configuring the Kubelet for CNI

To enable CNI functionality, the kubelet must be configured to use the CNI network plugin and point to the appropriate binary and configuration directories. This configuration specifies where the kubelet discovers available CNI plugins:

```yaml

# kubelet-config.yaml

apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
networkPlugin: cni
cniConfDir: /etc/cni/net.d
cniBinDir: /opt/cni/bin

```

## Summary

- **CNI provides network identity**: Every pod receives a unique IP address attached to its network namespace, enabling individual network tracking.
- **CNI abstracts infrastructure**: The plugin architecture separates Kubernetes orchestration from underlying network implementation details, supporting diverse environments from cloud VPCs to on-premises overlays.
- **CNI enables policy enforcement**: Beyond basic connectivity, CNI plugins implement network policies and security rules that isolate workloads and control traffic flow.
- **Configuration is kubelet-driven**: The kubelet invokes CNI plugins during pod creation based on configuration files located in standard directories like `/etc/cni/net.d`.

## Frequently Asked Questions

### What is the primary purpose of the Container Network Interface (CNI) in Kubernetes?

The primary purpose of the Container Network Interface (CNI) in Kubernetes is to provide the networking infrastructure that assigns IP addresses to pods and establishes connectivity between them. According to the source material in [`Arrise_Solutions/DevOps_Engineer.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/Arrise_Solutions/DevOps_Engineer.md), CNI acts as the "plumbing" that gives each pod its own network identity while abstracting the underlying network implementation from the Kubernetes orchestration layer.

### How does the kubelet interact with CNI plugins during pod creation?

When the kubelet creates a new pod, it invokes the configured CNI plugin to set up the pod's network stack. The plugin allocates an IP address, attaches it to the pod's network namespace, and configures routing rules. This process, documented in [`Amazon/DevOps_Consultant_1.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/Amazon/DevOps_Consultant_1.md), ensures that by the time the pod starts running, it has full network connectivity according to the cluster's configuration.

### What is the difference between AWS VPC CNI and Calico?

AWS VPC CNI assigns IP addresses directly from the Amazon VPC's CIDR blocks, allowing pods to communicate as first-class VPC citizens without overlay networking. Calico, as referenced in [`ZS_Associates/DevOps_Engineer.md`](https://github.com/litu54/DevOps-Interview-Guide/blob/main/ZS_Associates/DevOps_Engineer.md), typically uses an overlay network with IPIP encapsulation and focuses heavily on network policy enforcement. While AWS VPC CNI optimizes for AWS integration and performance, Calico provides advanced security features and works across multiple cloud providers and on-premises environments.

### Why does Kubernetes use CNI instead of built-in networking?

Kubernetes uses CNI to maintain separation of concerns between container orchestration and network implementation. The CNI specification allows Kubernetes to remain agnostic about how the underlying network is configured, whether it runs on AWS, Azure, GCP, or on-premises hardware. This modularity enables operators to choose plugins that match their specific infrastructure requirements, security policies, and performance characteristics without modifying the Kubernetes core.