How do I assign Elastic IP addresses to EKS Pods using VPC CNI?
To assign Elastic IP addresses to EKS Pods using the Amazon VPC CNI plugin, you need to configure the VPC CNI plugin to enable the use of secondary IP addresses on ENIs for pods. This setup allows pods to use IPs from the VPC subnet, which can be associated with Elastic IPs.
Below is a Pulumi program in TypeScript that demonstrates how to create an EKS cluster and configure the VPC CNI plugin to assign Elastic IPs to pods.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as eks from "@pulumi/eks";
// Create a VPC for our EKS cluster
const vpc = new aws.ec2.Vpc("vpc", {
cidrBlock: "10.0.0.0/16",
enableDnsHostnames: true,
enableDnsSupport: true,
});
// Create subnets for our VPC
const subnet = new aws.ec2.Subnet("subnet", {
vpcId: vpc.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
});
// Create an EKS cluster
const cluster = new eks.Cluster("eksCluster", {
vpcId: vpc.id,
subnetIds: [subnet.id],
instanceType: "t2.medium",
desiredCapacity: 2,
minSize: 1,
maxSize: 3,
vpcCniOptions: {
enablePodEni: true, // Enable the assignment of ENIs to pods
},
});
// Create an Elastic IP
const eip = new aws.ec2.Eip("eip", {
vpc: true,
});
// Associate the Elastic IP with the ENI of a pod
const eni = new aws.ec2.NetworkInterface("eni", {
subnetId: subnet.id,
privateIps: [eip.privateIp],
});
const eipAssociation = new aws.ec2.EipAssociation("eipAssociation", {
allocationId: eip.id,
networkInterfaceId: eni.id,
});
// Export the cluster's kubeconfig
export const kubeconfig = cluster.kubeconfig;
In this program, we:
- Create a VPC and a subnet.
- Create an EKS cluster with the VPC CNI plugin configured to enable the assignment of ENIs to pods.
- Create an Elastic IP and associate it with the ENI of a pod.
This setup ensures that pods within the EKS cluster can have Elastic IP addresses assigned to them, allowing for direct internet access and static IP allocation.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.