fix health endpoints
This commit is contained in:
32
app/main.py
32
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)"}
|
||||
@@ -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" }
|
||||
##
|
||||
requests:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
||||
limits:
|
||||
memory: "128Mi"
|
||||
cpu: "200m"
|
||||
Reference in New Issue
Block a user