From c8cd541348960dfae9da9d6b193e2066ea68a7ae Mon Sep 17 00:00:00 2001 From: ITO Mac Date: Tue, 26 May 2026 10:23:44 +0200 Subject: [PATCH] init --- app/.dockerignore | 6 ++++++ app/Dockerfile | 15 +++++++++++++++ app/main.py | 11 +++++++++++ app/requirements.txt | 2 ++ k8s/deployment.yaml | 27 +++++++++++++++++++++++++++ k8s/ingress.yaml | 18 ++++++++++++++++++ k8s/service.yaml | 13 +++++++++++++ 7 files changed, 92 insertions(+) create mode 100644 app/.dockerignore create mode 100644 app/Dockerfile create mode 100644 app/main.py create mode 100644 app/requirements.txt create mode 100644 k8s/deployment.yaml create mode 100644 k8s/ingress.yaml create mode 100644 k8s/service.yaml diff --git a/app/.dockerignore b/app/.dockerignore new file mode 100644 index 0000000..7079a7b --- /dev/null +++ b/app/.dockerignore @@ -0,0 +1,6 @@ +__pycache__/ +*.pyc +.env +.git/ +*.md +k8s/ \ No newline at end of file diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..f4c96b5 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.12-slim + +WORKDIR /app + +# Kopiraj ovisnosti PRVO — ako se ne mijenjaju, pip install se preskace (cache hit) +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +# Kopiraj kod NAKON instalacije +COPY app/ ./app/ + +EXPOSE 8000 + +# OBAVEZNO: --host 0.0.0.0 da Ingress moze pristupiti containeru +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..6b922ac --- /dev/null +++ b/app/main.py @@ -0,0 +1,11 @@ +from fastapi import FastAPI + +app = FastAPI() + +@app.get("/") +def root(): + return {"message": "Pozdrav svijete!", "autor": "VAŠ_KORISNIK"} + +@app.get("/health") +def health(): + return {"status": "ok"} \ No newline at end of file diff --git a/app/requirements.txt b/app/requirements.txt new file mode 100644 index 0000000..d50dc68 --- /dev/null +++ b/app/requirements.txt @@ -0,0 +1,2 @@ +fastapi==0.111.0 +uvicorn[standard]==0.29.0 \ No newline at end of file diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 0000000..2978b92 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,27 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: priprema-za-kolokvij + namespace: student-blazp04 +spec: + replicas: 1 + selector: + matchLabels: + app: priprema-za-kolokvij + template: + metadata: + labels: + app: priprema-za-kolokvij + spec: + containers: + - name: priprema-za-kolokvij + image: git.fpmoz.sum.ba/blazp04/priprema-za-kolokvij:1.0 + ports: + - containerPort: 8000 + resources: + requests: + memory: "64Mi" + cpu: "50m" + limits: + memory: "128Mi" + cpu: "200m" \ No newline at end of file diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml new file mode 100644 index 0000000..8a98fbc --- /dev/null +++ b/k8s/ingress.yaml @@ -0,0 +1,18 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: priprema-ingress + namespace: student-blazp04 +spec: + ingressClassName: traefik + rules: + - host: blazp04.argocd.fpmoz.sum.ba + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: priprema-svc # mora odgovarati service.yaml + port: + number: 80 # port Servicea (ne containera!) \ No newline at end of file diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 0000000..b076655 --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: priprema-svc + namespace: student-blazp04 +spec: + selector: + app: priprema-za-kolokvij # spaja Service s Podovima koji imaju ovaj label + ports: + - port: 80 # port koji Service eksponira (Ingress ce slati ovdje) + targetPort: 8000 # port containera (uvicorn slusa na 8000) + protocol: TCP + type: ClusterIP # samo unutar K8s clustera — Ingress rjesava vanjski pristup \ No newline at end of file