From 321911b09b669a0d1d106e92e308f53ab8d987d4 Mon Sep 17 00:00:00 2001 From: David Burke Date: Fri, 28 May 2021 17:32:09 -0400 Subject: [PATCH] update --- .gitlab-ci.yml | 7 ++++- LICENSE | 2 +- README.md | 54 ++++++++++++++++++++++++++++++-- templates/beat/deployment.yaml | 2 ++ templates/web/ingress.yaml | 26 +++++++++++++-- templates/worker/deployment.yaml | 2 ++ values.yaml | 15 +++++---- 7 files changed, 94 insertions(+), 14 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f305358..81d3111 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,12 @@ image: - name: alpine/helm:3.2.4 + name: alpine/helm:3.5.4 entrypoint: ["/bin/sh", "-c"] +lint: + stage: test + script: + - helm lint + pages: stage: deploy script: diff --git a/LICENSE b/LICENSE index 0d30bd7..d9899a0 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ 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 of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 76de6a3..1e6613d 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,58 @@ # Django Helm Chart -We use this chart internally. However it's not fully documented yet nor tested in a wide range of scenarios. -If you are a helm and kubernetes expert - feel free to use this and help contribute to this repo. +A generic Django (plus Celery) Helm chart. + +# 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 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` + +# 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. \ No newline at end of file diff --git a/templates/beat/deployment.yaml b/templates/beat/deployment.yaml index bdebde3..4112037 100644 --- a/templates/beat/deployment.yaml +++ b/templates/beat/deployment.yaml @@ -1,3 +1,4 @@ +{{- if .Values.worker.enabled -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -48,3 +49,4 @@ spec: name: {{ include "django.fullname" . }} - configMapRef: name: {{ include "django.fullname" . }} +{{- end }} \ No newline at end of file diff --git a/templates/web/ingress.yaml b/templates/web/ingress.yaml index 3f9860d..c9f7e0f 100644 --- a/templates/web/ingress.yaml +++ b/templates/web/ingress.yaml @@ -1,7 +1,14 @@ {{- if .Values.web.ingress.enabled -}} {{- $fullName := include "django.fullname" . -}} {{- $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 {{- else -}} apiVersion: extensions/v1beta1 @@ -16,6 +23,9 @@ metadata: {{- toYaml . | nindent 4 }} {{- end }} 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 }} tls: {{- range .Values.web.ingress.tls }} @@ -33,9 +43,19 @@ spec: paths: {{- range .paths }} - path: {{ .path }} + {{- if and .pathType (semverCompare ">=1.18-0" $.Capabilities.KubeVersion.GitVersion) }} + pathType: {{ .pathType }} + {{- end }} backend: - serviceName: {{ $fullName }}-web + {{- if semverCompare ">=1.19-0" $.Capabilities.KubeVersion.GitVersion }} + service: + name: {{ $fullName }} + port: + number: {{ $svcPort }} + {{- else }} + serviceName: {{ $fullName }} servicePort: {{ $svcPort }} + {{- end }} {{- end }} {{- end }} - {{- end }} +{{- end }} diff --git a/templates/worker/deployment.yaml b/templates/worker/deployment.yaml index ddcccd8..f37a890 100644 --- a/templates/worker/deployment.yaml +++ b/templates/worker/deployment.yaml @@ -1,3 +1,4 @@ +{{- if .Values.worker.enabled -}} apiVersion: apps/v1 kind: Deployment metadata: @@ -55,3 +56,4 @@ spec: tolerations: {{- toYaml . | nindent 8 }} {{- end }} +{{- end }} \ No newline at end of file diff --git a/values.yaml b/values.yaml index dc72eff..6e90721 100644 --- a/values.yaml +++ b/values.yaml @@ -12,8 +12,8 @@ nameOverride: "" fullnameOverride: "" env: - normal: [] - secrets: [] + normal: {} + secret: {} # SECRET_KEY: # DATABASE_URL: # REDIS_URL: @@ -38,7 +38,7 @@ web: memory: 128Mi nodeSelector: {} tolerations: [] - affinity: [] + affinity: {} # podAntiAffinity: # preferredDuringSchedulingIgnoredDuringExecution: # - weight: 100 @@ -64,19 +64,22 @@ web: ingress: enabled: false - annotations: - {} + className: "" + annotations: {} # kubernetes.io/ingress.class: nginx # kubernetes.io/tls-acme: "true" hosts: - host: chart-example.local - paths: [] + paths: + - path: / + pathType: ImplementationSpecific tls: [] # - secretName: chart-example-tls # hosts: # - chart-example.local worker: + enabled: true replicaCount: 1 autoscaling: enabled: false