Running Flannel on EKS

Jeremy Cowan
5 min readFeb 9, 2019

--

The Elastic Container Service for Kubernetes (EKS) is a managed service from AWS that was launched in 2018. As part of the service, AWS manages the Kubernetes control plane which consists of a set of masters nodes and an etcd database. When you provision a cluster, it comes pre-configured with the AWS VPC Container Networking Interface (CNI) plugin, a Kubernetes networking plugin that assigns IP addresses from your Virtual Private Cloud (VPC) to pods. Using this plugin has several advantages. First, you don’t incur the overhead of encapsulation and de-encapsulation as you do with overlay networks. Second, you can use VPC Flow Logs to capture information about the IP traffic going to and from the pods in your cluster. Third, there’s less contention for network bandwidth because fewer pods are sharing an Elastic Network Interface (ENI). And finally, traffic from the VPC can be directly routed to pods. The VPC CNI plugin has its own set of challenges, however. For example, the EC2 instance type and size determines number of pods you can run on an instance. And there are instances where attaining higher pod density will force you to over-provision the instance types you use for your worker nodes. Your VPC may also be so IP constrained that you cannot afford to assign IP address from your VPC to your pods, though the VPC CNI custom networking feature attempts to address this by allowing you to specify a separate set of subnets for your pod network.

Despite the VPC CNI’s advantages, folks may still want to use another CNI with EKS. This post explains how to install and configure the flannel CNI with EKS.

Installing flannel

The first step is to create an EKS cluster. I recommend using eksctl because it lets you to provision a cluster (and workers nodes) by issuing a single command.

When you create an EKS cluster, a daemonset for the VPC CNI plugin, called aws-node, is automatically created. As worker nodes are joined to the cluster, the Kubernetnes scheduler will schedule an instance of this daemon onto each node. This alters the route table on the instance, affecting its ability to support other network plugins like Flannel. Creating a node-less cluster will allow you to replace the aws-node daemonset with a different networking plugin before nodes are joined to the cluster.

The next step is to delete the aws-node daemonset.

Since EKS doesn’t allow you to set the pod CIDR on the API server, we’re going to use an external etcd database to store the network configuration for flannel. To get started with etcd, we first need to install CoreOS’s config transpiler(ct).

Next, we want to get a token for our single node etcd “cluster”.

Execute the following command to create a file named etcd.yaml

Run the following command to convert the etcd.yaml file into an ignition configuration. The output will be used to configure CoreOS when it first boots.

Launch an instance of CoreOS-stable-1967.4.0. When running this command, replace key_name, sg_ids, and subnet_id with values that correspond to the appropriate resources within your AWS environment.

By adding the etcd instance to the worker node security group , you can avoid creating additional security group rules to allow the flannel daemon to read data from your etcd database.

After the instance is in a running state, SSH to the instance and execute the following commands:

Logout of etcd and install the flannel CNI. Before running the next command replace <etcd_ip> with the IP address of your etcd server.

Open the EC2 console and increase the desired and maximum count for the autoscaling group that eksctl created for your worker nodes.

Testing

Now that you’ve finished configuring flannel, let’s deploy some nginx pods.

Verify pods are getting created in the CIDR range that you configured.

If you followed all the steps correctly, the IPs of your pods should be in the range you configured.

Conclusion

The VPC CNI plugin from AWS provides robust networking for Kubernetes pods. Nonetheless, there are situations where using an alternate CNI may be preferable. While this blog outlined the steps to install the flannel CNI on EKS, a similar approach can be used to install other CNIs such as Calico or Cilium.

--

--

Jeremy Cowan

Jeremy Cowan is a Principal Container Specialist at AWS