Skip to content

Commit 34ae420

Browse files
committed
Add scaled FastAPI instances and Nginx load balancer
1 parent 432767a commit 34ae420

12 files changed

Lines changed: 39 additions & 5 deletions

docker-compose.yml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
1+
12
services:
23
fastapi:
34
build: .
45
image: fastapi-app
5-
ports:
6-
- "8000:80"
76
networks:
87
- app-network
8+
deploy:
9+
replicas: 3
910
prometheus:
1011
image: prom/prometheus:latest
1112
ports:
12-
- "9091:9090"
13+
- "9090:9090"
1314
volumes:
1415
- ./prometheus.yml:/etc/prometheus/prometheus.yml
1516
networks:
1617
- app-network
18+
nginx:
19+
image: nginx:latest
20+
ports:
21+
- "80:80"
22+
volumes:
23+
- ./nginx.conf:/etc/nginx/nginx.conf
24+
networks:
25+
- app-network
1726

1827
networks:
1928
app-network:

nginx.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
events {}
2+
http {
3+
upstream fastapi_backend {
4+
server fastapi:80;
5+
}
6+
server {
7+
listen 80;
8+
location / {
9+
proxy_pass http://fastapi_backend;
10+
proxy_set_header Host $host;
11+
proxy_set_header X-Real-IP $remote_addr;
12+
}
13+
}
14+
}

nginx_screenshot.png

12.4 KB
Loading

prometheus.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ global:
33
scrape_configs:
44
- job_name: "fastapi"
55
static_configs:
6-
- targets:
7-
- "fastapi:80"
6+
- targets: ['fastapi:80']

scale_fastapi_8000.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"message":"Welcome to my DevOps API!"}

scale_fastapi_8001.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"message":"Welcome to my DevOps API!"}

scale_fastapi_8002.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"message":"Welcome to my DevOps API!"}

scale_nginx_fastapi.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"message":"Welcome to my DevOps API!"}

scale_nginx_health.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"healthy"}

scale_nginx_query.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"up","instance":"fastapi:80","job":"fastapi"},"value":[1756639953.723,"1"]}]}}

0 commit comments

Comments
 (0)