DevOps on E-commerce Project: Step-by-Step Implementation Using AWS, Docker, Terraform, and Kubernetes
Raghavender Chari
I specialize in empowering businesses to achieve exponential growth through Digital Marketing ( SEO, Google, Meta & Linkedin Ads ) | Generated 80K to 600K organic impressions in 6 months & achieved 10X revenue growth
Introduction
In this newsletter series, I will walk you through a complete DevOps implementation for an e-commerce project. We will use AWS, Docker, Terraform, Kubernetes, Ingress, GitHub Actions, and ArgoCD to build and deploy the project in a fully automated way.
Step 1: Create an AWS Account
If you don’t have an AWS account, sign up at AWS Console.
Step 2: Create an IAM User with Required Permissions
Step 3: Create an EC2 Instance
ssh -i your-key.pem ec2-user@your-ec2-public-ip
Step 4: Install Docker, Kubectl, and Terraform on EC2
Install Docker
sudo yum update -y
sudo yum install docker -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker $USER
Install Kubectl
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
chmod +x kubectl
sudo mv kubectl /usr/local/bin/
kubectl version --client
Install Terraform
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum install -y terraform
terraform -version
Step 5: Run the Project in EC2
Clone the project from GitHub:
git clone https://github.com/your-repo.git
cd your-repo
Run the application:
docker-compose up -d
Step 6: Containerize the Microservices Using Docker
Initialize Docker
Inside your project directory,
docker init
Create a Dockerfile for Each Microservice
Example Dockerfile: dockerfile:
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["npm", "start"]
Build and Push Docker Images to AWS ECR
Authenticate to AWS ECR:
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com
Build and tag the image:
docker build -t ecommerce-service .
docker tag ecommerce-service:latest <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/ecommerce-service:latest
Push the image:
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/ecommerce-service:latest
Step 7: Configure Terraform to Create AWS Resources
Setup Remote Backend (S3 & DynamoDB)
Example terraform/backend.tf:
terraform {
backend "s3" {
bucket = "terraform-state-bucket"
key = "devops-project/terraform.tfstate"
region = "us-east-1"
dynamodb_table = "terraform-lock"
}
}
Define VPC & EKS Cluster
Example terraform/main.tf:
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
name = "ecommerce-vpc"
cidr = "10.0.0.0/16"
}
module "eks" {
source = "terraform-aws-modules/eks/aws"
cluster_name = "ecommerce-cluster"
cluster_version = "1.27"
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.private_subnets
}
Apply Terraform
terraform init
terraform apply -auto-approve
Step 8: Deploy Microservices on Kubernetes
Create Deployment and Service Files
deployment.yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: ecommerce-service
spec:
replicas: 2
selector:
matchLabels:
app: ecommerce
template:
metadata:
labels:
app: ecommerce
spec:
containers:
- name: ecommerce
image: <AWS_ACCOUNT_ID>.dkr.ecr.us-east-1.amazonaws.com/ecommerce-service:latest
ports:
- containerPort: 3000
service.yaml:
apiVersion: v1
kind: Service
metadata:
name: ecommerce-service
spec:
selector:
app: ecommerce
ports:
- protocol: TCP
port: 80
targetPort: 3000
type: LoadBalancer
Deploy to Kubernetes
kubectl apply -f deployment.yaml
kubectl apply -f service.yaml
kubectl get pods
Step 9: Deploy ALB Ingress Controller
helm repo add eks https://aws.github.io/eks-charts
helm install aws-load-balancer-controller eks/aws-load-balancer-controller \
--set clusterName=ecommerce-cluster
Step 10: Custom Domain Configuration
Example ingress.yaml:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ecommerce-ingress
spec:
rules:
- host: ecommerce.example.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: ecommerce-service
port:
number: 80
kubectl apply -f ingress.yaml
Step 11: Implement CI/CD with GitHub Actions & ArgoCD
Setup GitHub Actions
Example .github/workflows/deploy.yml:
name: CI/CD Pipeline
on:
push:
branches:
- main
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Build and Push Docker Image
run: |
docker build -t ecommerce-service .
docker push <AWS_ACCOUNT_ID>.dkr.ecr.us-east1.amazonaws.com/ecommerce-service:latest
Deploy Using ArgoCD
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
This completes the end-to-end DevOps setup for the e-commerce project! ??
This project involves a wide range of DevOps and Cloud Engineering skills across multiple domains. Here's a breakdown of the key skills we utilized:
1. Cloud Computing (AWS)
2. Infrastructure as Code (IaC)
3. Containerization & Orchestration
4. Networking & Security
5. CI/CD (Continuous Integration & Continuous Deployment)
6. Domain & DNS Management
7. Monitoring & Logging (Optional but Recommended)
8. Linux & Command Line
9. Version Control & Collaboration
Summary of Key Skills Used
? AWS (EC2, S3, IAM, EKS, Route 53, ALB, ECR, DynamoDB)
? Terraform (Infrastructure as Code - IaC)
? Docker & Kubernetes (Containerization & Orchestration)
? CI/CD (GitHub Actions & ArgoCD)
? Networking & Security (VPC, Load Balancer, Ingress Controller, IAM)
? Custom Domain Configuration (Route 53 & DNS Management)
? Linux & Shell Scripting
? Version Control (Git & GitHub)
Would you like to add any monitoring/logging tools to enhance observability? ??
#devops #docker #kubernetes #aws #ingress #github #argocd