Welcome to this lesson on how Kubernetes uses the Container Network Interface (CNI) to configure network plugins for containers. In earlier lessons, we covered the fundamentals of network namespaces, Docker networking, and the emergence of CNI along with its plugins.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.


Kubelet Configuration for CNI
The kubelet service on each node is the key component for configuring the CNI plugin. Within the kubelet service file, the network plugin is set to CNI and options are provided that specify the directories for both CNI plugins and configuration files. Here is an example snippet from a kubelet service file:- The CNI binaries directory (
/opt/cni/bin), which contains executables for supported plugins (e.g., bridge, DHCP, flannel). - The CNI configuration directory (
/etc/cni/net.d), where the kubelet reads configuration files to determine which plugin to use.
If multiple configuration files exist in the directory, kubelet selects the first file in alphabetical order. A common configuration file is
10-bridge.conf.Example Bridge Configuration
Below is an example bridge configuration file (10-bridge.conf) that complies with the CNI standard:
- The
"bridge"parameter specifies the name of the bridge interface (in this case,cni0). - The
"isGateway"option determines whether the bridge network should have an IP address to function as a gateway. - The
"ipMasq"option configures IP masquerading (NAT rules) for outgoing traffic. - The
"ipam"section sets up IP Address Management. Here,"host-local"management is used where the"subnet"field defines the IP range for the pods (e.g.,10.22.0.0/16), and the"routes"array sets the default routing.
Be cautious when modifying the IPAM settings, as incorrect configuration can lead to network conflicts or unreachable pods.
"dhcp" if you prefer to use an external DHCP server for IP address allocation.
That concludes our lesson on how Kubernetes integrates with CNI to manage container networking. For more detailed information, consider exploring Kubernetes Documentation.