One Project to get you hired as DevOps Engineer

HarshHarsh
5 min read

In the world of DevOps, practical knowledge of cloud platforms, automation, and Kubernetes orchestration is crucial. In this project, we will deploy an API in Amazon Elastic Kubernetes Service (EKS) using AWS resources. This blog will walk you through the requirements and steps needed to create an API, containerize it, push it to Amazon Elastic Container Registry (ECR), and deploy it in an EKS cluster. We'll also integrate Kubernetes ConfigMaps, Secrets, and explore optional features like autoscaling and using AWS Secrets Manager for database credentials. Let’s dive in!
It has been divided into three parts for ease of understanding.

Requirements

  1. Cloud Account: We will use AWS, specifically an AWS free-tier account or AWS Sandbox from A Cloud Guru (ACG).

  2. Terraform: To automate infrastructure setup, we will use Terraform scripts to create and manage our EKS cluster.

  3. kubectl: The command-line tool for interacting with the Kubernetes cluster.

  4. Programming Language: We will create a simple API (using Python FastAPI or Node.js).

  5. AWS ECR: This will serve as our Docker container registry to store the API image.


Part 1

Step 1: Setting Up the EKS and ECR Cluster

The first step is to set up your EKS cluster using Terraform. AWS EKS simplifies Kubernetes management, while Terraform allows you to declare infrastructure as code.

  • Use Terraform’s aws_eks module to create the cluster, worker node groups, and required IAM roles.

  • Specify the VPC, subnets, and security groups for EKS.

  • Once the EKS cluster is provisioned, configure kubectl to interact with it by updating your kubeconfig file using the AWS CLI.

  • Also setup aws_ecr using modules where we will push the image of our api

These steps can be challenging and will solidify your concepts about networking components and services. So, be patient and follow the next blog where I will share the solution.


Step 2: Create the API

You can choose any programming language to create the API. For this example, we'll use Python's FastAPI:

  1. FastAPI Setup: Create a simple FastAPI application that has an endpoint / to return a message along with values fetched from a ConfigMap and Secrets in Kubernetes.

  2. Dockerize the API: Write a Dockerfile to containerize the FastAPI app. The Dockerfile should copy your code, install dependencies, and run the application.


Step 3: Push the Docker Image to AWS ECR

Once the API is containerized, push the Docker image to AWS ECR.

  • First, create a new repository in ECR.

  • Authenticate Docker to ECR and push your container

You can just copy the commands from the repository itself.


Step 4: Deploy API to EKS

Now that the image is in ECR, deploy it in your EKS cluster.

  1. Create a Namespace (Optional, can use default): Start by creating a new Kubernetes namespace where your API will run:

  2. Create a ConfigMap and Secret: Kubernetes ConfigMaps and Secrets allow you to decouple configuration and sensitive information from your code. Create a ConfigMap and a Secret:

    • ConfigMap: Store non-sensitive configuration data.

    • Secrets: Store sensitive information like API keys.

Apply them using YAML files and retrieve their values in your FastAPI code.

  1. Deploy Your API: Write a Kubernetes Deployment YAML that pulls your image from ECR and creates the necessary pods. Make sure the pods are in the namespace you created earlier.

  2. Expose the API: Use a Service of type LoadBalancer/NodePort to expose the API to the outside world. This will provide an external IP that can be accessed from a browser:


Part 2

If you've completed the basic tasks, try enhancing the API deployment with the following optional activities to deepen your experience:

  1. Expose API Using Ingress: Instead of using a LoadBalancer service, configure Kubernetes Ingress to route traffic. This is the most crucial part and you will need to study about ingress, it’s use case and multiple components that get’s created, ingress-controller configuration. You can find a yaml configuration from GitHub and directly apply it but understanding is important.

  2. View Logs with kubectl: Implement basic logging in your API and retrieve logs using kubectl logs.

  3. Configure Liveness and Readiness Probes: Define these probes in your Deployment YAML to ensure that your application is running correctly and is ready to handle traffic.

  4. Horizontal Pod Autoscaling (HPA): Configure HPA to automatically scale the number of pods based on CPU utilization.

  5. Resource Requests and Limits: Set requests and limits for CPU and memory to ensure your containers run efficiently.


Part 3

Now, let’s take it up a notch by deploying a full-stack application on the EKS cluster.

  1. Frontend, Backend, and RDS: The backend (Node.js or Python API) will connect to an RDS instance (PostgreSQL). The frontend (React or Angular) will interact with the backend API.

  2. CI/CD Pipeline: Use GitLab CI/CD to automate the build and deployment process. Define a .gitlab-ci.yml file to build Docker images, push them to ECR, and deploy to EKS automatically.

  3. S3 Backup of RDS: Automate regular backups of your RDS database to an S3 bucket for durability.

  4. Grafana for Logs: Set up Grafana to monitor logs and visualize performance metrics for your application.

  5. Secrets Manager: Fetch sensitive information like database credentials from AWS Secrets Manager in your backend code for better security.


Conclusion

This project showcases your ability to handle a complete DevOps workflow—from setting up infrastructure to deploying a scalable application on EKS. You’ll not only demonstrate your Kubernetes knowledge but also how to integrate AWS services effectively. Tackling the optional activities will further strengthen your DevOps skill set and prepare you for real-world challenges.

Good luck, and happy deploying!

0
Subscribe to my newsletter

Read articles from Harsh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Harsh
Harsh

Technology and Problem Solving motivates me. Code and Computer Science is what I Practice. Portfolio: https://portfolio-harshumpoxy.vercel.app/