Prerequisite Cni Container Networking Interfac
- Currently with Network Namespaces –>
1. Create Network Namespace–>2. Create Bridge Network / Interface–>3. Create VETH Pairs (Pipe, Virtual Cable)–>4. Attach vEth to Namespace–>5. Attach Other vEth to Bridge–>6. Assign IP Addresses–>7. Bring the interfaces up–>8. Enable NAT - IP Masquerade - How
Dockerdoes it –>1. Crate Network Namespace–>2. Create Bridge Network / Inteface–>3. Create VETH Pairs (Pipe, Virtual Cable)–>4. Attach vEth to Namespace–>Attach Other vEth to Bridge–>6. Assign IP Addresses–>7. Bring the interfaces up–>8. Enable NAT - IP Masqueradekubernetes,rkt,mesosfollows the exact same steps as above.
- Why code the same solution multiple times? Why not use one approach that everyone can follow?
- We split off
1. Crate Network Namespaceinto its own part.- Then place
2. Create Bridge Network / Inteface–>3. Create VETH Pairs (Pipe, Virtual Cable)–>4. Attach vEth to Namespace–>Attach Other vEth to Bridge–>6. Assign IP Addresses–>7. Bring the interfaces up–>8. Enable NAT - IP Masqueradeunder aBridgeconfig.
- Then place
- We run a script that runs the above tasks to have a container connect to the
Bridgenetwork. - Example of adding a container to a particular network namespace:
bridge add 2e34dcf34 /var/run/netns/2e34dcf34 - The
Bridgeprogram takes care of the rest, so the runtime environments don’t need to bother with those tasks. - For example, how
rktandkubernetesget networking configured for a particular container:bridge add <cid> <namespace> - What is a CNI?
- Set of standards - define how programs should be developed to solve networking challenges in container runtime environments.
- This type of program is referred to as a
plugin.
- This type of program is referred to as a
- Set of standards - define how programs should be developed to solve networking challenges in container runtime environments.
- In the above case,the
Bridgeprogram would be a plugin for the CNI.- CNI defines how the plugin should be developed and how container run times should use them.
-
Defines a set of runtimes and responsibilities:
- Container Runtime must create a network namespace.
- Identify the network that the container must attach to.
- Have the container runtime invoke the Network Plugin (bridge) when the container is ADDed (using the
addcommand). - The Container runtime invokes the Network Plugin (bridge) when the container is DELeted (using the
delcommand). - Specifies how to configure a network plugin on the runtime environment using a JSON file.
- It must support cmdline environments such ash
ADD/DEL/CHECK. - Must support parameters
container id,network ns. - Must manage IP address assignment to PODs.
-
Must return results in a specific format.
- As long as the container runtimes and plugins, no problem.
- CNI already comes with this set of supported plugins:
BRIDGEVLANIPVLANMACVLANWINDOWSDHCPhost-local
- Other plugins from third-party advisors as well:
weaveworks flannel cilium nsx calico infobox - All of the above container run time implement CNI standards.
- All of them can work with the above plugins.
Dockerdoes not implement CNI.Dockerhas its own standard called CNM (Container Network Model).- Aims to solve container networking challenges.
- The above plugins do not natively integrate with
Dockerbecause of the different network model in use. - Can’t run a
dockercontainer and specify a CNI like the following:docker run --network=cni-bridge nginx - Doesn’t mean you can’t use
dockerwith CNI at all. Have to work around it:docker run --network=none nginx - Then manually invoke the
bridgeplugin:bridge add 2e34dcf34 /var/run/netns/2e34dcf34 - The above is how Kubernetes does it:
- When Kubernetes creates
Dockercontainers, it creates them on the non-network. - Invokes the CNI changes.
- Takes care of the rest of the configuration.
- When Kubernetes creates