Container Network Interface (CNI)

What Is Container Network Interface (CNI)?

The Container Network Interface (CNI) is a specification that defines how container runtimes communicate with network plugins to configure container networking. The purpose of this specification is to enable a common interface between the software that runs the containers and the various plug-ins that allow for the connection of the containers with the networks. CNI plugins are responsible for configuring network connectivity for containers while the runtime calls the relevant plugin and sends it the necessary network configuration processes. Additionally, CNI is responsible for defining the process through which network resources are then released following the removal of containers.

How Does Container Network Interface (CNI) Work?

When a container runtime creates a container, it invokes the configured CNI plugin with network settings and container-specific details. The plugin configures the container’s network interface, assigns network information when required, and establishes connectivity according to its implementation. The plugin returns the result to the runtime, which uses it to complete the container’s network setup.

CNI also defines operations for checking network configuration and removing resources. When a container is deleted, the runtime invokes the plugin’s DEL operation to release allocated resources. The specification defines this interaction, while the plugin determines how networking is implemented.

Key Characteristics of Container Network Interface (CNI)

  • Plugin-based networking: Separates network configuration from container execution through a defined runtime-plugin interface.
  • Network interface configuration: Sets up interfaces and connectivity within a container’s network isolation environment.
  • IP address management integration: Works with IPAM plugins to allocate and manage IP addresses.
  • Lifecycle operations: Defines commands such as ADD, DEL, CHECK, and VERSION for network setup, cleanup, validation, and compatibility.
  • Plugin chaining: Allows multiple plugins to handle different parts of a network configuration.
  • Implementation flexibility: Supports different networking approaches without requiring changes to the container runtime.

Benefits of Container Network Interface (CNI)

  • Interoperability: Container runtimes use a common specification to work with compatible networking plugins.
  • Network choice: Administrators select plugins according to network architecture and operational requirements.
  • Simplified integration: Plugin developers follow a defined protocol instead of building runtime-specific networking integrations.
  • Resource cleanup: Standardized deletion operations help release network resources when containers are removed.

Container Network Interface (CNI) in Cloud Computing

In cloud computing environments that are based on Kubernetes cluster, CNI plugin offers the necessary network connectivity for Pods. Kubernetes employs a supported CNI plugin implementing its networking model where Pods communicate with each other. The implementation of the plugin is responsible for the designing of Pods IP addresses, interfaces, and communication paths.

Cloud networking plugins can connect Pods to different clouds by creating virtual networks for Pods on different nodes of the cluster. For example, AWS VPC CNI and Azure CNI help in connecting the pods networking in Kubernetes to the same cloud-based networking. CNI designates the runtime interaction of plugins without limiting the network capability or saying how the packets are delivered from one Pod to another.