From b509e6ac8a6e4a138d51de7c758103172cec4552 Mon Sep 17 00:00:00 2001 From: Cipher Date: Mon, 25 Aug 2025 06:54:22 -0500 Subject: [PATCH] init ci deployment for homelab k3s --- Dockerfile | 10 ++++++++++ app.py | 9 +++++++++ helm/templates/deployment.yaml | 21 +++++++++++++++++++++ helm/values.yaml | 18 ++++++++++++++++++ requirements.txt | 2 ++ 5 files changed, 60 insertions(+) create mode 100644 Dockerfile create mode 100644 app.py create mode 100644 helm/templates/deployment.yaml create mode 100644 helm/values.yaml create mode 100644 requirements.txt diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f10f5dd --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.12-slim +WORKDIR /app +ENV PYTHONDONTWRITEBYTECODE=1 PYTHONUNBUFFERED=1 +RUN pip install -U pip && adduser --disabled-password --gecos '' app +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt +COPY . . +USER app +EXPOSE 8080 +CMD ["gunicorn","-w","2","-b","0.0.0.0:8080","app:app"] diff --git a/app.py b/app.py new file mode 100644 index 0000000..a0d3a32 --- /dev/null +++ b/app.py @@ -0,0 +1,9 @@ +from flask import Flask +app = Flask(__name__) + +@app.get("/") +def hello(): + return "Hello from Flask on Kubernetes! 🚀" + +if __name__ == "__main__": + app.run(host="0.0.0.0", port=8080) diff --git a/helm/templates/deployment.yaml b/helm/templates/deployment.yaml new file mode 100644 index 0000000..b956f62 --- /dev/null +++ b/helm/templates/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "flask-hello.fullname" . }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: { app: {{ include "flask-hello.name" . }} } + template: + metadata: + labels: { app: {{ include "flask-hello.name" . }} } + spec: + {{- if .Values.imagePullSecrets }} + imagePullSecrets: {{ toYaml .Values.imagePullSecrets | nindent 6 }} + {{- end }} + containers: + - name: app + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + ports: [{ containerPort: {{ .Values.containerPort }} }] + readinessProbe: { httpGet: { path: "/", port: {{ .Values.containerPort }} } } + livenessProbe: { httpGet: { path: "/", port: {{ .Values.containerPort }} } } diff --git a/helm/values.yaml b/helm/values.yaml new file mode 100644 index 0000000..4076f4d --- /dev/null +++ b/helm/values.yaml @@ -0,0 +1,18 @@ +image: + repository: registry.gitlab.com/REPLACE_GROUP/REPLACE_PROJECT + tag: "latest" + pullPolicy: IfNotPresent + +replicaCount: 2 +containerPort: 8080 +servicePort: 8080 + +ingress: + enabled: true + className: nginx + host: hello.example.com + tls: + enabled: true + secretName: flask-hello-tls + clusterIssuer: letsencrypt +imagePullSecrets: [] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b733f8f --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask==3.0.3 +gunicorn==22.0.0