Compare commits
11 Commits
6fc589e871
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7877298c2a | |||
| ea5f129de3 | |||
| 2bf5debbfd | |||
| 424a82aaaa | |||
| 0b630929fc | |||
| 430f0d22e4 | |||
| 30a2dc2e20 | |||
| c99dbffa5a | |||
| 260ad28e7f | |||
| 32a7369881 | |||
| 706fed5961 |
15
app/main.py
15
app/main.py
@@ -1,11 +1,24 @@
|
|||||||
from fastapi import FastAPI
|
from fastapi import FastAPI
|
||||||
|
from fastapi.responses import JSONResponse
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
_healthy = True
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/")
|
||||||
def root():
|
def root():
|
||||||
return {"message": "Pozdrav svijete"}
|
return {"message": "Pozdrav svijete"}
|
||||||
|
|
||||||
|
|
||||||
@app.get("/health")
|
@app.get("/health")
|
||||||
def health():
|
def health():
|
||||||
return {"status": "ok"}
|
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"}
|
||||||
@@ -4,7 +4,7 @@ metadata:
|
|||||||
name: moj-servis
|
name: moj-servis
|
||||||
namespace: student-leonarda11
|
namespace: student-leonarda11
|
||||||
spec:
|
spec:
|
||||||
replicas: 1
|
replicas: 4
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
app: moj-servis
|
app: moj-servis
|
||||||
@@ -15,27 +15,50 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
containers:
|
containers:
|
||||||
- name: moj-servis
|
- name: moj-servis
|
||||||
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.0
|
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.2
|
||||||
ports:
|
ports:
|
||||||
- containerPort: 8000
|
- 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:
|
- configMapRef:
|
||||||
name: moj-servis-config # <-- ConfigMap
|
name: moj-servis-config
|
||||||
env: # <-- NOVO
|
|
||||||
|
env:
|
||||||
- name: DB_PASSWORD
|
- name: DB_PASSWORD
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: moj-servis-secret # <-- Secret
|
name: moj-servis-secret
|
||||||
key: DB_PASSWORD
|
key: DB_PASSWORD
|
||||||
- name: API_KEY
|
- name: API_KEY
|
||||||
valueFrom:
|
valueFrom:
|
||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: moj-servis-secret
|
name: moj-servis-secret
|
||||||
key: API_KEY
|
key: API_KEY
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
memory: "64Mi"
|
|
||||||
cpu: "50m"
|
|
||||||
limits:
|
|
||||||
memory: "128Mi"
|
memory: "128Mi"
|
||||||
cpu: "200m"
|
cpu: "150m"
|
||||||
|
limits:
|
||||||
|
memory: "256Mi"
|
||||||
|
cpu: "500m"
|
||||||
@@ -4,16 +4,18 @@ metadata:
|
|||||||
name: moj-servis-ingress
|
name: moj-servis-ingress
|
||||||
namespace: student-leonarda11
|
namespace: student-leonarda11
|
||||||
annotations:
|
annotations:
|
||||||
traefik.ingress.kubernetes.io/router.entrypoints: web
|
traefik.ingress.kubernetes.io/router.entrypoints: web,websecure
|
||||||
|
traefik.ingress.kubernetes.io/router.tls: "true"
|
||||||
spec:
|
spec:
|
||||||
|
ingressClassName: traefik
|
||||||
rules:
|
rules:
|
||||||
- host: leonarda11.argocd.fpmoz.sum.ba
|
- host: moj-servis-leonarda11.argocd.fpmoz.sum.ba
|
||||||
http:
|
http:
|
||||||
paths:
|
paths:
|
||||||
- path: /
|
- path: /
|
||||||
pathType: Prefix
|
pathType: Prefix
|
||||||
backend:
|
backend:
|
||||||
service:
|
service:
|
||||||
name: moj-servis-svc
|
name: moj-servis-svc
|
||||||
port:
|
port:
|
||||||
number: 80
|
number: 80
|
||||||
@@ -10,4 +10,4 @@ spec:
|
|||||||
- port: 80
|
- port: 80
|
||||||
targetPort: 8000
|
targetPort: 8000
|
||||||
protocol: TCP
|
protocol: TCP
|
||||||
type: NodePort
|
type: ClusterIP
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: ConfigMap
|
|
||||||
metadata:
|
|
||||||
name: moj-servis-config
|
|
||||||
namespace: student-leonarda11
|
|
||||||
data:
|
|
||||||
SERVICE_NAME: "moj-servis"
|
|
||||||
LOG_LEVEL: "info"
|
|
||||||
WELCOME_MSG: "Pozdrav iz FPMOZ k3s clustera!"
|
|
||||||
@@ -1,64 +0,0 @@
|
|||||||
apiVersion: apps/v1
|
|
||||||
kind: Deployment
|
|
||||||
metadata:
|
|
||||||
name: moj-servis
|
|
||||||
namespace: student-leonarda11
|
|
||||||
spec:
|
|
||||||
replicas: 1
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app: moj-servis
|
|
||||||
template:
|
|
||||||
metadata:
|
|
||||||
labels:
|
|
||||||
app: moj-servis
|
|
||||||
spec:
|
|
||||||
containers:
|
|
||||||
- name: moj-servis
|
|
||||||
image: git.fpmoz.sum.ba/leonarda11/moj-servis:1.0
|
|
||||||
ports:
|
|
||||||
- containerPort: 8000
|
|
||||||
|
|
||||||
# ── 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
|
|
||||||
|
|
||||||
env:
|
|
||||||
- name: DB_PASSWORD
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
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"
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
apiVersion: networking.k8s.io/v1
|
|
||||||
kind: Ingress
|
|
||||||
metadata:
|
|
||||||
name: moj-servis-ingress
|
|
||||||
namespace: student-leonarda11
|
|
||||||
annotations:
|
|
||||||
traefik.ingress.kubernetes.io/router.entrypoints: web
|
|
||||||
spec:
|
|
||||||
rules:
|
|
||||||
- host: leonarda11.argocd.fpmoz.sum.ba
|
|
||||||
http:
|
|
||||||
paths:
|
|
||||||
- path: /
|
|
||||||
pathType: Prefix
|
|
||||||
backend:
|
|
||||||
service:
|
|
||||||
name: moj-servis-svc
|
|
||||||
port:
|
|
||||||
number: 80
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
apiVersion: v1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: moj-servis-svc
|
|
||||||
namespace: student-leonarda11
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
app: moj-servis
|
|
||||||
ports:
|
|
||||||
- port: 80
|
|
||||||
targetPort: 8000
|
|
||||||
protocol: TCP
|
|
||||||
type: NodePort
|
|
||||||
Reference in New Issue
Block a user