Compare commits

..

13 Commits

6 changed files with 86 additions and 22 deletions

13
Dockerfile Normal file
View File

@@ -0,0 +1,13 @@
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY app/ ./app/
EXPOSE 8000
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]

24
app/main.py Normal file
View File

@@ -0,0 +1,24 @@
from fastapi import FastAPI
from fastapi.responses import JSONResponse
app = FastAPI()
_healthy = True
@app.get("/")
def root():
return {"message": "Pozdrav svijete"}
@app.get("/health")
def health():
if not _healthy:
return {"status": "unhealthy"}, 503
return {"status": "ok"}
@app.post("/break")
def break_health():
global _healthy
_healthy = False
return {"message": "Servis je sada nezdrav - ocekuj restart"}

View File

@@ -4,7 +4,7 @@ metadata:
name: moj-servis
namespace: student-leonarda11
spec:
replicas: 1
replicas: 4
selector:
matchLabels:
app: moj-servis
@@ -15,27 +15,50 @@ spec:
spec:
containers:
- name: moj-servis
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.0
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.2
ports:
- containerPort: 8000
envFrom: # <-- NOVO
# ── Liveness
livenessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 10
periodSeconds: 15
timeoutSeconds: 3
failureThreshold: 3
# ── Readiness
readinessProbe:
httpGet:
path: /health
port: 8000
initialDelaySeconds: 5
periodSeconds: 10
timeoutSeconds: 2
failureThreshold: 2
envFrom:
- configMapRef:
name: moj-servis-config # <-- ConfigMap
env: # <-- NOVO
name: moj-servis-config
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef:
name: moj-servis-secret # <-- Secret
name: moj-servis-secret
key: DB_PASSWORD
- name: API_KEY
valueFrom:
secretKeyRef:
name: moj-servis-secret
key: API_KEY
resources:
requests:
memory: "64Mi"
cpu: "50m"
limits:
memory: "128Mi"
cpu: "200m"
cpu: "150m"
limits:
memory: "256Mi"
cpu: "500m"

View File

@@ -4,10 +4,12 @@ metadata:
name: moj-servis-ingress
namespace: student-leonarda11
annotations:
traefik.ingress.kubernetes.io/router.entrypoints: web
traefik.ingress.kubernetes.io/router.entrypoints: web,websecure
traefik.ingress.kubernetes.io/router.tls: "true"
spec:
ingressClassName: traefik
rules:
- host: leonarda11.argocd.fpmoz.sum.ba
- host: moj-servis-leonarda11.argocd.fpmoz.sum.ba
http:
paths:
- path: /

View File

@@ -10,4 +10,4 @@ spec:
- port: 80
targetPort: 8000
protocol: TCP
type: NodePort
type: ClusterIP

2
requirements.txt Normal file
View File

@@ -0,0 +1,2 @@
fastapi==0.111.0
uvicorn[standard]==0.29.0