How do I use Amazon EKS with Amazon ElastiCache?
In this guide, we will create an Amazon Elastic Kubernetes Service (EKS) cluster and an Amazon ElastiCache cluster, then configure them to work together. EKS is a managed Kubernetes service, while ElastiCache is a caching service that improves application performance. We will start by creating an EKS cluster, followed by an ElastiCache cluster, and finally linking both.
Detailed Steps
We’ll begin with setting up the necessary resources:
- Amazon VPC: A Virtual Private Cloud where our EKS and ElastiCache will reside.
- Amazon EKS Cluster: The Kubernetes cluster where applications will run.
- Amazon ElastiCache Cluster: A managed cache cluster that will support our applications in the EKS cluster.
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
// Create a VPC
const main = new aws.ec2.Vpc("main", {cidrBlock: "10.0.0.0/16"});
// Create Internet Gateway
const igw = new aws.ec2.InternetGateway("igw", {vpcId: main.id});
// Create subnets
const subnet1 = new aws.ec2.Subnet("subnet1", {
vpcId: main.id,
cidrBlock: "10.0.1.0/24",
availabilityZone: "us-west-2a",
});
const subnet2 = new aws.ec2.Subnet("subnet2", {
vpcId: main.id,
cidrBlock: "10.0.2.0/24",
availabilityZone: "us-west-2b",
});
// EKS Cluster role
const eksRole = new aws.iam.Role("eks_role", {
name: "eks-role",
assumeRolePolicy: JSON.stringify({
Version: "2012-10-17",
Statement: [{
Effect: "Allow",
Principal: {
Service: "eks.amazonaws.com",
},
Action: "sts:AssumeRole",
}],
}),
});
const eksPolicy = new aws.iam.RolePolicyAttachment("eks_policy", {
role: eksRole.name,
policyArn: "arn:aws:iam::aws:policy/AmazonEKSClusterPolicy",
});
const eks = new aws.eks.Cluster("eks", {
name: "eks-cluster",
roleArn: eksRole.arn,
vpcConfig: {
subnetIds: [
subnet1.id,
subnet2.id,
],
},
});
// ElastiCache Subnet Group
const cacheSubnet = new aws.elasticache.SubnetGroup("cache_subnet", {
name: "cache-subnet-group",
subnetIds: [
subnet1.id,
subnet2.id,
],
});
// ElastiCache Cluster
const cache = new aws.elasticache.Cluster("cache", {
clusterId: "my-cache-cluster",
engine: "redis",
nodeType: "cache.t2.micro",
numCacheNodes: 1,
parameterGroupName: "default.redis3.2",
subnetGroupName: cacheSubnet.name,
});
export const eksClusterEndpoint = eks.endpoint;
export const elasticacheClusterEndpoint = cache.cacheNodes.apply(cacheNodes => cacheNodes[0].address);
Key Points:
- VPC and Subnets: The foundational network setup needed for both EKS and ElastiCache resources.
- EKS Cluster: Created with a role that specifies the permissions needed for EKS to interact with AWS resources.
- ElastiCache Cluster: Provisioned within the same VPC as the EKS cluster ensuring network connectivity.
- Outputs: The endpoints for the EKS cluster and the ElastiCache cluster are exported for connectivity purposes.
Summary
We created an integrated AWS setup comprising an EKS cluster and an ElastiCache cluster within a VPC. This configuration allows applications running on EKS to utilize the caching capabilities of ElastiCache, enhancing performance and scalability.
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.