Skip to content

A fully automated DevOps pipeline for deploying an email breach checking service to Kubernetes using Docker, GitHub Actions, and Ansible.

License

Notifications You must be signed in to change notification settings

akash2061/K8s-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

K8s-Project: Automated Email Breach Checking Service

A fully automated DevOps pipeline for deploying an email breach checking service to Kubernetes using Docker, GitHub Actions, and Ansible.

CI/CD Pipeline

πŸš€ Project Overview

This project demonstrates a complete CI/CD pipeline that automatically builds, containerizes, and deploys a Next.js email breach checking application to a K3s cluster using modern DevOps practices.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GitHub    │───▢│ GitHub       │───▢│   Docker    │───▢│   K3s        β”‚
β”‚ Repository  β”‚    β”‚ Actions      β”‚    β”‚   Hub       β”‚    β”‚  Cluster     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚                                       β–²
                          β–Ό                                       β”‚
                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                   β”‚   Ansible    │───────────────────────▢│  Remote     β”‚
                   β”‚  Playbook    β”‚         SSH            β”‚  Server     β”‚
                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technology Stack

Frontend & Application

  • Next.js 14 - React framework with TypeScript
  • Tailwind CSS - Utility-first CSS framework
  • Lucide React - Beautiful icons
  • Theme Support - Light/Dark mode toggle

DevOps & Infrastructure

  • Docker - Containerization
  • Kubernetes (K3s) - Container orchestration
  • GitHub Actions - CI/CD pipeline
  • Ansible - Configuration management
  • Docker Hub - Container registry

Monitoring & Scaling

  • Horizontal Pod Autoscaler (HPA) - Auto-scaling based on CPU/Memory
  • Resource Limits - CPU and memory management
  • Health Checks - Readiness and liveness probes

πŸ“‹ Features

Application Features

  • βœ… Email breach checking functionality
  • βœ… Real-time breach status feedback
  • βœ… Responsive design
  • βœ… Dark/Light theme toggle
  • βœ… Clean, modern UI
  • βœ… Security-focused email analysis

DevOps Features

  • πŸ”„ Automated CI/CD Pipeline
  • 🐳 Docker containerization
  • ☸️ Kubernetes deployment
  • πŸ“Š Auto-scaling capabilities

πŸš€ Quick Start

Prerequisites

  • K3s cluster [light-weight] or Kubernetes cluster
  • Docker Hub account
  • GitHub repository with secrets configured
  • Ansible installed on the deployment machine

Required GitHub Secrets

DOCKER_USERNAME=my-dockerhub-username
DOCKER_PASSWORD=my-dockerhub-password
K3S_HOST=my-k3s-server-ip
K3S_USER=my-ssh-username
K3S_SSH_PRIVATE_KEY=my-ssh-private-key

Manual Deployment

  1. Clone the repository

    git clone https://github.com/akash2061/K8s-Project.git
    cd K8s-Project
  2. Build and push Docker image

    docker build -t akash2061/email-check:latest ./App
    docker push akash2061/email-check:latest
  3. Deploy using Ansible

    ansible-playbook -i ansible/inventory.yml ansible/deploy.yml \
      -e k3s_host=SERVER_IP \
      -e k3s_user=SSH_USER
  4. Access the application

    http://SERVER_IP:30080
    

πŸ”§ Configuration

Kubernetes Resources

Resource Configuration
Deployment 1 replica, rolling updates
Service NodePort (30080)
HPA 1-2 replicas, CPU: 20%, Memory: 50%
Resources Request: 250m CPU, 256Mi RAM
Limits 500m CPU, 512Mi RAM

CI/CD Pipeline

The pipeline consists of two main jobs:

  1. Build Job

    • Checkout code
    • Docker login
    • Build and push image to Docker Hub
  2. Deploy Job

    • Install Ansible
    • Setup SSH connectivity
    • Deploy to K3s using Ansible playbook

Ansible Deployment Strategy

  • Rolling updates for zero-downtime deployments
  • Smart deployment with change detection
  • Health checks to ensure successful deployment
  • Resource monitoring with HPA status verification

πŸ“Š Monitoring & Scaling

Auto-scaling Configuration

HPA Thresholds:
- CPU: 20% (Testing threshold)
- Memory: 50%
- Min Replicas: 1
- Max Replicas: 2

Health Monitoring

# Check deployment status
kubectl get pods -l app=email-check

# Monitor HPA
kubectl get hpa email-check-hpa

# View service
kubectl get svc email-check-service

πŸ›‘οΈ Security Features

  • Non-root containers - Security best practices
  • Resource limits - Prevent resource exhaustion
  • SSH key authentication - Secure server access
  • Private container registry - Controlled image distribution
  • Email breach detection - Core security functionality

πŸ“ Project Structure

K8s-Project/
β”œβ”€β”€ App/                          # Next.js email breach checking app
β”‚   β”œβ”€β”€ components/              # React components
β”‚   β”œβ”€β”€ app/                     # App router pages
β”‚   └── Dockerfile              # Container configuration
β”œβ”€β”€ k8s/
β”‚   └── k8s.yml                 # Kubernetes manifests
β”œβ”€β”€ ansible/
β”‚   β”œβ”€β”€ deploy.yml              # Ansible playbook
β”‚   └── inventory.yml           # Ansible inventory
β”œβ”€β”€ .github/workflows/
β”‚   └── CI_CD_Pipeline.yml      # GitHub Actions workflow
└── README.md                   # Project documentation

πŸ”„ Deployment Workflow

  1. Code Push β†’ Triggers GitHub Actions
  2. Build Stage β†’ Docker image creation and push
  3. Deploy Stage β†’ Ansible deployment to K3s
  4. Health Check β†’ Verify deployment success
  5. Monitoring β†’ HPA and resource monitoring

🎯 Performance Metrics

Metric Target Current
Deployment Time < 2 minutes ~1 minute
CPU Usage < 20% 0% (idle)
Memory Usage < 50% ~27%
Uptime 99.9% βœ…
Auto-scale Response < 30s βœ…

🚨 Troubleshooting

Common Issues

  1. HPA Metrics showing <unknown>

    # Wait 2-3 minutes for metrics initialization
    kubectl describe hpa email-check-hpa
  2. Deployment stuck in pending

    kubectl describe pod -l app=email-check
  3. Service not accessible

    kubectl get svc email-check-service
    # Check NodePort and firewall rules

Debug Commands

# Pod logs
kubectl logs -l app=email-check

# Deployment events
kubectl describe deployment email-check

# Node resources
kubectl top nodes

# Ansible verbose output
ansible-playbook -vvv -i ansible/inventory.yml ansible/deploy.yml

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test the deployment pipeline
  5. Submit a pull request

πŸ“ License

This project is open source and available under the MIT License.

πŸ”— Links


Built with ❀️ using Modern DevOps Practices

Automated β€’ Scalable β€’ Reliable

About

A fully automated DevOps pipeline for deploying an email breach checking service to Kubernetes using Docker, GitHub Actions, and Ansible.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages