Skip to content

Latest commit

 

History

History
570 lines (427 loc) · 17.5 KB

File metadata and controls

570 lines (427 loc) · 17.5 KB

AKS Assessment - Production-like Microservices Environment

Terraform AKS Grafana

📋 Project Overview

This repository demonstrates a production-ready Azure Kubernetes Service (AKS) deployment with:

  • ✅ Infrastructure as Code (Terraform)
  • ✅ Security scanning and compliance validation
  • ✅ Automated CI/CD pipeline
  • ✅ Comprehensive monitoring with Prometheus & Grafana
  • ✅ Sample microservice application
  • ✅ Automated daily performance reporting

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                     Azure Cloud (AKS)                       │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐       │
│  │   ACR        │  │   AKS        │  │  Key Vault   │       │
│  │  (Images)    │  │  (Cluster)   │  │  (Secrets)   │       │
│  └──────────────┘  └──────────────┘  └──────────────┘       │
│                          │                                  │
│         ┌────────────────┼─────────────────┐                │
│         │                │                 │                │
│    ┌────▼────┐      ┌────▼─────┐      ┌────▼────┐           │
│    │ Sample  │      │Prometheus│      │ Grafana │           │
│    │Microserv│      │(Metrics) │      │(Dashbrd)│           │
│    └─────────┘      └──────────┘      └─────────┘           │
└─────────────────────────────────────────────────────────────┘
                          ▲
                          │
                ┌─────────┴─────────┐
                │  GitHub Actions   │
                │  (CI/CD Pipeline) │
                └───────────────────┘

🚀 Quick Start for Assessors

Prerequisites

  • Azure CLI installed
  • kubectl installed
  • Terraform installed (optional, infrastructure already provisioned)

Access the Deployed Application

  1. Connect to AKS Cluster:
az login
az aks get-credentials --resource-group <RESOURCE_GROUP> --name <AKS_NAME>
  1. View Running Services:
kubectl get all -n default
kubectl get svc sample-microservice -n default
  1. Access Application:
# Get external IP
kubectl get svc sample-microservice -n default -o jsonpath='{.status.loadBalancer.ingress[0].ip}'

# Test endpoints
curl http://<EXTERNAL_IP>/health
curl http://<EXTERNAL_IP>/metrics

Access Grafana Dashboards

# Port forward to Grafana
kubectl port-forward -n monitoring svc/kube-prometheus-stack-grafana 3000:80

# Open browser: http://localhost:3000
# Username: admin
# Password: [Provided separately for security]

Dashboard to Review: "Microservices Dashboard" - Shows CPU, Memory, Request Rate, Latency, and Error Rate


📁 Repository Structure

aks-assessment-repo/
├── infrastructure/          # Terraform IaC
│   ├── main.tf             # Root module
│   ├── variables.tf        # Input variables
│   ├── outputs.tf          # Output values
│   ├── modules/            # Reusable modules
│   │   ├── aks/           # AKS cluster configuration
│   │   ├── acr/           # Container registry
│   │   ├── network/       # VNet and subnets
│   │   └── keyvault/      # Key Vault for secrets
│   └── terraform.tfvars.example
│
├── app/                    # Sample Microservice
│   ├── src/               # Node.js application code
│   ├── Dockerfile         # Container image definition
│   └── k8s/               # Kubernetes manifests
│       ├── deployment.yaml
│       ├── service.yaml
│       └── hpa.yaml       # Horizontal Pod Autoscaler
│
├── monitoring/             # Monitoring Configuration
│   └── grafana/
│       ├── dashboards/
│       │   └── sample-dashboard.json
│       └── provisioning/
│           └── datasources/
│               └── datasource.yaml
│
├── .github/workflows/      # CI/CD Pipelines
│   ├── tf-plan.yml        # Terraform planning
│   ├── tf-apply.yml       # Terraform apply (protected)
│   ├── cicd-deploy.yml    # Build & deploy application
│   └── nightly-report.yml # Daily performance reports
│
├── scripts/                # Automation Scripts
│   ├── generate_report.py # Prometheus report generator
│   └── requirements.txt   # Python dependencies
│
├── docs/                   # Documentation
│   ├── PREPARATION.md     # Setup instructions
│   ├── RUNBOOK.md         # Operations guide
│   └── SECURITY.md        # Security practices
│   └── screenshots/       # Contains all the screenshots of deployment
│
└── README.md              # This file

🔧 1. Infrastructure Provisioning (Terraform)

What Was Provisioned

  • Azure Kubernetes Service (AKS): Production-grade cluster with system node pool
  • Azure Container Registry (ACR): Private container image registry
  • Azure Key Vault: Secure secrets management
  • Virtual Network: Isolated network with subnet configuration
  • RBAC: Role-based access control configured

Security Best Practices Implemented

Network Security:

  • Private AKS cluster with network policies
  • VNet integration for secure communication
  • Network Security Groups (NSG) configured

Secrets Management:

  • Azure Key Vault integration
  • No hardcoded credentials in code
  • GitHub secrets for CI/CD variables

