Bitesized Engineering

Share this post

What is Container Network Interface (CNI)?

www.bitesizedengineering.com

What is Container Network Interface (CNI)?

Chronicles of Containers - Part 7

Mihailo Joksimovic
Jan 20, 2023
1
Share

Hey there! ๐Ÿ‘‹

Previous article gave an intro to Container Networking and now Iโ€™d like to focus on CNI (Container Network Interface) specifically. If you were ever to deal with a non-Docker runtime, chances are high youโ€™ve heard of it. So, what is it? As usual, first the image and then the details!

(click on image to enlarge)

๐Ÿ“ต ๐‚๐จ๐ง๐ญ๐š๐ข๐ง๐ž๐ซ๐ฌ ๐ก๐š๐ฏ๐ž ๐ง๐จ ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ๐ข๐ฏ๐ข๐ญ๐ฒ ๐›๐ฒ ๐๐ž๐Ÿ๐š๐ฎ๐ฅ๐ญ - and this is really interesting! Try starting a container using "containerd" and then try pinging anything outside of it. It doesn't work! And that's because, out of the box, containers come with very few things set up. That's where Container Networking solutions come into game.

No network adapters out of the box


๐Ÿ•ธ ๐“๐ก๐ž๐ซ๐ž ๐š๐ซ๐ž ๐ฆ๐š๐ง๐ฒ ๐ฌ๐จ๐ฅ๐ฎ๐ญ๐ข๐จ๐ง๐ฌ ๐จ๐ฎ๐ญ ๐ญ๐ก๐ž๐ซ๐ž - Docker uses it's own logic to set up the networking, containerd relies on CNI, whereas Kubernetes allows you to specify your own CRI (Container Runtime Interface) compliant solution.

Screenshot from https://landscape.cncf.io/


โšก ๐‚๐๐ˆ ๐ข๐ฌ ๐š ๐ฌ๐ข๐ฆ๐ฉ๐ฅ๐ž ๐š๐ง๐ ๐ฒ๐ž๐ญ ๐ฉ๐จ๐ฐ๐ž๐ซ๐Ÿ๐ฎ๐ฅ ๐Ÿ๐ซ๐š๐ฆ๐ž๐ฐ๐จ๐ซ๐ค - although not the ONLY one out there (as can be seen on screenshot above) it appears to be the most popular framework for solving the network configuration problem. And the beauty of it is that it's REALLY SIMPLE. Itโ€™s simple because it boils down to specifying a config file and using existing (or writing new) plugins to do the actual work for you.

โœ ๐ƒ๐ž๐ฌ๐œ๐ซ๐ข๐›๐ž ๐ฒ๐จ๐ฎ๐ซ ๐ง๐ž๐ญ๐ฐ๐จ๐ซ๐ค - first step is to create a manifest file (fancy word for a simple JSON config file, really) that describes which interfaces you need, which subnets to use, which ports to open, etc. And this is usually done by your network admin. Hereโ€™s the default one I used for testing purposes:

CNI manifest file, describing WHAT I want out of my network


๐Ÿ‘‘ ๐ƒ๐ข๐ฏ๐ข๐๐ž & ๐œ๐จ๐ง๐ช๐ฎ๐ž๐ซ - instead of wasting time implementing billion different solutions by itself, CNI went the other route - YOU are supposed to write a program that takes YOUR manifest and does something useful with it. And that program is called "plugin". Luckily for us, there's tons of prebuilt plugins for common scenarios, but if you need something specific you are more than free to write it! Hereโ€™s an example of how it looks like now:

Good enough to have Internet back!

Do note two things, though: 1) I specified โ€œโ€”cniโ€ parameter, which tells containerd to use CNI plugin, and 2) it loads manifest file from โ€œ/etc/cni/net.dโ€ (and yes, this maps to D:\etc\cni\net.d on Windows :)).

๐Ÿ‘ฎโ€โ™€โ€ ๐‚๐๐ˆ ๐ž๐ง๐ฌ๐ฎ๐ซ๐ž๐ฌ ๐ฉ๐ซ๐จ๐œ๐ž๐ฌ๐ฌ ๐ข๐ฌ ๐œ๐š๐ซ๐ซ๐ข๐ž๐ ๐ญ๐ก๐ซ๐จ๐ฎ๐ ๐ก - if you check official CNI website, you will notice that they call it a FRAMEWORK which specifies the format of MANIFEST and how plugins communicate with Runtime. It doesn't say HOW you configure stuff, but it rather ensures there's a common language between Runtime, Containers & Plugins.

And that's pretty much all about it :) CNI works pretty well on Windows and, as such, makes for a great candidate for your container journey ;)

Next article will likely deal a bit more with Container Runtimes, but until then, if you havenโ€™t subscribed already, nowโ€™s the time to do so!

Thanks for reading Bitesized Engineering! Subscribe for free to receive new posts and support my work.

P.S. If you missed some of the previous articles, here are the last three that were published:

Bitesized Engineering
๐ˆ๐ง๐ญ๐ซ๐จ ๐ญ๐จ ๐‚๐จ๐ง๐ญ๐š๐ข๐ง๐ž๐ซ ๐๐ž๐ญ๐ฐ๐จ๐ซ๐ค๐ข๐ง๐ 
Hey there! ๐Ÿ‘‹ As promised last week, Iโ€™m switching gears a bit and moving back to deep-dives in containers :) If you are curious on โ€œWHYโ€ am I switching contexts, itโ€™s actually quite simple - Iโ€™m experimenting with this approach where I spend a week or two exploring a topic, and just when I reach the peak of โ€œwow, I can draw a ton of stuff on this topicโ€ฆ
Read more
5 months ago ยท Mihailo Joksimovic
Bitesized Engineering
How do COWs (Containers on Windows) work?
Hey there! ๐Ÿ‘‹ What a better to spend your Sunday than reading a bit on containers, eh? :) I actually planned on sharing this article on Tuesday but it opened so many things to think about that I just couldnโ€™t wait. As usual, hereโ€™s an infographic, and the expanded description can be found below itโ€ฆ
Read more
5 months ago ยท Mihailo Joksimovic
Bitesized Engineering
Containers are like The Truman Show
Hey folks! Iโ€™ve been gearing it a bit up this week and thatโ€™s why Iโ€™m publishing a bit more than usual. And this really happens a lot - the moment I get interested in a topic and the more I gain knowledge of it, the more Iโ€™m curious and the faster do I produce content. Does that happen to you as wellโ€ฆ
Read more
5 months ago ยท Mihailo Joksimovic
1
Share
Comments
Top
New
Community

No posts

Ready for more?

ยฉ 2023 Mihailo Joksimovic
Privacy โˆ™ Terms โˆ™ Collection notice
Start WritingGet the app
Substackย is the home for great writing