Today, I will walk you through deploying the backend of an application using Kubernetes. This project starts from scratch—beginning with launching an EC2 instance and culminating in a fully deployed backend. By the end of this guide, we will have a scalable and containerized application running in an Amazon EKS cluster.
⚠ Important Cost Note: Amazon EKS is not part of the AWS Free Tier and costs $0.10 per hour while running. To minimize costs, I will ensure to delete my EKS cluster at the end of the project.
Step 1: Setting Up the EKS Cluster
To deploy with Kubernetes, the first step is setting up an EKS cluster. This cluster acts as the control center for managing Kubernetes workloads and orchestrating the containers for our backend application.
Installing Dependencies:
- eksctl: A command-line tool used to create and manage EKS clusters.
Creating the EKS Cluster:
Using eksctl
, I set up a new Kubernetes cluster:
2: Pulling Backend Code from GitHub
Next, I need access to my backend code, which is stored in a GitHub repository.
Installing Dependencies:
- Git: Required to clone the repository.
Cloning the Repository:
Cloning the repo provides a local copy of the backend code, which is crucial for building a container image that Kubernetes will deploy. It is best to clone instead of edit the original code to avoid mistakes.
Step 3: Building a Container Image with Docker
Since Kubernetes requires applications to be containerized, I need to build a Docker image for my backend.
Installing Dependencies:
- Docker: Needed to build and manage container images.
Building the Image:
This packages my backend application into a container image, making it portable and deployable.
Step 4: Pushing the Image to Amazon ECR
Now that I have a container image, I need to store it in a registry so Kubernetes can pull and deploy it.
Installing Dependencies:
- Amazon Elastic Container Registry (ECR): AWS service for managing container images.
Creating an ECR Repository:
Pushing the Image to ECR:
This step ensures my image is stored in ECR, allowing Kubernetes to pull and deploy it easily.
Step 5: Creating Kubernetes Manifest Files
To deploy my backend, I need to create Kubernetes manifests. These files provide instructions on how Kubernetes should deploy and expose my application.
Key Manifest Files:
Deployment Manifest (
deployment.yaml
):Manages container creation and rolling updates.
Specifies the container image location.
Service Manifest (
service.yaml
):Exposes the application via a LoadBalancer or NodePort.
Defines how users access the backend.
Step 6: Deploying the Application with kubectl
With the manifests ready, I can now deploy the application using kubectl
.
Installing Dependencies:
- kubectl: The CLI tool for managing Kubernetes resources.
Applying the Manifest Files:
This creates the necessary Kubernetes resources, allowing my backend to run and be accessible.
Step 7: Verifying Deployment
To ensure everything is running correctly, I checked my Kubernetes resources:
This confirms that my backend application is successfully deployed and accessible.
Conclusion
🎯 Technologies Used:
- Kubernetes, ECR, kubectl, Docker, eksctl, EC2, and GitHub.
⏳ Project Duration:
- This project took about 3 hours.
💡 Key Takeaways:
Most Challenging Part: Creating the Kubernetes manifests as it was a new experience for me.
Favorite Part: Gaining a deeper understanding of standard cloud deployment practices used in real-world companies.
🚀 Why I Did This:
- To gain hands-on experience with Kubernetes, Docker, EKS, and ECR—essential skills for mastering AWS and cloud computing.
Final Thoughts
Deploying an application with Kubernetes may seem complex at first, but breaking it down into structured steps makes the process more manageable. By automating deployments with Kubernetes, we ensure scalability, reliability, and efficiency in our cloud-based applications.
If you're looking to improve your cloud deployment skills, I highly recommend trying out a similar project. Feel free to reach out if you have any questions!