1
CNI相关介绍
1. CNI概念
Container Network Interface,容器网络接口,这个接口是 由 CRI 发起调用。接口的提供形式是 exec 二进制文件,重定向输入输出(元信息 version),以及设置环境变量(各种关键参数,pod name、namespace、netns 等)。即,将固定结构入参序列化成 json 字符串,重定向给 cni 二进制文件,二进制文件执行完从标准输出返回一个固定结构 json 序列化的结果。即,完成一次 cni 调用。官方文档详见https://www.cni.dev/docs/spec/#section-4-plugin-delegation
2. 常见实现思路
二进制、脚本:containernetworking/plugins: Some reference and example networking plugins, maintained by the CNI team(请复制粘贴后打开)
cncf 官方带的 cni 实现,都是直接在二进制里实现的,用不同的 linux 内核特性,创建容器 network interface 支持不同的网络模式,如bridge,ipvlan,vlan等,cncf 自带的 ipam 有 dhcp、static、host-local 。
Plugins supplied:
Main: interface-creating
bridge
: Creates a bridge, adds the host and the container to it.ipvlan
: Adds an ipvlan interface in the container.loopback
: Set the state of loopback interface to up.macvlan
: Creates a new MAC address, forwards all traffic to that to the container.ptp
: Creates a veth pair.vlan
: All