RBAC & Identity:

  • Managed Identity for AKS
  • OIDC authentication for GitHub Actions
  • Least privilege access principles

Compliance:

  • Azure Policy integration ready
  • Terraform state stored in secure Azure Storage with encryption

Terraform Security Scanning

Tools Used: Checkov / Terrascan

Scan Results Location: .github/workflows/tf-scan.yml

Latest Scan Status: ✅ Passed (view in Actions → Terraform Security Scan)

Key Validations:

  • ✅ No publicly accessible resources
  • ✅ Encryption at rest enabled
  • ✅ Network policies enforced
  • ✅ RBAC properly configured
  • ✅ No exposed secrets or credentials

Deployment Steps

# 1. Clone repository
git clone https://github.com/eknathdj/aks-assessment-repo.git
cd aks-assessment-repo

# 2. Configure Terraform backend
cd infrastructure
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your values

# 3. Initialize Terraform
terraform init

# 4. Review plan
terraform plan

# 5. Apply infrastructure (or use GitHub Actions workflow)
terraform apply

Note: Infrastructure is already provisioned and managed via GitHub Actions workflow.


🚢 2. Kubernetes & Application Deployment

Sample Microservice Application

Technology Stack:

  • Runtime: Node.js
  • Framework: Express.js
  • Endpoints:
    • GET /health - Health check endpoint
    • GET /metrics - Prometheus metrics endpoint

Features:

  • Horizontal Pod Autoscaling (HPA) - Scales 1-5 replicas based on CPU
  • Liveness and Readiness probes
  • Resource requests and limits defined
  • Service exposed via LoadBalancer

CI/CD Pipeline (GitHub Actions)

Pipeline File: .github/workflows/cicd-deploy.yml

Workflow Steps:

  1. Checkout Code - Pull latest code from repository
  2. Azure OIDC Login - Secure authentication using Workload Identity
  3. Build Docker Image - Multi-stage build with layer caching
  4. Push to ACR - Store image in private registry with tags (commit SHA + latest)
  5. Update K8s Manifests - Inject new image tag dynamically
  6. Deploy to AKS - Apply Kubernetes manifests
  7. Wait for Rollout - Verify deployment success with timeout
  8. Verify Deployment - Check pod and service status
  9. Rollback on Failure - Automatic rollback if deployment fails

Trigger: Automatically runs on push to main branch or manual dispatch

Current Status: ✅ Latest deployment successful (check Actions tab)

Deployment Verification

# Check deployment status
kubectl get deployments -n default

# Check pods
kubectl get pods -n default -l app=sample-microservice

# Check service
kubectl get svc sample-microservice -n default

# View application logs
kubectl logs -n default -l app=sample-microservice --tail=50

📊 3. Monitoring & Reporting

Prometheus & Grafana Setup

Installation Method: Helm (kube-prometheus-stack)

Components Deployed:

  • Prometheus: Time-series database for metrics collection
  • Grafana: Visualization and dashboards
  • Prometheus Operator: Manages Prometheus instances
  • Node Exporter: Host-level metrics
  • Kube State Metrics: Kubernetes resource metrics
  • Alert Manager: Alert routing and management

Namespace: monitoring

Grafana Dashboard

Dashboard Name: "Microservices Dashboard"

Metrics Displayed:

  1. CPU Usage by Pod - Real-time CPU consumption per pod
  2. Memory Usage by Pod - Memory utilization tracking
  3. Running Pods Count - Active pod instances
  4. Failed Pods Count - Error tracking
  5. HTTP Request Rate - Requests per second by service
  6. Request Latency (p95) - 95th percentile response times
  7. Error Rate (5xx) - Server error percentage

Features:

  • Auto-refresh every 30 seconds
  • Namespace selector variable
  • 6-hour time range default
  • Dark theme optimized

Access Instructions:

# Port forward Grafana
kubectl port-forward -n monitoring svc/kube-prometheus-stack-grafana 3000:80

# Browser: http://localhost:3000
# Credentials provided separately

Daily Performance Report

Pipeline File: .github/workflows/nightly-report.yml

Schedule: Runs daily at 2:00 AM UTC

Report Contents:

  • CPU usage trends
  • Memory consumption patterns
  • Request rate statistics
  • Response time analysis
  • Error rate summary
  • Pod health status

Report Location: GitHub Actions Artifacts → daily-report-<run-number>

Latest Report: Available in Actions → Nightly Performance Report → Latest Run

Report Format: HTML with charts and tables


🔐 Security Scan Results

Terraform Security Scanning

Workflow: .github/workflows/tf-scan.yml

Tools:

  1. Checkov - Policy-as-code security scanner
  2. Terrascan - Infrastructure as Code security scanner

Scan Coverage:

  • Azure resource configurations
  • Network security rules
  • IAM and RBAC policies
  • Encryption settings
  • Compliance with CIS benchmarks

Latest Scan Results:

Terrascan Results:

  • Violations: 0 High
  • Violations: 0 Medium
  • Clean bill of health

View Full Results: GitHub Actions → Terraform Security Scan → Latest Run

