diff --git a/README.md b/README.md index 96027c9..0f5f5aa 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,12 @@ The portals chart is located in the [`charts/portals`](./charts/portals/) folder See more about the chart in the [README](./charts/portals/README.md) of the chart. +### Strichlistensystem + +The strichlistensystem chart is located in the [`charts/strichlistensystem`](./charts/strichlistensystem/) folder. It contains our [tally system](github.com/fsr5-fhaachen/strichlistensystem). + +See more about the chart in the [README](./charts/strichlistensystem/README.md) of the chart. + ## Authors 👤 **Simon Ostendorf** diff --git a/charts/portals/README.md b/charts/portals/README.md index 9ebddd1..a2966a6 100644 --- a/charts/portals/README.md +++ b/charts/portals/README.md @@ -7,8 +7,8 @@ This chart deploys the Portals application to a Kubernetes cluster. You can install the chart with the following command: ```sh -helm repo add portals https://fsr5-fhaachen.github.io/portals/ -helm upgrade --install portals portals/portals --namespace portals --create-namespace -f values.yaml +helm repo add fsr5-fhaachen https://fsr5-fhaachen.github.io/charts/ +helm upgrade --install portals fsr5-fhaachen/portals --namespace portals --create-namespace -f values.yaml ``` ## Database and Redis diff --git a/charts/strichlistensystem/Chart.yaml b/charts/strichlistensystem/Chart.yaml new file mode 100644 index 0000000..99d5476 --- /dev/null +++ b/charts/strichlistensystem/Chart.yaml @@ -0,0 +1,11 @@ +apiVersion: v2 +name: strichlistensystem +description: Tally system for the first week of the Department of Electrical Engineering and Information Technology at FH Aachen - University of Applied Sciences. +type: application +version: 0.0.1 +appVersion: "2.0.0" +home: github.com/fsr5-fhaachen/strichlistensystem +maintainers: + - name: fsr5-fhaachen + email: fsr-fb5@fh-aachen.de + url: https://fsr5.de/ diff --git a/charts/strichlistensystem/README.md b/charts/strichlistensystem/README.md new file mode 100644 index 0000000..bd82a25 --- /dev/null +++ b/charts/strichlistensystem/README.md @@ -0,0 +1,52 @@ +# Strichlistensystem Helm Chart + +This chart deploys the Strichlistensystem application to a Kubernetes cluster. + +## Install + +You can install the chart with the following command: + +```sh +helm repo add fsr5-fhaachen https://fsr5-fhaachen.github.io/charts/ +helm upgrade --install strichlistensystem fsr5-fhaachen/strichlistensystem --namespace strichlistensystem --create-namespace -f values.yaml +``` + +## Database and Redis + +The chart does not install a database or redis. You have to install them yourself. + +You could use the [postgresql operator](https://cloudnative-pg.io/) and [redis operator](https://ot-container-kit.github.io/redis-operator/) for kubernetes. + +If you want a deployment example, view [our deployment guide](https://github.com/fsr5-fhaachen/portals/blob/main/deploy/README.md) inside the portals repo. (This guide is written for portals but can be adapted for the strichlistensystem because they are both laravel applications installed via helm.) + +## Values + +You can find the default values in the [values.yaml](values.yaml) file. + +You can override the default values but there are some values that need to be changed. The (minimum) required values are: + +```yaml +environment: + APP_NAME: Gerolstein FB5 + APP_KEY: # insert app key here + APP_URL: https://strichlistensystem.fsr5.de + APP_VPN_IP: # insert vpn ip here + CSV_EXPORT_PW: password # insert secret password here + DB_CONNECTION: pgsql + DB_HOST: # insert db host here + DB_PORT: "5432" + DB_DATABASE: postgres + DB_USERNAME: postgres + DB_PASSWORD: # insert db password here + REDIS_HOST: # insert redis host here + REDIS_PASSWORD: # insert redis password here + REDIS_PORT: "6379" +ingress: + enabled: true + className: "nginx" + annotations: + cert-manager.io/issuer: "letsencrypt-prod" + hosts: + - strichlistensystem.fsr5.de + tls: true +``` diff --git a/charts/strichlistensystem/templates/NOTES.txt b/charts/strichlistensystem/templates/NOTES.txt new file mode 100644 index 0000000..cea5bcf --- /dev/null +++ b/charts/strichlistensystem/templates/NOTES.txt @@ -0,0 +1,13 @@ +Thank you for installing {{ .Chart.Name }}. + +Your release is named {{ .Release.Name }}. + +{{- if .Values.ingress.enabled }} +You can access your site on your configured domain by visiting {{ index .Values.ingress.hosts 0 }}. +{{- else }} +You can access your site by port-forwarding to the service: "kubectl port-forward -n {{ .Release.Namespace }} svc/{{ include "strichlistensystem.fullname" . }} 8000:8000" +{{- end }} + + + +Learn more about portals at https://github.com/fsr5-fhaachen/strichlistensystem. diff --git a/charts/strichlistensystem/templates/_helpers.tpl b/charts/strichlistensystem/templates/_helpers.tpl new file mode 100644 index 0000000..2466dd9 --- /dev/null +++ b/charts/strichlistensystem/templates/_helpers.tpl @@ -0,0 +1,51 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "strichlistensystem.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "strichlistensystem.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "strichlistensystem.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "strichlistensystem.labels" -}} +helm.sh/chart: {{ include "strichlistensystem.chart" . }} +{{ include "strichlistensystem.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "strichlistensystem.selectorLabels" -}} +app.kubernetes.io/name: {{ include "strichlistensystem.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/charts/strichlistensystem/templates/deployment.yaml b/charts/strichlistensystem/templates/deployment.yaml new file mode 100644 index 0000000..53b6e2c --- /dev/null +++ b/charts/strichlistensystem/templates/deployment.yaml @@ -0,0 +1,59 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "strichlistensystem.fullname" . }} + labels: + {{- include "strichlistensystem.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "strichlistensystem.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "strichlistensystem.selectorLabels" . | nindent 8 }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8000 + protocol: TCP + {{- if not .Values.disableLivenessProbe }} + livenessProbe: + httpGet: + path: / + port: http + {{- end }} + {{- if not .Values.disableReadinessProbe }} + readinessProbe: + httpGet: + path: / + port: http + {{- end }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + {{- range $key, $value := .Values.environment }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/charts/strichlistensystem/templates/hpa.yaml b/charts/strichlistensystem/templates/hpa.yaml new file mode 100644 index 0000000..05c5ca5 --- /dev/null +++ b/charts/strichlistensystem/templates/hpa.yaml @@ -0,0 +1,20 @@ +{{- if .Values.hpa.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "strichlistensystem.fullname" . }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "strichlistensystem.fullname" . }} + minReplicas: {{ .Values.hpa.minReplicas }} + maxReplicas: {{ .Values.hpa.maxReplicas }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.hpa.averageCPUUtilization }} +{{- end }} diff --git a/charts/strichlistensystem/templates/ingress.yaml b/charts/strichlistensystem/templates/ingress.yaml new file mode 100644 index 0000000..0d9a571 --- /dev/null +++ b/charts/strichlistensystem/templates/ingress.yaml @@ -0,0 +1,54 @@ +{{- if .Values.ingress.enabled -}} +{{- $fullName := include "strichlistensystem.fullname" . -}} +{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }} + {{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }} + {{- $_ := set .Values.ingress.annotations "kubernetes.io/ingress.class" .Values.ingress.className}} + {{- end }} +{{- end }} +{{- if semverCompare ">=1.19-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1 +{{- else if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} +apiVersion: networking.k8s.io/v1beta1 +{{- else -}} +apiVersion: extensions/v1beta1 +{{- end }} +kind: Ingress +metadata: + name: {{ $fullName }} + labels: + {{- include "strichlistensystem.labels" . | nindent 4 }} + {{- with .Values.ingress.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +spec: + {{- if and .Values.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }} + ingressClassName: {{ .Values.ingress.className }} + {{- end }} + {{- if .Values.ingress.tls }} + tls: + - hosts: + {{- range .Values.ingress.hosts }} + - {{ . | quote }} + {{- end }} + secretName: {{ $fullName }}-ingress-tls + {{- end }} + rules: + {{- range .Values.ingress.hosts }} + - host: {{ . | quote }} + http: + paths: + - path: / + pathType: Prefix + backend: + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: 8000 + {{- else }} + serviceName: {{ $fullName }} + servicePort: 8000 + {{- end }} + {{- end }} +{{- end }} diff --git a/charts/strichlistensystem/templates/seed-job.yaml b/charts/strichlistensystem/templates/seed-job.yaml new file mode 100644 index 0000000..0bd5ff0 --- /dev/null +++ b/charts/strichlistensystem/templates/seed-job.yaml @@ -0,0 +1,59 @@ +{{- if or .Values.migrateJob.onInstall .Values.migrateJob.onUpgrade -}} +apiVersion: batch/v1 +kind: Job +metadata: + name: {{ include "strichlistensystem.fullname" . }}-migrate-job + labels: + {{- include "strichlistensystem.labels" . | nindent 4 }} + annotations: + helm.sh/hook: {{ if .Values.migrateJob.onInstall }}pre-install{{ end }}{{ if and .Values.migrateJob.onInstall .Values.migrateJob.onUpgrade }},{{ end }}{{ if .Values.migrateJob.onUpgrade }}pre-upgrade{{ end }} + helm.sh/hook-weight: "1" + helm.sh/hook-delete-policy: hook-succeeded +spec: + template: + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + resources: + {{- toYaml .Values.resources | nindent 12 }} + env: + {{- range $key, $value := .Values.environment }} + - name: {{ $key }} + value: {{ $value | quote }} + {{- end }} + {{- if .Values.migrateJob.seed }} + command: ["php", "artisan", "migrate:fresh", "--seed", "--no-interaction", "--force"] + {{- else }} + command: ["php", "artisan", "migrate", "--no-interaction", "--force"] + {{- end }} + {{- if or (ne .Values.migrateJob.tutorsCsvConfigMapName "") (ne .Values.migrateJob.studentsCsvConfigMapName "") }} + volumeMounts: + {{- if ne .Values.migrateJob.tutorsCsvConfigMapName "" }} + - name: tutors-csv + mountPath: /var/www/html/database/seeders/tutors.csv + subPath: tutors.csv + {{- end }} + {{- if ne .Values.migrateJob.studentsCsvConfigMapName "" }} + - name: students-csv + mountPath: /var/www/html/database/seeders/students.csv + subPath: students.csv + {{- end }} + {{- end }} + {{- if or (ne .Values.migrateJob.tutorsCsvConfigMapName "") (ne .Values.migrateJob.studentsCsvConfigMapName "") }} + volumes: + {{- if ne .Values.migrateJob.tutorsCsvConfigMapName "" }} + - name: tutors-csv + configMap: + name: {{ .Values.migrateJob.tutorsCsvConfigMapName }} + {{- end }} + {{- if ne .Values.migrateJob.studentsCsvConfigMapName "" }} + - name: students-csv + configMap: + name: {{ .Values.migrateJob.studentsCsvConfigMapName }} + {{- end }} + {{- end }} + restartPolicy: Never + backoffLimit: 1 +{{- end }} diff --git a/charts/strichlistensystem/templates/service.yaml b/charts/strichlistensystem/templates/service.yaml new file mode 100644 index 0000000..767eb85 --- /dev/null +++ b/charts/strichlistensystem/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "strichlistensystem.fullname" . }} + labels: + {{- include "strichlistensystem.labels" . | nindent 4 }} +spec: + ports: + - name: http + port: 8000 + targetPort: http + protocol: TCP + selector: + {{- include "strichlistensystem.selectorLabels" . | nindent 4 }} diff --git a/charts/strichlistensystem/values.yaml b/charts/strichlistensystem/values.yaml new file mode 100644 index 0000000..56794e8 --- /dev/null +++ b/charts/strichlistensystem/values.yaml @@ -0,0 +1,83 @@ +replicaCount: 1 + +hpa: + enabled: true + minReplicas: 1 + maxReplicas: 10 + averageCPUUtilization: 90 + +nameOverride: "" +fullnameOverride: "" + +podAnnotations: {} + +image: + repository: ghcr.io/fsr5-fhaachen/strichlistensystem + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: "" + +environment: + APP_NAME: Gerolstein FB5 + APP_ENV: production + APP_KEY: # insert app key here + APP_DEBUG: "false" + APP_FORCE_HTTPS: "true" + APP_EVENT_TYPE: "demo" + APP_URL: https://portals.fsr5.de + APP_VPN_IP: # insert vpn ip here + CSV_EXPORT_PW: password # insert secret password here + DB_CONNECTION: pgsql + DB_HOST: # insert db host here + DB_PORT: "5432" + DB_DATABASE: postgres + DB_USERNAME: postgres + DB_PASSWORD: # insert db password here + OCTANE_HTTPS: "true" + OCTANE_WORKERS: "1" # only one worker per cpu core should be started, see https://laravel.com/docs/10.x/octane#specifying-the-worker-count + OCTANE_MAX_REQUESTS: "512" # set max "open" requests a octane worker can handle, see https://laravel.com/docs/10.x/octane#specifying-the-max-request-count + WWWGROUP: "1000" + WWWUSER: "1000" + CACHE_DRIVER: redis + SESSION_DRIVER: redis + SESSION_LIFETIME: "120" + REDIS_HOST: # insert redis host here + REDIS_PASSWORD: # insert redis password here + REDIS_PORT: "6379" + +ingress: + enabled: true + className: "nginx" + annotations: {} + # cert-manager.io/cluster-issuer: "letsencrypt-prod" + # nginx.ingress.kubernetes.io/limit-rps: "500" + hosts: + - portals.fsr5.de + tls: true + +# default ressources +# should handle about 6 req/s per pod +# scales linear with pod count (15 pods = 90 req/s, 30 pods = 180 req/s, ...) +resources: + limits: + cpu: 150m + memory: 128Mi + requests: + cpu: 150m + memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +migrateJob: + onInstall: false # run on helm install + onUpgrade: false # run on helm upgrade + seed: false # set to true to use migrate:fresh --seed, otherwise only migrate will be executed + tutorsCsvConfigMapName: "" + studentsCsvConfigMapName: "" + +disableReadinessProbe: false # disable pod readiness probe (used for debugging) +disableLivenessProbe: false # disable pod liveness probe (used for debugging)