adding helm
This commit is contained in:
parent
a4e31beb21
commit
d8b074d731
9 changed files with 259 additions and 0 deletions
6
charts/boday-it/Chart.yaml
Normal file
6
charts/boday-it/Chart.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
apiVersion: v2
|
||||||
|
name: boday-it
|
||||||
|
description: Helm Chart für die Django-Webseite von Boday-IT
|
||||||
|
type: application
|
||||||
|
version: 1.0.0
|
||||||
|
appVersion: "1.0.0"
|
||||||
9
charts/boday-it/templates/db-service.yaml
Normal file
9
charts/boday-it/templates/db-service.yaml
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-db
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 5432
|
||||||
|
selector:
|
||||||
|
app: {{ .Release.Name }}-db
|
||||||
42
charts/boday-it/templates/db-statefulset.yaml
Normal file
42
charts/boday-it/templates/db-statefulset.yaml
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-db
|
||||||
|
spec:
|
||||||
|
serviceName: {{ .Release.Name }}-db
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ .Release.Name }}-db
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: {{ .Release.Name }}-db
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres:15-alpine
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
value: {{ .Values.postgres.database | quote }}
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: {{ .Values.postgres.user | quote }}
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .Release.Name }}-secrets
|
||||||
|
key: postgres-password
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
name: dbport
|
||||||
|
volumeMounts:
|
||||||
|
- name: db-data
|
||||||
|
mountPath: /var/lib/postgresql/data
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: db-data
|
||||||
|
spec:
|
||||||
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: {{ .Values.postgres.storageSize }}
|
||||||
44
charts/boday-it/templates/ingress.yaml
Normal file
44
charts/boday-it/templates/ingress.yaml
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
apiVersion: kubernetes.io/ingress.v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-ingress
|
||||||
|
annotations:
|
||||||
|
kubernetes.io/ingress.class: "nginx"
|
||||||
|
spec:
|
||||||
|
rules:
|
||||||
|
- host: boday-it.ch
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
# Statische Dateien gehen an den Nginx-Sidecar (Port 80)
|
||||||
|
- path: /static
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
port:
|
||||||
|
name: static
|
||||||
|
# Alles andere geht direkt an Django (Port 8000)
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
port:
|
||||||
|
name: django
|
||||||
|
- host: www.boday-it.ch
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /static
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
port:
|
||||||
|
name: static
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
port:
|
||||||
|
name: django
|
||||||
8
charts/boday-it/templates/secrets.yaml
Normal file
8
charts/boday-it/templates/secrets.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-secrets
|
||||||
|
type: Opaque
|
||||||
|
data:
|
||||||
|
django-secret-key: {{ .Values.secrets.djangoSecretKey | b64enc | quote }}
|
||||||
|
postgres-password: {{ .Values.secrets.postgresPassword | b64enc | quote }}
|
||||||
72
charts/boday-it/templates/web-deployment.yaml
Normal file
72
charts/boday-it/templates/web-deployment.yaml
Normal file
|
|
@ -0,0 +1,72 @@
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
spec:
|
||||||
|
replicas: {{ .Values.replicaCount }}
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: {{ .Release.Name }}-web
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: {{ .Release.Name }}-web
|
||||||
|
spec:
|
||||||
|
# 1. INIT-CONTAINER: Sammelt statische Dateien beim Pod-Start
|
||||||
|
initContainers:
|
||||||
|
- name: collectstatic
|
||||||
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
|
command: ["/bin/sh", "-c", "python manage.py collectstatic --noinput"]
|
||||||
|
env:
|
||||||
|
- name: DEBUG
|
||||||
|
value: {{ .Values.django.debug | quote }}
|
||||||
|
- name: SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .Release.Name }}-secrets
|
||||||
|
key: django-secret-key
|
||||||
|
volumeMounts:
|
||||||
|
- name: static-assets
|
||||||
|
mountPath: /code/staticfiles
|
||||||
|
|
||||||
|
containers:
|
||||||
|
# 2. HAUPT-CONTAINER: Django / Gunicorn
|
||||||
|
- name: django
|
||||||
|
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
|
||||||
|
imagePullPolicy: {{ .Values.image.pullPolicy }}
|
||||||
|
command: ["gunicorn", "boday_it.wsgi:application", "--bind", "0.0.0.0:8000"]
|
||||||
|
env:
|
||||||
|
- name: DEBUG
|
||||||
|
value: {{ .Values.django.debug | quote }}
|
||||||
|
- name: ALLOWED_HOSTS
|
||||||
|
value: {{ .Values.django.allowedHosts | quote }}
|
||||||
|
- name: SECRET_KEY
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .Release.Name }}-secrets
|
||||||
|
key: django-secret-key
|
||||||
|
- name: DATABASE_URL
|
||||||
|
value: "postgres://{{ .Values.postgres.user }}:$(POSTGRES_PASSWORD)@{{ .Release.Name }}-db:5432/{{ .Values.postgres.database }}"
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: {{ .Release.Name }}-secrets
|
||||||
|
key: postgres-password
|
||||||
|
ports:
|
||||||
|
- containerPort: 8000
|
||||||
|
name: webport
|
||||||
|
|
||||||
|
# 3. SIDECAR-CONTAINER: Nginx für superschnelles Static-Asset Delivery
|
||||||
|
- name: nginx-static
|
||||||
|
image: nginx:alpine
|
||||||
|
volumeMounts:
|
||||||
|
- name: static-assets
|
||||||
|
mountPath: /usr/share/nginx/html/static
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: staticport
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
- name: static-assets
|
||||||
|
emptyDir: {}
|
||||||
12
charts/boday-it/templates/web-service.yaml
Normal file
12
charts/boday-it/templates/web-service.yaml
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: {{ .Release.Name }}-web
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 8000
|
||||||
|
name: django
|
||||||
|
- port: 80
|
||||||
|
name: static
|
||||||
|
selector:
|
||||||
|
app: {{ .Release.Name }}-web
|
||||||
20
charts/boday-it/values.yaml
Normal file
20
charts/boday-it/values.yaml
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
replicaCount: 1
|
||||||
|
|
||||||
|
image:
|
||||||
|
repository: registry.local/bast/boday-it-web
|
||||||
|
tag: latest
|
||||||
|
pullPolicy: Always
|
||||||
|
|
||||||
|
django:
|
||||||
|
debug: "0"
|
||||||
|
allowedHosts: "boday-it.ch,www.boday-it.ch,localhost,127.0.0.1"
|
||||||
|
|
||||||
|
# Diese Werte werden im Secret verschlüsselt
|
||||||
|
secrets:
|
||||||
|
djangoSecretKey: "aldhguroqugaplslljdgzlshfz"
|
||||||
|
postgresPassword: "asafdksdf"
|
||||||
|
|
||||||
|
postgres:
|
||||||
|
database: "djangodb"
|
||||||
|
user: "djangouser"
|
||||||
|
storageSize: 1Gi
|
||||||
46
main.tf
Normal file
46
main.tf
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
terraform {
|
||||||
|
required_providers {
|
||||||
|
kubernetes = {
|
||||||
|
source = "hashicorp/kubernetes"
|
||||||
|
version = "~> 2.26"
|
||||||
|
}
|
||||||
|
helm = {
|
||||||
|
source = "hashicorp/helm"
|
||||||
|
version = "~> 2.12"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Variable für den dynamischen Git-SHA-Tag deiner Pipeline
|
||||||
|
variable "app_version" {
|
||||||
|
type = string
|
||||||
|
default = "latest"
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "kubernetes" {
|
||||||
|
config_path = "./kind_kubeconfig"
|
||||||
|
host = "https://local-k3s-platform:6443"
|
||||||
|
insecure = true
|
||||||
|
}
|
||||||
|
|
||||||
|
provider "helm" {
|
||||||
|
kubernetes {
|
||||||
|
config_path = "./kind_kubeconfig"
|
||||||
|
host = "https://local-k3s-platform:6443"
|
||||||
|
insecure = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# DAS FINALE DJANGO HELM-CHART DEPLOYMENT
|
||||||
|
resource "helm_release" "boday_website" {
|
||||||
|
name = "boday-it"
|
||||||
|
chart = "./charts/boday-it" # Zeigt direkt auf den lokalen Chart-Ordner im Repo
|
||||||
|
namespace = "default"
|
||||||
|
|
||||||
|
# Überschreibt das Image-Tag dynamisch mit der aktuellen Pipeline-Version
|
||||||
|
set {
|
||||||
|
name = "image.tag"
|
||||||
|
value = var.app_version
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in a new issue