fix health endpoints

This commit is contained in:
2026-05-03 00:20:05 +02:00
parent c1196b075c
commit 683de80429
2 changed files with 42 additions and 19 deletions

View File

@@ -3,10 +3,14 @@ import platform
app = FastAPI() app = FastAPI()
_healthy = True
@app.get("/") @app.get("/")
def root(): def root():
return {"poruka": "Hello iz mog Docker containera v2!"} return {"poruka": "Hello iz mog Docker containera v2!"}
@app.get("/info") @app.get("/info")
def info(): def info():
return { return {
@@ -14,6 +18,26 @@ def info():
"verzija": "2.0" "verzija": "2.0"
} }
@app.get("/health") @app.get("/health")
def health(): def health():
return {"status": "ok"} 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)"}

View File

@@ -16,26 +16,22 @@ spec:
labels: labels:
app: moj-servis app: moj-servis
spec:
template:
spec: spec:
containers: containers:
- name: moj-servis - name: moj-servis
image: git.fpmoz.sum.ba/MartaBulic/moj-servis:1.0 image: git.fpmoz.sum.ba/martabulic/moj-servis:1.1
ports: ports:
- containerPort: 8000 - containerPort: 8000
# ── Liveness: je li proces živ? ─────────────────
livenessProbe: livenessProbe:
httpGet: httpGet:
path: /health path: /health
port: 8000 port: 8000
initialDelaySeconds: 10 # čekaj 10s nakon starta initialDelaySeconds: 10
periodSeconds: 15 # provjeri svakih 15s periodSeconds: 15
timeoutSeconds: 3 # timeout odgovora timeoutSeconds: 3
failureThreshold: 3 # 3 fail-a => restart failureThreshold: 3
# ── Readiness: prima li promet? ─────────────────
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /health path: /health
@@ -46,6 +42,9 @@ spec:
failureThreshold: 2 failureThreshold: 2
resources: resources:
requests: { memory: "64Mi", cpu: "50m" } requests:
limits: { memory: "128Mi", cpu: "200m" } memory: "64Mi"
## cpu: "50m"
limits:
memory: "128Mi"
cpu: "200m"