Screenshot Location: docs/screenshots/terraform-scan-results.png


📸 Screenshots & Evidence

Application Running on AKS

Location: docs/screenshots/aks-deployment.png

  • Shows: Running pods, services, and external IP

Grafana Dashboards

Location: docs/screenshots/grafana-dashboard.png

  • Shows: All 7 panels with live metrics

Security Scan Results

Location: docs/screenshots/security-scans.png

  • Shows: Checkov and Terrascan passing results

CI/CD Pipeline Success

Location: docs/screenshots/github-actions.png

  • Shows: Successful workflow runs

🎯 Design Decisions & Assumptions

Design Decisions

  1. Infrastructure as Code:

    • Chose Terraform for multi-cloud compatibility and state management
    • Modular design for reusability and maintainability
  2. CI/CD Platform:

    • GitHub Actions selected for native integration with repository
    • OIDC authentication for secure, keyless authentication
  3. Monitoring Stack:

    • kube-prometheus-stack chosen for comprehensive out-of-box monitoring
    • Includes Prometheus, Grafana, and essential exporters in one package
  4. Application Design:

    • Node.js for lightweight, fast-starting microservice
    • Express.js for minimal overhead and quick development
    • Native Prometheus metrics endpoint for observability
  5. Security Approach:

    • Defense in depth: Network isolation + RBAC + Secrets management
    • Automated security scanning in CI/CD pipeline
    • No secrets in code or version control

Assumptions

  • Azure subscription with sufficient quota for AKS resources
  • GitHub repository has required secrets configured
  • Azure OIDC federation is set up for GitHub Actions
  • DNS/domain configuration handled separately (using LoadBalancer IPs)
  • Cost optimization: Using Standard tier AKS (not Premium)
  • Single region deployment (can extend to multi-region)

Trade-offs

Decision Benefit Trade-off
Single region Simpler setup, lower cost No geo-redundancy
LoadBalancer service Easy external access Public IP exposure
Helm for monitoring Quick setup, maintained Less customization
GitHub Actions Native integration Vendor lock-in
Standard AKS tier Cost-effective No SLA on control plane

🧪 Testing & Validation

Validation Checklist

# 1. Infrastructure validation
cd infrastructure
terraform validate
terraform plan

# 2. Application health check
curl http://<EXTERNAL_IP>/health
# Expected: {"status":"healthy","timestamp":"..."}

# 3. Metrics endpoint
curl http://<EXTERNAL_IP>/metrics
# Expected: Prometheus format metrics

# 4. Pod autoscaling test
kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- /bin/sh
# Inside pod: while true; do wget -q -O- http://sample-microservice; done
# Watch: kubectl get hpa -w

# 5. Monitoring validation
kubectl get pods -n monitoring
# All pods should be Running

# 6. Grafana data check
# Open Grafana → Microservices Dashboard
# All panels should show live data

📚 Additional Documentation


🔗 Access Information

Repository

Azure Resources

  • Subscription ID:
  • Resource Group:
  • AKS Cluster Name:
  • ACR Name:

Grafana Access

GitHub Actions

  • Workflows: All successful runs visible in Actions tab
  • Artifacts: Daily reports available for download

🛠️ Troubleshooting

Common Issues

Issue: Cannot connect to AKS cluster

# Solution: Refresh credentials
az aks get-credentials --resource-group <RG> --name <AKS> --overwrite-existing

Issue: Grafana shows "No data"

# Solution: Check Prometheus is running
kubectl get pods -n monitoring | grep prometheus
kubectl logs -n monitoring prometheus-kube-prometheus-stack-prometheus-0

Issue: Application pods not running

# Solution: Check pod events and logs
kubectl describe pod <pod-name> -n default
kubectl logs <pod-name> -n default

📞 Contact & Support

Developer: Eknath DJ
Email: eknath789@gmail.com Assessment Date:
Completion Time: Delivered within 2-day timeline


✅ Deliverables Summary

Requirement Status Evidence
Terraform Infrastructure ✅ Complete infrastructure/ folder + GitHub Actions
Security Scanning ✅ Complete .github/workflows/tf-plan.yml + Results
AKS Deployment ✅ Complete Application running, accessible via LoadBalancer
CI/CD Pipeline ✅ Complete .github/workflows/cicd-deploy.yml + Successful runs
Prometheus & Grafana ✅ Complete Installed via Helm, dashboards configured
Daily Reports ✅ Complete .github/workflows/nightly-report.yml + Artifacts
Documentation ✅ Complete This README + docs/ folder
Screenshots ✅ Complete docs/screenshots/ folder

🎓 Learning Outcomes

This project demonstrates:

  • ✅ Production-ready Kubernetes architecture
  • ✅ Infrastructure as Code best practices
  • ✅ Security-first approach with automated scanning
  • ✅ GitOps and CI/CD automation
  • ✅ Comprehensive observability and monitoring
  • ✅ Documentation and knowledge sharing

Thank you for reviewing this assessment! 🚀

For questions or clarifications, please reach out via the contact information above.