Heading image

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

Prerequisites

  1. Basic familiarity with AWS CDK for TypeScript.
  2. Familiarity with Kubernetes.

Getting started

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

In 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 8080.

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

The 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 kubectl config.

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:

Summary

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

  1. AWS CDK for TypeScript
  2. Project code
  3. Kubernetes
  4. EKS Application Load Balancer Ingress Controller for Fargate

Photo credit: picsbyjameslee

Originally posted on my blog. To see new posts without delay, read the posts there and subscribe to my newsletter.

I write content for AWS, Kubernetes, Python, JavaScript and more. To view all the latest content, be sure to visit my blog and subscribe to my newsletter. Follow me on Twitter.

Senior Engineer @ UsabilityHub. Formerly Culture Amp.