Skip to content

nilspolek/Hauptseminar-Kubernetes-Beispiel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cloud-Plattformen und Big Data - Kubernetes Demo

DigitalOcean Referral Badge

A simple microservices application demonstrating Kubernetes deployment with auto-scaling on DigitalOcean. This project was created for the CS1025 Hauptseminar "Cloud-Plattformen und Big Data" (Rupp).

🎯 Project Overview

This application consists of a Go backend and an HTML/JavaScript frontend that displays the current time. It demonstrates:

  • Containerization with Docker
  • Kubernetes orchestration
  • Horizontal Pod Autoscaling (HPA)
  • Infrastructure as Code with Terraform
  • DigitalOcean cloud deployment
  • NGINX Ingress Controller

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                   Ingress (NGINX)                   β”‚
β”‚              time.webnils.de                        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚                     β”‚
             β”‚ /                   β”‚ /api
             β–Ό                     β–Ό
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚   Frontend    β”‚     β”‚    Backend    β”‚
     β”‚  (nginx:80)   │────▢│   (Go:8080)   β”‚
     β”‚               β”‚     β”‚   + HPA       β”‚
     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Components

  • Frontend: Static HTML page served by NGINX that fetches and displays the current time
  • Backend: Go HTTP server that provides a REST API endpoint (/api/time) returning the current time in JSON format
  • Auto-scaling: HPA configured to scale backend pods (1-5 replicas) based on 50% CPU utilization
  • Infrastructure: DigitalOcean Kubernetes cluster (3 nodes, s-2vcpu-4gb) provisioned via Terraform

πŸ“ Project Structure

.
β”œβ”€β”€ Backend/
β”‚   β”œβ”€β”€ Dockerfile          # Multi-stage build for Go backend
β”‚   β”œβ”€β”€ go.mod              # Go module definition
β”‚   └── main.go             # Backend API server
β”œβ”€β”€ Frontend/
β”‚   β”œβ”€β”€ Dockerfile          # NGINX container for static frontend
β”‚   └── index.html          # Time display UI
β”œβ”€β”€ K8S/
β”‚   β”œβ”€β”€ backend.yaml        # Backend deployment, service, and HPA
β”‚   β”œβ”€β”€ frontend.yaml       # Frontend deployment and service
β”‚   └── ingress.yaml        # Ingress routing configuration
β”œβ”€β”€ terraform/
β”‚   β”œβ”€β”€ main.tf             # DigitalOcean cluster and infrastructure
β”‚   β”œβ”€β”€ input.tf            # Terraform variables
β”‚   └── output.tf           # Terraform outputs
└── presi.txt               # Deployment commands and notes

πŸš€ Deployment

Prerequisites

1. Provision Infrastructure

cd terraform
terraform init
terraform apply

This creates:

  • Kubernetes cluster (3-node, fra1 region)
  • Container registry
  • NGINX Ingress Controller
  • Metrics Server (for HPA)

2. Build and Push Docker Images

Login to DigitalOcean container registry:

doctl registry login

Build and push backend:

cd Backend
docker buildx build --platform linux/amd64 \
  -t registry.digitalocean.com/hauptseminar/backend:latest \
  --push .

Build and push frontend:

cd Frontend
docker buildx build --platform linux/amd64 \
  -t registry.digitalocean.com/hauptseminar/frontend:latest \
  --push .

3. Configure kubectl

doctl kubernetes cluster list
doctl kubernetes cluster kubeconfig save hs-cluster

4. Deploy to Kubernetes

kubectl apply -f K8S/backend.yaml
kubectl apply -f K8S/frontend.yaml
kubectl apply -f K8S/ingress.yaml

5. Verify Deployment

kubectl get pods
kubectl get services
kubectl get ingress
kubectl get hpa

πŸ”§ Configuration

Backend

  • Port: 8080
  • Endpoint: /api/time
  • CPU Requests: 100m
  • CPU Limits: 500m
  • Auto-scaling: 1-5 replicas at 50% CPU

Frontend

  • Port: 80
  • Update Interval: 1 second

Ingress

  • Host: time.webnils.de
  • Routes:
    • / β†’ Frontend
    • /api β†’ Backend

πŸ“Š Monitoring

Check HPA status:

kubectl get hpa backend-hpa --watch

View backend logs:

kubectl logs -l app=backend -f

View metrics:

kubectl top pods
kubectl top nodes

πŸ§ͺ Testing Auto-Scaling

The backend includes a CPU-intensive loop in each request to simulate load. Generate traffic to trigger auto-scaling:

# Simple load test
while true; do curl https://time.webnils.de/api/time; done

Watch pods scale:

kubectl get hpa backend-hpa --watch
kubectl get pods -l app=backend --watch

πŸ› οΈ Development

Local Backend Development

cd Backend
go run main.go
# Server runs on http://localhost:8080

Test endpoint:

curl http://localhost:8080/api/time

Local Frontend Development

cd Frontend
python3 -m http.server 8080
# Open http://localhost:8080

πŸ“ API Reference

GET /api/time

Returns the current server time in RFC3339 format.

Response:

{
  "time": "2025-12-16T10:30:45+01:00"
}

🧹 Cleanup

Remove Kubernetes resources:

kubectl delete -f K8S/

Destroy infrastructure:

cd terraform
terraform destroy

πŸ“š Technologies Used

  • Backend: Go 1.25
  • Frontend: HTML, JavaScript, NGINX
  • Container: Docker, Multi-stage builds
  • Orchestration: Kubernetes 1.34
  • Cloud: DigitalOcean
  • IaC: Terraform
  • Ingress: NGINX Ingress Controller
  • Monitoring: Kubernetes Metrics Server

πŸ“„ License

This is an educational project created for the Hauptseminar "Cloud-Plattformen und Big Data" at the university.

πŸ‘€ Author

Nils Polek


Note: This project demonstrates cloud-native development principles including containerization, orchestration, auto-scaling, and infrastructure as code for educational purposes.

This README was created with AI assistance.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors