DevOps on E-commerce Project: Step-by-Step Implementation Using AWS, Docker, Terraform, and Kubernetes

DevOps on E-commerce Project: Step-by-Step Implementation Using AWS, Docker, Terraform, and Kubernetes

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

  1. Go to AWS IAM (Identity and Access Management).
  2. Create a new user with programmatic access.
  3. Assign the following policies:
  4. Save the Access Key ID and Secret Access Key for later use.

Step 3: Create an EC2 Instance

  1. Launch an EC2 instance (Amazon Linux 2 or Ubuntu).
  2. Choose an instance type (e.g., t2.medium or higher).
  3. Allow inbound traffic for SSH, HTTP, and HTTPS in the security group.
  4. Connect via SSH:

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)

  1. Create an S3 bucket for state storage.
  2. Create a DynamoDB table for state locking.

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

  1. Buy a domain from Route 53.
  2. Create a hosted zone and update nameservers.
  3. Configure ingress with hostname.

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)

  • EC2 – Launching virtual machines for hosting applications.
  • IAM – Managing access and permissions securely.
  • S3 – Storing Terraform state files.
  • DynamoDB – Implementing state locking in Terraform.
  • EKS – Deploying and managing Kubernetes clusters.
  • Route 53 – Configuring custom domains and DNS.
  • Elastic Load Balancer (ALB) – Load balancing traffic across microservices.
  • AWS ECR – Storing and managing Docker container images.


2. Infrastructure as Code (IaC)

  • Terraform – Automating AWS resource provisioning.


3. Containerization & Orchestration

  • Docker – Containerizing microservices.
  • Kubernetes – Deploying and managing microservices.
  • Helm – Installing and managing AWS ALB Ingress Controller.


4. Networking & Security

  • VPC Configuration – Setting up a private cloud network.
  • Ingress & Load Balancers – Managing external traffic flow.
  • IAM Roles & Policies – Ensuring secure access to AWS services.


5. CI/CD (Continuous Integration & Continuous Deployment)

  • GitHub Actions – Automating build, test, and deployment pipelines.
  • ArgoCD – Deploying applications using GitOps methodology.


6. Domain & DNS Management

  • Route 53 – Configuring custom domains and DNS records.
  • Ingress Controller – Mapping custom domains to Kubernetes services.


7. Monitoring & Logging (Optional but Recommended)

  • Prometheus & Grafana – Monitoring Kubernetes clusters (if implemented).
  • CloudWatch Logs – Logging AWS services and Kubernetes workloads.


8. Linux & Command Line

  • Installing Docker, Kubectl, and Terraform on EC2.
  • Running bash scripts to automate tasks.


9. Version Control & Collaboration

  • Git & GitHub – Managing source code and CI/CD workflows.


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



要查看或添加评论,请登录

Raghavender Chari的更多文章