Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Jenny's Helm chart #5

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*/*.tgz
1 change: 1 addition & 0 deletions jenny/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
jenny-*.tgz
20 changes: 15 additions & 5 deletions jenny/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,26 @@ Common labels
*/}}
{{- define "jenny.labels" -}}
helm.sh/chart: {{ include "jenny.chart" . }}
{{ include "jenny.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "jenny.selectorLabels" -}}
app.kubernetes.io/name: {{ include "jenny.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app: jenny
service: app
app.kubernetes.io/part-of: {{ .Chart.Name }}
{{- end }}

{{- define "jenny.djangoSelectorLabels" -}}
app.kubernetes.io/name: django
app.kubernetes.io/component: backend
{{- end -}}

{{- define "jenny.envs" -}}
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
- name: "DJANGO_SETTINGS_MODULE"
value: "{{ .Values.django.settings }}"
Expand All @@ -77,6 +80,13 @@ service: app
value: "{{ .Values.django.db.host }}"
- name: "DB_PORT"
value: "{{ .Values.django.db.port }}"
{{- range $key, $val := .Values.env.secret }}
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
- name: {{ $val.envName }}
valueFrom:
secretKeyRef:
name: {{ $val.secretName }}
key: {{ $val.keyName }}
{{- end }}
{{- end }}

{{- define "django.imagePullSecrets" -}}
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -85,6 +95,6 @@ service: app
imagePullSecrets:
{{- range $pullSecrets }}
- name: {{ . }}
{{ end }}
{{- end }}
{{- end -}}
{{- end }}
60 changes: 60 additions & 0 deletions jenny/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: "{{ template "jenny.fullname" . }}-nginx"
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
labels:
{{- include "jenny.labels" . | nindent 4 }}
{{- include "jenny.djangoSelectorLabels" . | nindent 4 -}}
{{- if .Values.commonLabels }}
{{ toYaml .Values.commonLabels | nindent 4 }}
{{- end }}
data:
config: |
# nginx.conf
user nobody nogroup;
# 'user nobody nobody;' for systems with 'nobody' as a group instead
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024; # increase if you have lots of clients
accept_mutex off; # set to 'on' if nginx worker_processes > 1
# 'use epoll;' to enable for Linux 2.6+
# 'use kqueue;' to enable for FreeBSD, OSX
}

http {
upstream django_app {
server localhost:{{ .Values.django.port }};
}

server {
listen {{ .Values.nginx.port }};

root /usr/share/nginx;
location / {
# checks for static file, if not found proxy to app
try_files $uri @proxy_to_app;
}

location @proxy_to_app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
proxy_pass http://django_app;
}
}

server {
listen 5000;
server_name localhost;

location /__status__ {
stub_status;
access_log off;
}

}

include /etc/nginx/mime.types;
}
93 changes: 75 additions & 18 deletions jenny/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ template "jenny.fullname" . }}
name: "{{ template "jenny.fullname" . }}"
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "jenny.labels" . | nindent 4 }}
{{- include "jenny.djangoSelectorLabels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{ toYaml .Values.commonLabels | nindent 4 }}
{{- end }}
spec:
selector:
matchLabels:
{{- include "jenny.selectorLabels" . | nindent 6 }}
{{- include "jenny.selectorLabels" . | nindent 6 -}}
{{- include "jenny.djangoSelectorLabels" . | nindent 6 }}
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
Expand All @@ -20,46 +26,97 @@ spec:
{{- end }}
labels:
{{- include "jenny.selectorLabels" . | nindent 8 }}
{{- include "jenny.djangoSelectorLabels" . | nindent 8 }}
spec:
{{- include "django.imagePullSecrets" . | nindent 6 }}
securityContext:
{{- toYaml .Values.securityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
initContainers:
- name: "{{ .Chart.Name }}-collectstatic"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
command:
{{- toYaml .Values.django.command | nindent 12 }}
- "python"
- "manage.py"
- "collectstatic"
- "--no-input"
volumeMounts:
- name: "static"
mountPath: /app/static
env:
{{- include "jenny.envs" . | nindent 12 }}
containers:
- name: "{{ .Chart.Name }}-django"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- toYaml .Values.django.resources | nindent 12 }}
livenessProbe:
httpGet:
path: /__lbheartbeat__
path: /__heartbeat__
port: {{ .Values.django.port }}
httpHeaders:
- name: "Host"
value: "{{ .Values.ingress.host}}"
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
initialDelaySeconds: 15
periodSeconds: 30
readinessProbe:
httpGet:
path: /__heartbeat__
path: /__lbheartbeat__
port: {{ .Values.django.port }}
httpHeaders:
- name: "Host"
value: "{{ .Values.ingress.host}}"
initialDelaySeconds: 5
periodSeconds: 5
startupProbe:
exec:
command:
- python3
- manage.py
- migrate
- --check
initialDelaySeconds: 5
periodSeconds: 5
timeoutSeconds: 30
env:
{{- include "jenny.envs" . | nindent 12 }}
{{- if .Values.persistence.enabled }}
- name: "UWSGI_PORT"
value: "{{ .Values.django.port }}"
volumeMounts:
- name: {{ .Values.volumes.static.name }}
mountPath: {{ .Values.volumes.static.mountPath }}
- name: static
mountPath: /app/static
- name: {{ .Values.volumes.media.name }}
mountPath: {{ .Values.volumes.media.mountPath }}
- name: "{{ .Chart.Name }}-nginx"
image: nginx:1.25.4-alpine
resources:
{{- toYaml .Values.nginx.resources | nindent 12 }}
volumeMounts:
- name: "static"
mountPath: /usr/share/nginx/static
- name: {{ .Values.volumes.media.name }}
mountPath: /usr/share/nginx/media
- name: nginx
mountPath: /etc/nginx
readOnly: true
livenessProbe:
httpGet:
path: /__status__
port: 5000
initialDelaySeconds: 15
periodSeconds: 30
volumes:
- name: {{ .Values.volumes.static.name }}
persistentVolumeClaim:
claimName: {{ .Values.volumes.static.claimName }}
- name: {{ .Values.volumes.media.name }}
persistentVolumeClaim:
claimName: {{ .Values.volumes.media.claimName }}
{{- end }}
- name: nginx
configMap:
items:
- key: config
path: nginx.conf
name: "{{ .Chart.Name }}-nginx"
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
- name: "static"
emptyDir:
sizeLimit: 50Mi
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand All @@ -71,4 +128,4 @@ spec:
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- end }}
20 changes: 16 additions & 4 deletions jenny/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ template "jenny.fullname" . }}-ingress
name: {{ template "jenny.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "jenny.labels" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{ toYaml .Values.commonLabels | nindent 4 }}
{{- end }}
app.kubernetes.io/component: django
{{- if and .Values.commonAnnotations -}}
annotations:
{{- if .Values.commonAnnotations }}
{{- if and .Values.commonAnnotations .Values.ingress.annotations }}
{{- toYaml .Values.commonAnnotations | nindent 4 }}
{{- end }}
{{- if .Values.ingress.annotations }}
{{- toYaml .Values.ingress.annotations | nindent 4 }}
{{- end }}
{{- end }}
spec:
ingressClassName: {{ .Values.ingress.class_name }}
{{- if $.Values.ingress.tls.enabled }}
tls:
- hosts:
- {{ required "A host is required" $.Values.ingress.host }}
secretName: {{ $.Values.ingress.tls.certificateSecretName }}
claudusd marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}
rules:
- http:
- host: {{ required "A host is required" .Values.ingress.host }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: {{ include "jenny.fullname" . }}-service
port:
number: {{ .Values.service.port }}
number: {{ .Values.nginx.port }}
{{- end }}
20 changes: 4 additions & 16 deletions jenny/templates/jobs.yaml
wilbrdt marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{{- range .Values.django.jobs }}
---
apiVersion: batch/v1
kind: Job
metadata:
Expand All @@ -8,46 +9,33 @@ metadata:
{{- if $.Values.commonLabels }}
{{ toYaml $.Values.commonLabels | nindent 4 }}
{{- end }}
app.kubernetes.io/component: jenny
app.kubernetes.io/part-of: {{ $.Chart.Name }}
annotations:
{{- if $.Values.commonAnnotations }}
{{- toYaml $.Values.commonAnnotations | nindent 4 }}
{{- end }}
"helm.sh/hook": pre-upgrade, pre-install
"helm.sh/hook": post-upgrade,post-install
"helm.sh/hook-weight": "0"
spec:
template:
metadata:
labels: {{- include "jenny.selectorLabels" $ | nindent 8 }}
app.kubernetes.io/component: django
spec:
{{- include "django.imagePullSecrets" $ | nindent 6 }}
{{- if $.Values.podSecurityContext }}
securityContext: {{- toYaml $.Values.podSecurityContext | nindent 8 }}
{{- end }}
{{- include "django.imagePullSecrets" $ | nindent 6 -}}
containers:
- name: django-{{ .name }}
image: {{ $.Values.image.repository }}:{{ $.Values.image.tag }}
imagePullPolicy: {{ $.Values.image.pullPolicy }}
env:
{{- include "jenny.envs" $ | nindent 12 }}
command: {{ .command | toJson }}
{{- if $.Values.resources }}
resources: {{ toYaml $.Values.resources | nindent 12 }}
{{- end }}
{{- if $.Values.persistence.enabled }}
volumeMounts:
- name: {{ $.Values.volumes.static.name }}
mountPath: {{ $.Values.volumes.static.mountPath }}
- name: {{ $.Values.volumes.media.name }}
mountPath: {{ $.Values.volumes.media.mountPath }}
volumes:
- name: {{ $.Values.volumes.static.name }}
persistentVolumeClaim:
claimName: {{ $.Values.volumes.static.claimName }}
- name: {{ $.Values.volumes.media.name }}
persistentVolumeClaim:
claimName: {{ $.Values.volumes.media.claimName }}
{{- end }}
restartPolicy: Never
{{- end }}
20 changes: 5 additions & 15 deletions jenny/templates/pvc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ kind: PersistentVolumeClaim
metadata:
name: {{ .Values.volumes.media.claimName }}
namespace: {{ .Release.Namespace | quote }}
spec:
accessModes:
{{ with .Values.persistence.accessModes }}
{{- toYaml . | indent 4 }}
{{- end }}
storageClassName: {{ .Values.persistence.storageClass }}
resources:
requests:
storage: {{ .Values.persistence.size }}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ .Values.volumes.static.claimName }}
namespace: {{ .Release.Namespace | quote }}
labels:
{{- include "jenny.labels" $ | nindent 4 }}
{{- if $.Values.commonLabels }}
{{ toYaml $.Values.commonLabels | nindent 4 }}
{{- end }}
spec:
accessModes:
{{ with .Values.persistence.accessModes }}
Expand Down
Loading