Skip to main content
Chat with me

Deploy a Dockerized Express App on AWS EKS


Hey Dev Fam,

So, you've got another cool Express.js app huh? and now you're thinking, "How can I make it play nice with AWS EKS?" Fear not, I’ve got you covered with a laid-back, step-by-step guide.

Intro 👋

Amazon Elastic Kubernetes Service (EKS) provides a scalable and managed Kubernetes environment that simplifies the deployment and operation of containerized applications. In this article, I’ll walk through the process of deploying a Dockerized Express.js application on AWS EKS. This guide assumes you have a basic understanding of Docker, Kubernetes, and AWS services.

Prerequisites 📋

  1. AWS Account: Ensure you have an AWS account and an IAM user with the necessary permissions to create and manage EKS clusters, EC2, CloudFormation and VPC.
  2. Docker: Have Docker installed on your local machine to containerize the Express.js app.
  3. AWS CLI and EKSCTL: Install the AWS CLI and EKSCTL to interact with AWS services and Kubernetes clusters.

Step 1: Dockerize the Express.js App 🐳

First off, let's get this party started by containerizing your Express.js app. Create a Dockerfile in your project directory:

# Use an official Node.js runtime as a parent image
FROM node:18-alpine

# Set the working directory to /app

# Copy only necessary files to the working directory
COPY package.json yarn.lock ./
COPY src ./src

# Install app dependencies
RUN yarn install --production

# Expose the port where our app meant to run

# Defining the environment variables
ENV NODE_ENV=production

# Use a non-root user for better security
USER monkey

# Specify the command to run on startup
CMD ["node", "src/index.js"]

Build the Docker image:

docker build -t .

Step 2: Push the Docker Image to GitHub Packages 🚀

Github has a fully managed container registry that makes it easy to store, manage, and deploy Docker container images.

  1. Heads up to the Github settings and generate a classic personal access token with full access to the packages. You can follow this guid.

  2. Authorize Docker to your GitHub Account:

docker login --username your-username --password your-gh-access-token
  1. Push the Docker image:
docker push
  1. Open up the Packages tab on Github and make that package public. Otherwise you’ll need to define an access token in deployment config.

Step 3: Create an Amazon EKS Cluster 🤩

Assuming you have correctly configured the awscli with a correct IAM user and installed eksctl.

  1. Run the following command in your terminal with appropriate options. More info about the eksctl options can be found here.
eksctl create cluster --name my-first-cluster --region us-east-2

Hang tight, It can take some time as it needs to setup VPC, CloudFormation etc.

Step 4: Configure kubectl for the EKS Cluster ⚙️

After the cluster is created, configure kubectl to use it:

aws eks update-kubeconfig --name my-first-cluster --region us-east-2

Step 5: Deploy the App 🕺

Before deployment, you’ll need to create 2 config files to setup Kubernetes.

  1. Create a Kubernetes deployment YAML file (e.g., deployment.yaml):
apiVersion: apps/v1
kind: Deployment
  name: my-express-app
  replicas: 2
      app: my-express-app
        app: my-express-app
        - name: my-express-app
            - containerPort: 5000
  1. Create a service.yaml file that will manage the ports etc:
apiVersion: v1
kind: Service
  name: my-express-service
    app: my-express-app
    - protocol: TCP
      port: 80
      targetPort: 5000
  type: LoadBalancer
  1. Apply the deployment:
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml

Step 6: Access the App 🤘

Once the deployment is complete, copy the external IP address of the LoadBalancer service:

kubectl get svc express-app

Open a browser, punch in that IP, and behold your Express.js app, now grooving on AWS EKS with GitHub Packages!

Bonus 😌

You can use the following command to delete the cluster and linked services completely:

eksctl delete cluster --name my-first-cluster

Following this guide will help you successfully run your Express.js app on a scalable and managed Kubernetes environment provided by AWS EKS.

Rock on! 🚀✨