Skip to content

Instantly share code, notes, and snippets.

@akhan4u
Created May 1, 2025 12:48
Show Gist options
  • Save akhan4u/9c0cf394e535c9c03bc7815a2c0e0ba9 to your computer and use it in GitHub Desktop.
Save akhan4u/9c0cf394e535c9c03bc7815a2c0e0ba9 to your computer and use it in GitHub Desktop.
EKS & Terraform Exercises
# Exercise 1: EKS + ECR - Containerized Application Deployment
# Goal
Deploy a containerized application using Amazon EKS and manage container images with ECR.
# Steps
1. Containerize your application using Docker.
2. Push the Docker image to Amazon ECR.
3. Set up an Amazon EKS cluster.
4. Configure access from EKS to ECR.
5. Create Kubernetes deployment and service manifests referencing the ECR image.
6. Apply the manifests to test the application deployment on EKS.
# Outcome
A robust, scalable application running on Kubernetes, with images securely stored in ECR.
# ---------------------------------------------------------------------------------------------
# Exercise 2: AWS ECS + ECR + GitHub Actions
# Project Overview
# You'll build a continuous integration and deployment (CI/CD) pipeline that:
1. Containerizes Your Application: Utilize Docker to package your application into a container.
2. Stores the Container Image: Push the Docker image to AWS ECR, a fully managed container registry.
3. Deploys to AWS ECS: Automatically deploy the containerized application to AWS ECS, a scalable container orchestration service.
4. Automates with GitHub Actions: Set up GitHub Actions to automate the build, test, and deployment processes.
# Steps
1. Set Up AWS IAM User
• Create an IAM user with permissions to access ECR and ECS.
• Generate access keys for this user.
2. Create an ECR Repository
• Use the AWS Management Console or AWS CLI to create a new repository in ECR to store your Docker images.
3. Prepare Your Application
• Create a Dockerfile that defines the environment and specifies how to build your application into a Docker image.
4. Push Code to GitHub
• Initialize a Git repository in your project directory.
• Commit your application code and Dockerfile.
• Push the code to a new repository on GitHub.
5. Configure GitHub Secrets
• In your GitHub repository settings, add the AWS access key ID and secret access key as secrets
(e.g., AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY).
6. Set Up GitHub Actions Workflow
• In your repository, create a .github/workflows directory.
• Inside this directory, create a YAML file (e.g., deploy.yml) to define the CI/CD pipeline.
7. Define Workflow Steps
• Configure the workflow to trigger on code pushes to the main branch.
Add steps to -
• Check out the repository code.
• Log in to AWS using the configured secrets.
• Set up Docker.
• Build the Docker image.
• Push the Docker image to the ECR repository.
8. Create ECS Cluster and Task Definition
• In the AWS Management Console, create an ECS cluster.
• Define a task definition that specifies the Docker image from ECR and the necessary configurations (e.g., CPU, memory, port mappings).
9. Deploy Application via GitHub Actions
• Add a step in the GitHub Actions workflow to register and update the ECS task definition.
• Configure the workflow to deploy the updated task definition to the ECS service, ensuring the application runs with the latest Docker image.
10. Test the Deployment
• Obtain the public IP or DNS of the ECS service.
• Access the application through a web browser or API client to verify it’s running correctly.
# ---------------------------------------------------------------------------------------------
# Exercise 3: Practicing Terraform ⭐
# Goal
This project challenges you to provision AWS infrastructure using Terraform, while emphasizing modularity, remote state management, & automation.
# Steps
1. Create an S3 bucket and DynamoDB table to serve as the remote backend for Terraform state management
2. Set up dedicated AWS IAM credentials with least-privilege permissions specifically for Terraform
3. Develop Terraform configurations to deploy basic AWS infrastructure (VPC, subnets, and an EC2 instance)
4. Organize your Terraform code into modules by separating network, compute, and storage resources
5. Configure the Terraform backend in your project to use the S3 bucket and DynamoDB table for state locking and versioning
6. Utilize variables, outputs, and workspaces to manage multiple environments (e.g., dev, staging, production)
7. Run Terraform commands (terraform init, terraform plan, and terraform apply) to provision and validate your infrastructure
8. Verify the deployed resources via the AWS Console and by accessing the public IP of the EC2 instance
# Bonus
1. Integrate your Terraform project with a CI/CD pipeline (using GitHub Actions, GitLab CI/CD, or similar) to automate deployments
2. Enhance security by implementing strict IAM policies and continuously reviewing Terraform plan outputs
3. Implement resource tagging and cost monitoring configurations to manage and optimize cloud spending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment