From edfc46cb956748b4fd472c7dbbfae3f9ef2b2ba2 Mon Sep 17 00:00:00 2001 From: Zvonimir Cavar Date: Tue, 19 May 2026 10:52:20 +0200 Subject: [PATCH] feat: dodaj Kubernetes manifeste za FastAPI + Postgres --- manifests/app/deployment.yaml | 54 ++++++++++++++++++++++++++++++ manifests/app/ingress.yaml | 24 +++++++++++++ manifests/app/service.yaml | 12 +++++++ manifests/config/configmap.yaml | 9 +++++ manifests/config/namespace.yaml | 6 ++++ manifests/config/secret.yaml | 10 ++++++ manifests/database/deployment.yaml | 35 +++++++++++++++++++ manifests/database/pvc.yaml | 12 +++++++ manifests/database/service.yaml | 12 +++++++ 9 files changed, 174 insertions(+) create mode 100644 manifests/app/deployment.yaml create mode 100644 manifests/app/ingress.yaml create mode 100644 manifests/app/service.yaml create mode 100644 manifests/config/configmap.yaml create mode 100644 manifests/config/namespace.yaml create mode 100644 manifests/config/secret.yaml create mode 100644 manifests/database/deployment.yaml create mode 100644 manifests/database/pvc.yaml create mode 100644 manifests/database/service.yaml diff --git a/manifests/app/deployment.yaml b/manifests/app/deployment.yaml new file mode 100644 index 0000000..5df31f5 --- /dev/null +++ b/manifests/app/deployment.yaml @@ -0,0 +1,54 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fastapi-api + namespace: student-zvonec + annotations: + argocd.argoproj.io/sync-wave: "1" +spec: + replicas: 1 + selector: + matchLabels: + app: fastapi-api + template: + metadata: + labels: + app: fastapi-api + spec: + containers: + - name: fastapi-api + image: vasic/fastapi-todo-api:1.0 + ports: + - containerPort: 8000 + env: + - name: DATABASE_HOST + valueFrom: + configMapKeyRef: + name: fastapi-config + key: DATABASE_HOST + - name: DATABASE_PORT + valueFrom: + configMapKeyRef: + name: fastapi-config + key: DATABASE_PORT + - name: POSTGRES_USER + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_USER + - name: POSTGRES_PASSWORD + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_PASSWORD + - name: POSTGRES_DB + valueFrom: + secretKeyRef: + name: postgres-secret + key: POSTGRES_DB + readinessProbe: + httpGet: + path: /health + port: 8000 + initialDelaySeconds: 15 + periodSeconds: 5 \ No newline at end of file diff --git a/manifests/app/ingress.yaml b/manifests/app/ingress.yaml new file mode 100644 index 0000000..a758e30 --- /dev/null +++ b/manifests/app/ingress.yaml @@ -0,0 +1,24 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: fastapi-api-ingress + namespace: student-zvonec + annotations: + traefik.ingress.kubernetes.io/router.entrypoints: websecure + cert-manager.io/cluster-issuer: letsencrypt-prod +spec: + rules: + - host: zvonec.fpmoz.sum.ba + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: fastapi-api-service + port: + number: 80 + tls: + - hosts: + - zvonec.fpmoz.sum.ba + secretName: fastapi-api-tls \ No newline at end of file diff --git a/manifests/app/service.yaml b/manifests/app/service.yaml new file mode 100644 index 0000000..ff3cc2c --- /dev/null +++ b/manifests/app/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: fastapi-api-service + namespace: student-zvonec +spec: + selector: + app: fastapi-api + ports: + - port: 80 + targetPort: 8000 + type: ClusterIP \ No newline at end of file diff --git a/manifests/config/configmap.yaml b/manifests/config/configmap.yaml new file mode 100644 index 0000000..2fafe22 --- /dev/null +++ b/manifests/config/configmap.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: fastapi-config + namespace: student-zvonec +data: + DATABASE_HOST: postgres-service + DATABASE_PORT: "5432" + APP_ENV: production \ No newline at end of file diff --git a/manifests/config/namespace.yaml b/manifests/config/namespace.yaml new file mode 100644 index 0000000..818e5be --- /dev/null +++ b/manifests/config/namespace.yaml @@ -0,0 +1,6 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: student-zvonec # zamijenite + labels: + managed-by: argocd diff --git a/manifests/config/secret.yaml b/manifests/config/secret.yaml new file mode 100644 index 0000000..19f7af4 --- /dev/null +++ b/manifests/config/secret.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: Secret +metadata: + name: postgres-secret + namespace: student-zvonec +type: Opaque +data: + POSTGRES_PASSWORD: c3R1ZGVudDEyMw== + POSTGRES_DB: ZmFzdGFwaWRi + POSTGRES_USER: ZmFzdGFwaXZZXI= \ No newline at end of file diff --git a/manifests/database/deployment.yaml b/manifests/database/deployment.yaml new file mode 100644 index 0000000..a188336 --- /dev/null +++ b/manifests/database/deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postgres + namespace: student-zvonec +spec: + replicas: 1 + selector: + matchLabels: + app: postgres + template: + metadata: + labels: + app: postgres + spec: + containers: + - name: postgres + image: postgres:16-alpine + envFrom: + - secretRef: + name: postgres-secret + ports: + - containerPort: 5432 + volumeMounts: + - name: postgres-data + mountPath: /var/lib/postgresql/data + readinessProbe: + exec: + command: ["pg_isready", "-U", "fastapiuser", "-d", "fastapidb"] + initialDelaySeconds: 10 + periodSeconds: 5 + volumes: + - name: postgres-data + persistentVolumeClaim: + claimName: postgres-pvc \ No newline at end of file diff --git a/manifests/database/pvc.yaml b/manifests/database/pvc.yaml new file mode 100644 index 0000000..029c95f --- /dev/null +++ b/manifests/database/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: postgres-pvc + namespace: student-zvonec +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi + storageClassName: local-path \ No newline at end of file diff --git a/manifests/database/service.yaml b/manifests/database/service.yaml new file mode 100644 index 0000000..9b254cf --- /dev/null +++ b/manifests/database/service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: postgres-service + namespace: student-zvonec +spec: + selector: + app: postgres + ports: + - port: 5432 + targetPort: 5432 + type: ClusterIP \ No newline at end of file