1. Answers
  2. Amazon EKS and ElastiCache Integration Guide

How Do I Use Amazon EKS With Amazon ElastiCache?

Introduction

This guide provides a comprehensive walkthrough on integrating Amazon Elastic Kubernetes Service (EKS) with Amazon ElastiCache. The purpose of this guide is to help you set up a managed Kubernetes service using EKS and enhance your application’s performance with the caching capabilities of ElastiCache. By following the steps outlined, you’ll create an EKS cluster, set up an ElastiCache cluster, and configure them to work in tandem.

Detailed Steps

Follow these steps to set up the necessary resources:

  1. Amazon VPC: Create a Virtual Private Cloud where both EKS and ElastiCache will reside.
  2. Amazon EKS Cluster: Set up the Kubernetes cluster to run your applications.
  3. Amazon ElastiCache Cluster: Establish a managed cache cluster to support your 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: Establish the foundational network setup for both EKS and ElastiCache resources.
  • EKS Cluster: Created with a role specifying permissions for EKS to interact with AWS resources.
  • ElastiCache Cluster: Deployed within the same VPC as the EKS cluster to ensure network connectivity.
  • Outputs: The endpoints for the EKS cluster and the ElastiCache cluster are exported for connectivity purposes.

Summary

In this guide, we successfully set up an integrated AWS environment comprising an EKS cluster and an ElastiCache cluster within a VPC. This configuration allows applications running on EKS to leverage the caching capabilities of ElastiCache, thus boosting performance and scalability. By following these steps, you can efficiently manage and scale your applications on AWS.

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up