Skip to content

Gil80/eks-project

Repository files navigation

Flask Load Balancer Demo

A containerized demo that shows how Nginx round-robin load balancing works across multiple application instances. Built with Flask, Docker, and Docker Compose.

What It Does

A minimal Flask API serves a single endpoint that returns the IP address of the container handling the request. Nginx sits in front as a reverse proxy and distributes incoming requests across three Flask containers using round-robin load balancing.

Refreshing the browser repeatedly shows different IP addresses — one per container — demonstrating that each request is routed to a different backend instance.

Architecture

Browser (localhost:9090)
        │
        ▼
  ┌─────────────┐
  │    Nginx    │  ← reverse proxy / load balancer (port 80 → 9090)
  └─────────────┘
     │    │    │
     ▼    ▼    ▼
  Flask  Flask  Flask   ← 3 identical containers (port 5000 each)
  (app1) (app2) (app3)

Each Flask container returns its own container IP when hit, making it easy to see which instance served the request.

Tech Stack

  • Python / Flask — lightweight REST API
  • Nginx — reverse proxy with upstream round-robin balancing
  • Docker — containerized services
  • Docker Compose — multi-container orchestration with --scale

Quick Start

git clone https://github.com/Gil80/eks-project.git
cd eks-project
docker compose up --build --scale app=3

Open http://localhost:9090 and press F5 a few times — the IP changes with each request.

Project Structure

eks-project/
├── app/
│   ├── app.py              # Flask app — returns container IP
│   ├── Dockerfile
│   └── requirements.txt
├── nginx/
│   ├── nginx.conf          # Upstream + round-robin config
│   └── Dockerfile
├── docker-compose.yml      # Orchestrates app (×3) + nginx
└── SETUP.md                # Detailed setup and usage instructions

Key Concepts Demonstrated

  • Container networking — services communicate by name (app:5000) within the Docker network
  • Horizontal scaling--scale app=3 spins up multiple identical instances from one image
  • Round-robin load balancing — Nginx distributes requests evenly across all running instances
  • Reverse proxy — Nginx accepts external traffic and forwards it to internal services

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors