This commit is contained in:
David Burke 2021-05-28 17:32:09 -04:00
parent 6e42f3144e
commit 321911b09b
7 changed files with 94 additions and 14 deletions

View file

@ -1,7 +1,12 @@
image: image:
name: alpine/helm:3.2.4 name: alpine/helm:3.5.4
entrypoint: ["/bin/sh", "-c"] entrypoint: ["/bin/sh", "-c"]
lint:
stage: test
script:
- helm lint
pages: pages:
stage: deploy stage: deploy
script: script:

View file

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2020 GlitchTip Copyright (c) 2021 Burke Software and Consulting LLC
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -1,10 +1,58 @@
# Django Helm Chart # Django Helm Chart
We use this chart internally. However it's not fully documented yet nor tested in a wide range of scenarios. A generic Django (plus Celery) Helm chart.
If you are a helm and kubernetes expert - feel free to use this and help contribute to this repo.
# Preparing your Django app
This chart supports a web plus optional celery and beat deployments. Be prepared to extend it as necessary.
Django settings will be managed by environment variables. `os.getenv` is fine. `django-environ` is nice as well. This chart expects SECRET_KEY and DATABASE_URL variables.
Kubernetes works best when it is able to determine application health. You Django app should have a `/_health/` view such as
```
def health(request):
return HttpResponse("ok", content_type="text/plain")
urlpatterns = [
path("_health/", health),
...
```
# Usage # Usage
1. Add our Helm chart repo `helm repo add glitchtip https://glitchtip.gitlab.io/glitchtip-helm-chart/` 1. Add our Helm chart repo `helm repo add glitchtip https://glitchtip.gitlab.io/glitchtip-helm-chart/`
2. Review our values.yaml. At a minimum you'll need to set DATABASE_URL and SECRET_KEY. 2. Review our values.yaml. At a minimum you'll need to set SECRET_KEY.
3. Install the chart `helm install glitchtip/glitchtip --set databaseURL=your_db --set secretKey=random_string` 3. Install the chart `helm install glitchtip/glitchtip --set databaseURL=your_db --set secretKey=random_string`
# Tips
- Do you really need kubernetes? It's very complex.
- Don't use helm without [helm diff](https://github.com/databus23/helm-diff). One typo will wipe your app without warning otherwise.
- While supported, I don't suggest running stateful services like PostgreSQL in kubernetes. Upgrades will likely involve downtime or extensive and arcane knowledge.
- It's fine to use this chart as a reference for your own chart instead of directly using it.
## Managing environment variables and secrets
I suggest either
- Keep them in a values.yml file in a private repo
- Make use of --reuse-values and --set
- Keep them in a non helm chart managed service
## Deploying in CI
I use lwolf/helm-kubectl-docker with Gitlab CI. [Example](https://gitlab.com/glitchtip/glitchtip-frontend/-/blob/master/.gitlab-ci.yml).
# Support development
Maintaining this chart takes time. Considering supporting it by
- [Donating on liberapay](https://liberapay.com/burke-software/)
- Check out [GlitchTip](https://glitchtip.com) error tracking, which is where this project started
Commercial support is available - email info@burkesoftware.com
# Contributing
Contributions are welcome. Report bugs on gitlab issues. Please only open feature requests that you'd like to implement yourself or pay for.

View file

@ -1,3 +1,4 @@
{{- if .Values.worker.enabled -}}
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -48,3 +49,4 @@ spec:
name: {{ include "django.fullname" . }} name: {{ include "django.fullname" . }}
- configMapRef: - configMapRef:
name: {{ include "django.fullname" . }} name: {{ include "django.fullname" . }}
{{- end }}

View file

@ -1,7 +1,14 @@
{{- if .Values.web.ingress.enabled -}} {{- if .Values.web.ingress.enabled -}}
{{- $fullName := include "django.fullname" . -}} {{- $fullName := include "django.fullname" . -}}
{{- $svcPort := .Values.web.service.port -}} {{- $svcPort := .Values.web.service.port -}}
{{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} {{- if and .Values.web.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.web.ingress.annotations "kubernetes.io/ingress.class") }}
{{- $_ := set .Values.web.ingress.annotations "kubernetes.io/ingress.class" .Values.web.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 apiVersion: networking.k8s.io/v1beta1
{{- else -}} {{- else -}}
apiVersion: extensions/v1beta1 apiVersion: extensions/v1beta1
@ -16,6 +23,9 @@ metadata:
{{- toYaml . | nindent 4 }} {{- toYaml . | nindent 4 }}
{{- end }} {{- end }}
spec: spec:
{{- if and .Values.web.ingress.className (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion) }}
ingressClassName: {{ .Values.web.ingress.className }}
{{- end }}
{{- if .Values.web.ingress.tls }} {{- if .Values.web.ingress.tls }}
tls: tls:
{{- range .Values.web.ingress.tls }} {{- range .Values.web.ingress.tls }}
@ -33,9 +43,19 @@ spec:
paths: paths:
{{- range .paths }} {{- range .paths }}
- path: {{ .path }} - path: {{ .path }}
{{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }}
pathType: {{ .pathType }}
{{- end }}
backend: backend:
serviceName: {{ $fullName }}-web {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }}
service:
name: {{ $fullName }}
port:
number: {{ $svcPort }}
{{- else }}
serviceName: {{ $fullName }}
servicePort: {{ $svcPort }} servicePort: {{ $svcPort }}
{{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}
{{- end }} {{- end }}

View file

@ -1,3 +1,4 @@
{{- if .Values.worker.enabled -}}
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -55,3 +56,4 @@ spec:
tolerations: tolerations:
{{- toYaml . | nindent 8 }} {{- toYaml . | nindent 8 }}
{{- end }} {{- end }}
{{- end }}

View file

@ -12,8 +12,8 @@ nameOverride: ""
fullnameOverride: "" fullnameOverride: ""
env: env:
normal: [] normal: {}
secrets: [] secret: {}
# SECRET_KEY: # SECRET_KEY:
# DATABASE_URL: # DATABASE_URL:
# REDIS_URL: # REDIS_URL:
@ -38,7 +38,7 @@ web:
memory: 128Mi memory: 128Mi
nodeSelector: {} nodeSelector: {}
tolerations: [] tolerations: []
affinity: [] affinity: {}
# podAntiAffinity: # podAntiAffinity:
# preferredDuringSchedulingIgnoredDuringExecution: # preferredDuringSchedulingIgnoredDuringExecution:
# - weight: 100 # - weight: 100
@ -64,19 +64,22 @@ web:
ingress: ingress:
enabled: false enabled: false
annotations: className: ""
{} annotations: {}
# kubernetes.io/ingress.class: nginx # kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true" # kubernetes.io/tls-acme: "true"
hosts: hosts:
- host: chart-example.local - host: chart-example.local
paths: [] paths:
- path: /
pathType: ImplementationSpecific
tls: [] tls: []
# - secretName: chart-example-tls # - secretName: chart-example-tls
# hosts: # hosts:
# - chart-example.local # - chart-example.local
worker: worker:
enabled: true
replicaCount: 1 replicaCount: 1
autoscaling: autoscaling:
enabled: false enabled: false