Deploying An EKS Fargate Cluster With The AWS CDK (Part 1)
This post will demonstrate how we can deploy a Fargate on EKS Kubernetes cluster to run a simple application. Part one will focus on deploying the Kubernetes cluster with a running pod, but will not include the load balancer for the application.
This post will not be covering the basics of Kubernetes. If you want to learn more about that, I will be writing more on Kubernetes in upcoming posts.
Source code for this blog post can be found here
We will clone the template repo to get started:
At this stage, we will have the app in a basic working state.
In order to create the CDN stack, we will require the following AWS CDK libraries:
We can install these prior to doing any work:
The repository that we cloned already has a
upgrade script supplied. We can use this to ensure our CDK packages are at parity:
We are now at a stage add a pattern construct to a stack.
Updating our stack for the Fargate on EKS cluster
lib/aws-cdk-with-typescript-foundations-stack.ts, update to add the following code:
This code will create a fargate cluster and deploy a pod
mypod with a container
amazon/amazon-ecs-sample running on port
We will check to ensure the pod runs, but we will not be exposing it through a load balancer in this blog post.
Deploying the cluster
Outputs log will contain a command to use to update the kubeconfig file.
In our case, this is
aws eks update-kubeconfig --name fargate-demo --region us-east-1 --role-arn arn:aws:iam::123:role/AwsCdkWithTypescriptFound-HelloEKSMastersRole53742-123. Run that command to set up your
Checking the pod deployment
We can check the pod has deploy as expected by running the
kubectl get all or
kubectl get pods command:
In the above example, you can see that the pod is running on our Fargate on EKS cluster. Success!
At the time of writing, you will need to do more work to add a LoadBalancer with Fargate on EKS.
Destroying the cluster
EKS can be very expensive - be sure to tear down the cluster when you are done with this demo:
Today's post demonstrated how to deploy a Fargate on EKS cluster using the AWS CDK along with a pod and container.
Following posts will demonstrate how to add a load balancer.
Resources and further reading
- aws cdk
- aws lambda
Deploy a simple Python lambda function with the TypeScript AWS CDK to LocalStack.
Use the ECS patterns library to deploy a simple Fargate cluster to LocalStack.
- aws cdk
Use the TypeScript AWS CDK to deploy an S3 Bucket fronted by a CloudFront CDN and Route53 record.
1,200+ PEOPLE ALREADY JOINED ❤️️
Get fresh posts + news direct to your inbox.
No spam. We only send you relevant content.