Introduction
Containerization has revolutionized the way we deploy applications, providing a lightweight, portable, and efficient way to package software. AWS offers two powerful container orchestration services: Elastic Container Service (ECS) and Elastic Container Service for Kubernetes(EKS). In this guide, we'll walk through the process of deploying a docker image using ECS and a game application using EKS. Without wasting much time, let's dive in to today's project.
Part 1: Deploying A Docker Image Using ECS
Step 1: Create an ECS Cluster
- Login to your AWS Management Console
- Search for ECS and click on it
- Click on cluster by your left
- Click on create cluster
- Name your cluster
- Click on create
- After creating the cluster, click on ECR by your left ( open it in a new tab)
- Click on get started
- Click on repositories by your left
- click on create repository and create
- Open your terminal (preferably, using AWS CLI)
- Clone or fork this GitHub repo GitHub, then click on command.md
- Copy the login command from command.md
- paste it on your terminal -Remove.dkr.ecr.amazonaws.com
- Go to the repository you created in your AWS
- Copy the repo URL and paste it where you remove those things, and put your AWS region where you see region close to /docker
- Go back to the GitHub and copy the command for build docker image from command.md and paste it in your terminal
- Remove.dkr.ecr.amazonaws.com and replace it with your repo URL.
- Go back to the GitHub and copy the push image command, and paste it in your terminal
- Remove the.dkr.ecr.amazonaws.com and replace it with your repo URL. Remove the dot (.) by the end of latest then hit enter
- After creating and pushing, go back to your ECR, click on task definition by your left
- Click on create task definition
- Name the task
- Scroll down to memory and reduce it (optional though)
- Scroll down to task execution role
- Click the drop-down button and select create new role (because we want to integrate cloud watch)
- Scroll down to container details
- Name the container
- Paste your repo URL in image URL at the end of the URL, put :latest
- Put your port number under container port
- Choose http under app protocol
- Click on create
- After creating the task definition, click on it to see if it is active
- If it is active, click on deploy drop down above and select run task
- Under existing cluster put your cluster
- Then click on create
Part 2: Deploying 2048 Game Application Using EKS
Step 1: Install EKSCTL
- Before installing EKSCTL, ensure you have AWS CLI installed and configured in your laptop
- After installing your EKSCTL, open it and create cluster
- Here is the command for your Cluster creation Cluster. Behind --name, remove demo-cluster and put the name of what you want to name your cluster. Where you see region, remove US-east-1 and put your region then hit enter
- Go to your AWS, search for cluster, you will see your cluster
Note: Using EKSCTL to create cluster is very fast because it will create everything including network automatically
- Go to your AWS Management Console and search for EKS, and click on it
- You will see your cluster you just created
- Go back to your EKSCTL and type aws eks update-kubeconfig--name your cluster name--region your region, then hit enter
- Now let's deploy our app
- Go to the GitHub
- Click on 2048-app-deploy
- Copy everything under create fargate profile
- Paste it in your EKSCTL
- Change the region to your region and the cluster name hit enter
- Go to your cluster in your AWS, scroll down to fargate profile to see if the fargate profile you created is there
- Cluster and fargate created
- Go to the GitHub, and click on 2048-app
- Copy deploy the deployment URL
- Paste it in your EKSCTL enter ( this is to deploy ingress)
- Type kubectl get pods -n game-2048 -w enter (to see if the ingress has been created)
- Type kubectl get svc -n gameb-2048 enter (to see if the service is running)
- Type kubectl get ingress -n game-2048 enter
- Now let's create ingress controller
- Go to GitHub
- Click on configure oidc connector.md
- Copy the command to configure IAM OIDC PROVIDER (eksctl utils associate)
- Paste it in your EKSCTL terminal. Change the cluster name to your cluster name
- Go to here GitHub
- Click on alb controller and copy the command for download IAM policy
- Paste it in your EKSCTL terminal enter
- Go back to the alb controller in the GitHub, cpy the create IAM Role command
- Paste it in your EKSCTL terminal
- Where you see put your AWS account ID there. Put your cluster name where you see cluster name
- Copy the helm command from alb controller too
- paste it in your EKSCTL terminal
- Go to your cluster in your AWS
- Click on network
- Copy the VPC info
- Go back to your EKSCTL terminal, remove the VPC id you see and paste yours
- Put your region
- Put your cluster name enter
- Go to your AWS cluster, click on network and you will see your VPC created
- Type kubectl get deployment -n kube-system aws-loadbalancer-controller
- Type kubectl get deployment -n kube-system aws-loadbalancer-controller -w enter
- Type kubectl get pods -n kube-system -w enter (to see your cluster pods)
- After confirming it everything is ok, go to your AWS Management Console
- Search for EC2
- Click on instance
- Click on load balancer and see if load balancer has been created
- Copy the URL (k8s-game2048-ingress....)
- Go to your browser, type http and paste the copied URL
- This is the end result
Note: Ensure you have kubectl and AWS CLI installed on your laptop
See you soon 😊
Top comments (0)