使用 IPvlan 的 AWS VPC Kubernetes CNI 驱动程序
cni-ipvlan-vpc-k8s contains a set of
CNI and IPAM plugins to
provide a simple, host-local, low latency, high throughput, and compliant
networking stack for
Kubernetes
within Amazon Virtual Private Cloud
(VPC) environments by making use of
Amazon Elastic Network Interfaces
(ENI)
and binding AWS-managed IPs into Pods using the Linux kernel's IPvlan
driver in L2 mode.
The plugins are designed to be straightforward to configure and deploy
within a VPC. Kubelets boot and then self-configure and scale their IP
usage as needed, without requiring the often recommended complexities
of administering overlay networks, BGP, disabling source/destination
checks, or adjusting VPC route tables to provide per-instance subnets
to each host (which is limited to 50-100 entries per VPC). In short,
cni-ipvlan-vpc-k8s significantly reduces the network complexity
required to deploy Kubernetes at scale within AWS.
The maximum number of Pods per AWS instance is determined by ENI limits. Instance types offering 8 ENIs can scale up to and beyond the default Kubernetes limit of 110 pods per instance.
The primary EC2 boot ENI with its primary private IP is used as the IP address for the node. Our CNI plugins manage additional ENIs and private IPs on those ENIs to assign IP addresses to Pods.
Each Pod contains two network interfaces, a primary IPvlan interface and an unnumbered point-to-point virtual ethernet interface. These interfaces are created via a chained CNI execution.
For applications where Pods need to directly communicate with the Internet, by setting the default route to the unnumbered point-to-point interface, our stack can source NAT traffic from the Pod over the primary private IP of the boot ENI, which enables making use of Amazon’s Public IPv4 addressing attribute feature. When enabled, Pods can egress to the Internet without needing to manage Elastic IPs or NAT Gateways.
Kubelets and Daemon Sets have high bandwidth, host-local access to all Pods running on the instance — traffic doesn’t transit ENI devices. Source and destination IPs are the well-known Kubernetes addresses on either side of the connect.
Our design is heavily optimized for intra-VPC traffic where IPvlan is the only overhead between the instance’s ethernet interface and the Pod network namespace. We bias toward traffic remaining within the VPC and not transiting the IPv4 Internet where veth and NAT overhead is incurred. Unfortunately, many AWS services require transiting the Internet; however, both DynamoDB and S3 offer VPC gateway endpoints.
While we have not yet implemented IPv6 support in our CNI stack, we have plans to do so in the near future. IPv6 can make use of the IPvlan interface for both VPC traffic as well as Internet traffic, due to AWS’s use of public IPv6 addressing within VPCs and support for egress-only Internet Gateways. NAT and veth overhead will not be required for this traffic.
We’re planning to migrate to a VPC endpoint for DynamoDB and use native IPv6 support for communication to S3. Biasing toward extremely low overhead IPv6 traffic with higher overhead for IPv4 Internet traffic is the right future direction.
cni-ipvlan-vpc-k8s is used in production at Lyft with cri-o for
non-GPU workloads and Docker w/ nvidia-docker for GPU workloads.
Note that for cri-o, manage_network_ns_lifecycle must be set to
true.
By default, we use a secondary (and tertiary, ...) ENI adapter for all Pod networking. This allows isolation by security groups or other constraints on the Kubelet control plane. This requires that the hosts you are running on can attach at least two ENI adapters. See: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html Most hosts support > 1 adapter, except for some of the smallest hardware types.
AWS VPC with a recommended minimum number of subnets equal to the maximum number of attached ENIs. In the normal case of supporting up to the default 110 Pods per instance, you'll want five subnets (one for the control plane on the boot ENI and four subnets for the Pod ENIs). The example configuration uses adapter index 1 onward for Pods. We recommend creating a secondary IPv4 CIDR block for Kubernetes deployments within existing VPCs and subnet appropriately for the number of ENIs. In our primary region, we divide up our secondary IPv4 CIDR (/16) into 5 /20s per AZ with 3 AZs. Datadog has provided code which removes the restriction on one subnet per ENI; however, we've yet to test it thoroughly at Lyft.
(Optional) AWS subnets tagged if you want to limit which ones can be used.
The kubelet process must be started with the --node-ip option
if you also use --cloud-provider=aws. Use the primary IP on
the boot ENI adapter (eth0).
AWS permissions allowing at least these actions on the Kubelet role:
"ec2:DescribeSubnets"
"ec2:AttachNetworkInterface"
"ec2:AssignPrivateIpAddresses"
"ec2:UnassignPrivateIpAddresses"
"ec2:CreateNetworkInterface"
"ec2:DescribeNetworkInterfaces"
"ec2:DetachNetworkInterface"
"ec2:DeleteNetworkInterface"
"ec2:ModifyNetworkInterfaceAttribute"
"ec2:DescribeInstanceTypes"
"ec2:DescribeVpcs"
"ec2:DescribeVpcPeeringConnections"ec2:DescribeVpcs is required for m5 and c5 instances because the AWS metadata server does not return the secondary CIDR block on these instance types. This requirement will be removed when the issue is fixed.
ec2:DescribeVpcPeeringConnections is only required if routeToVpcPeers is enabled on the plugin.
See Security Considerations below for more on the implications of these permissions.
cni-ipvlan-vpc-k8s requires dep for dependency management. Please see
https://github.com/golang/dep#setup for build instructions. In a
pinch, you may go get -u github.com/golang/dep/cmd/dep.
go get github.com/lyft/cni-ipvlan-vpc-k8s
cd $GOPATH/src/github.com/lyft/cni-ipvlan-vpc-k8s
make buildThis example CNI conflist creates Pod IPs on the secondary and above
ENI adapters and chains with the upstream ipvlan plugin (0.7.0 or
later required) and the cni-ipvlan-vpc-k8s-unnumbered-ptp plugin to
create unnumbered point-to-point links back to the default namespace
from each Pod. New interfaces will be attached to subnets tagged with
kubernetes_kubelet = true, and created with the defined security
groups.
Routes are automatically formed for the VPC on the ipvlan adapter.
ipMasq is enabled to use the host-IP for egress to the Internet as
well as providing access to services such as kube2iam. kube2iam is
not a dependency of this software.
{
"cniVersion": "0.3.1",
"name": "cni-ipvlan-vpc-k8s",
"plugins": [
{
"cniVersion": "0.3.1",
"type": "cni-ipvlan-vpc-k8s-ipam",
"interfaceIndex": 1,
"subnetTags": {
"kubernetes_kubelet": "true"
},
"secGroupIds": [
"sg-1234",
"sg-5678"
]
},
{
"cniVersion": "0.3.1",
"type": "cni-ipvlan-vpc-k8s-ipvlan",
"mode": "l2"
},
{
"cniVersion": "0.3.1",
"type": "cni-ipvlan-vpc-k8s-unnumbered-ptp",
"hostInterface": "eth0",
"containerInterface": "eth1",
"ipMasq": true
}
]
}In the above cni-ipvlan-vpc-k8s-ipam config, several options are
available:
interfaceIndex: We also recommend never using the boot ENI
adapter with this plugin (though it is possible). By setting
interfaceIndex to 1, the plugin will only allocate IPs (and add
new adapters) starting at eth1.subnetTags: When allocating new adapters, by default the plugin
will use all available subnets within the availability zone. You
can restrict which subnets the plugin will use by specifying key /
value tag names that must be matched in order for the plugin to be
considered. These tags are set via the AWS API or in the AWS
Console on the subnet object.secGroupIds: When allocating a new ENI adapter, these interface
groups will be assigned to the adapter. Specify the sg-xxxx
interface group ID.skipDeallocation: true or false - when set to true, this
plugin will never remove a secondary IP address from an
adapter. Useful in workloads that churn many pods to reduce the AWS
ratelimits for configuring the VPC (which are low and cannot be
raised above a certain threshold). routeToVpcPeers: true or false - When set to true, the
plugin will make a (cached) call to暂无开放 Issues,或尚未同步最近议题。