Cni In Kubernetes
- CNI defines responsibilities of a container runtime.
- The Container Runtime must create the network namespace.
- Must identify and attach the namespaces to the appropriate container.
- Container Runtime to invoke Network Plugin (bridge) when a container is ADDed.
- Container Runtime to invoke the Network Plugin (bridge) when a container is DELeted.
- JSON format of the Network Configuration.
- CNI plugin must be invoked by the component within Kubernetes for creating containers.
- That component must invoke the appropriate network plugin, after the container is created.
- The component responsible for creating containers is the Container Runtime.
- Two good examples are
containerdandcri-o. containerdis an abstraction ofdockerand replaces it.
- Two good examples are
- All network plugins are installed under
/opt/cni/bin- This is where the Container Runtimes find the plugins.
- Which plugin and which to use is configured in the
/etc/cni/net.ddirectory.- May be multiple configuration files in this directory.
- Examples are
bridge.conflistandflannel.conflist.
- Checking the
/opt/cni/bindirectory will show the following available plugins:bridge dhcp flannel host-local ipvlan loopback macvlan portmap ptp sample tuning vlan weave-ipam weave-net weave-plugin-2.2.1 - The
/etc/cni/net.ddirectory has a bunch of configuration files:10-bridge.conflist - If there are multiple files in the above directory, it will choose the one in alphabetical order.
- The
10-bridge.conflistfile looks like this:`{ "cniVersion": "0.2.0", "name": "mynet", "type": "bridge", "bridge": "cni0", "isGateway": true, "ipam": { "type": "host-local", "subnet": "10.22.0.0/16", "routes": [ { "dst": "0.0.0.0/0"} ] } } - The
isGatewaydefines whether an IP Address should be assigned. ipMasqdefines if a NAT rule should be added for IP masquerading.- The IPAM section defines an IPAM configuration.
- Specify the subnet and IPs that are assigned to pods and any required routes.
host-localindicates the IP addresses are managed locally on the host. Thetypecan also be set todhcpto configure an external DHCP server.