容器网络接口(CNI) Plugin SPEC介绍
本文主要介绍一下容器网络接口(CNI) 的SPEC,主要参考SPEC v0.3.1,以及目前最新的SPEC,目前新SPEC针对v0.3.1版本改动不是很大,特别是相关接口输入输出方面,因此可以看作是一样的。
总览
所有的CNI Plugin,都必须实现为可以被容器管理系统(如rtk、Kubernetes等)调用的可执行文件。
CNI插件负责将网络接口插入容器网络命名空间(例如veth pair的其中一端),并在主机上进行任何必要的改变(例如将veth pair的另一端连接到网桥)。然后应该将IP分配给接口,并通过调用适当的IPAM插件将与“IP地址管理”部分一致的IP地址分配给该网络接口,并设置好对应的路由。
参数
所有的CNI Plugin必须实现以下操作:
添加一个容器到网络
- Parameters:
- Version. The version of CNI spec that the caller is using (container management system or the invoking plugin).
- Container ID. A unique plaintext identifier for a container, allocated by the runtime. Must not be empty.
- Network namespace path. This represents the path to the network namespace to be added, i.e. /proc/[pid]/ns/net or a bind-mount/link to it.
- Network configuration. This is a JSON document describing a network to which a container can be joined. The schema is described below.
- Extra arguments. This provides an alternative mechanism to allow simple configuration of CNI plugins on a per-container basis.
- Name of the interface inside the container. This is the name that should be assigned to the interface created inside the container (network namespace); consequently it must comply with the standard Linux restrictions on interface names.
- Result:
- Interfaces list. Depending on the plugin, this can include the sandbox (eg, container or hypervisor) interface name and/or the host interface name, the hardware addresses of each interface, and details about the sandbox (if any) the interface is in.
- IP configuration assigned to each interface. The IPv4 and/or IPv6 addresses, gateways, and routes assigned to sandbox and/or host interfaces.
- DNS information. Dictionary that includes DNS information for nameservers, domain, search domains and options.
- Parameters:
从网络中删除一个容器
- Parameters:
- Version. The version of CNI spec that the caller is using (container management system or the invoking plugin).
- Container ID, as defined above.
- Network namespace path, as defined above.
- Network configuration, as defined above.
- Extra arguments, as defined above.
- Name of the interface inside the container, as defined above.
- All parameters should be the same as those passed to the corresponding add operation.
- A delete operation should release all resources held by the supplied containerid in the configured network.
- Parameters:
报告插件支持的CNI版本
Parameters: NONE.
Result: information about the CNI spec versions supported by the plugin
{ "cniVersion": "0.3.1", // the version of the CNI spec in use for this output "supportedVersions": [ "0.1.0", "0.2.0", "0.3.0", "0.3.1" ] // the list of CNI spec versions that this plugin supports }