From 683de80429d8fade95c1108ed611f74dc0368aa8 Mon Sep 17 00:00:00 2001 From: Marta Bulic Date: Sun, 3 May 2026 00:20:05 +0200 Subject: [PATCH] fix health endpoints --- app/main.py | 32 ++++++++++++++++++++++++++++---- k8s/moj-servis/deployment.yaml | 29 ++++++++++++++--------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/main.py b/app/main.py index be5e392..ba76af3 100644 --- a/app/main.py +++ b/app/main.py @@ -1,19 +1,43 @@ from fastapi import FastAPI import platform - + app = FastAPI() - + +_healthy = True + + @app.get("/") def root(): return {"poruka": "Hello iz mog Docker containera v2!"} - + + @app.get("/info") def info(): return { "python": platform.python_version(), "verzija": "2.0" } - + + @app.get("/health") def health(): return {"status": "ok"} + + +@app.get("/live") +def live(): + return {"status": "alive"} + + +@app.get("/ready") +def ready(): + if not _healthy: + return {"status": "not ready"} + return {"status": "ready"} + + +@app.post("/break") +def break_health(): + global _healthy + _healthy = False + return {"message": "Simuliran pad servisa (readiness će pasti)"} \ No newline at end of file diff --git a/k8s/moj-servis/deployment.yaml b/k8s/moj-servis/deployment.yaml index fc7972d..9066d7b 100644 --- a/k8s/moj-servis/deployment.yaml +++ b/k8s/moj-servis/deployment.yaml @@ -16,26 +16,22 @@ spec: labels: app: moj-servis -spec: - template: spec: containers: - name: moj-servis - image: git.fpmoz.sum.ba/MartaBulic/moj-servis:1.0 + image: git.fpmoz.sum.ba/martabulic/moj-servis:1.1 ports: - containerPort: 8000 - - # ── Liveness: je li proces živ? ───────────────── + livenessProbe: httpGet: path: /health port: 8000 - initialDelaySeconds: 10 # čekaj 10s nakon starta - periodSeconds: 15 # provjeri svakih 15s - timeoutSeconds: 3 # timeout odgovora - failureThreshold: 3 # 3 fail-a => restart - - # ── Readiness: prima li promet? ───────────────── + initialDelaySeconds: 10 + periodSeconds: 15 + timeoutSeconds: 3 + failureThreshold: 3 + readinessProbe: httpGet: path: /health @@ -44,8 +40,11 @@ spec: periodSeconds: 10 timeoutSeconds: 2 failureThreshold: 2 - + resources: - requests: { memory: "64Mi", cpu: "50m" } - limits: { memory: "128Mi", cpu: "200m" } -## \ No newline at end of file + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "200m" \ No newline at end of file