From 3077a1d304c2d6b57771e78976420c6ab0c8f059 Mon Sep 17 00:00:00 2001 From: David Burke Date: Sun, 7 Feb 2021 16:48:32 -0500 Subject: [PATCH 1/6] Update to autoscaling/v2beta1 syntax for hpa --- templates/web-hpa.yaml | 29 +++++++++++++++++++---------- templates/worker-hpa.yaml | 33 +++++++++++++++++++++------------ values.yaml | 19 +++++++++++-------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/templates/web-hpa.yaml b/templates/web-hpa.yaml index f24629d..d737434 100644 --- a/templates/web-hpa.yaml +++ b/templates/web-hpa.yaml @@ -1,19 +1,28 @@ -{{- if .Values.web.hpa.enabled -}} -apiVersion: autoscaling/v1 +{{- if .Values.web.autoscaling.enabled -}} +apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: name: {{ template "glitchtip.fullname" . }} labels: - app: {{ template "glitchtip.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + {{- include "glitchtip.labels" . | nindent 4 }} spec: scaleTargetRef: - kind: Deployment apiVersion: apps/v1 + kind: Deployment name: {{ template "glitchtip.fullname" . }} - minReplicas: {{ .Values.web.hpa.minpods }} - maxReplicas: {{ .Values.web.hpa.maxpods }} - targetCPUUtilizationPercentage: {{ .Values.web.hpa.cputhreshold }} + minReplicas: {{ .Values.web.autoscaling.minReplicas }} + maxReplicas: {{ .Values.web.autoscaling.maxReplicas }} + metrics: + {{- if .Values.web.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.web.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.web.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.web.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} {{- end }} diff --git a/templates/worker-hpa.yaml b/templates/worker-hpa.yaml index 237977b..0e463d2 100644 --- a/templates/worker-hpa.yaml +++ b/templates/worker-hpa.yaml @@ -1,19 +1,28 @@ -{{- if .Values.worker.hpa.enabled -}} -apiVersion: autoscaling/v1 +{{- if .Values.worker.autoscaling.enabled -}} +apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ template "glitchtip.fullname" . }}-worker + name: {{ template "glitchtip.fullname" . }} labels: - app: {{ template "glitchtip.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" + {{- include "glitchtip.labels" . | nindent 4 }} spec: scaleTargetRef: - kind: Deployment apiVersion: apps/v1 + kind: Deployment name: {{ template "glitchtip.fullname" . }}-worker - minReplicas: {{ .Values.worker.hpa.minpods }} - maxReplicas: {{ .Values.worker.hpa.maxpods }} - targetCPUUtilizationPercentage: {{ .Values.worker.hpa.cputhreshold }} -{{- end }} + minReplicas: {{ .Values.worker.autoscaling.minReplicas }} + maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }} + metrics: + {{- if .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .Values.worker.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .Values.worker.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} \ No newline at end of file diff --git a/values.yaml b/values.yaml index 28a0043..dc36b1a 100644 --- a/values.yaml +++ b/values.yaml @@ -23,11 +23,13 @@ environmentVariables: web: replicaCount: 1 - hpa: + autoscaling: enabled: false - cputhreshold: 70 - minpods: 2 - maxpods: 4 + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + # budget: # minAvailable: 1 resources: @@ -52,11 +54,12 @@ web: worker: replicaCount: 1 - hpa: + autoscaling: enabled: false - cputhreshold: 90 - minpods: 1 - maxpods: 4 + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 90 + # targetMemoryUtilizationPercentage: 80 resources: {} # limits: From e957cae6dedb00cc0abe8d5fbb680a26442ce4a0 Mon Sep 17 00:00:00 2001 From: David Burke Date: Fri, 12 Feb 2021 17:18:07 -0500 Subject: [PATCH 2/6] Folders for components --- templates/NOTES.txt | 14 +++---- templates/{ => beat}/deployment-beat.yaml | 7 ++-- templates/serviceaccount.yaml | 8 +++- templates/tests/test-connection.yaml | 4 +- templates/{ => web}/deployment.yaml | 15 ++++---- templates/{web-hpa.yaml => web/hpa.yaml} | 2 +- templates/{ => web}/ingress.yaml | 18 +++++---- templates/{ => web}/pdb.yaml | 4 +- templates/{ => web}/service.yaml | 8 ++-- .../deployment.yaml} | 7 ++-- .../{worker-hpa.yaml => worker/hpa.yaml} | 0 values.yaml | 37 +++++++++---------- 12 files changed, 63 insertions(+), 61 deletions(-) rename templates/{ => beat}/deployment-beat.yaml (94%) rename templates/{ => web}/deployment.yaml (92%) rename templates/{web-hpa.yaml => web/hpa.yaml} (94%) rename templates/{ => web}/ingress.yaml (65%) rename templates/{ => web}/pdb.yaml (80%) rename templates/{ => web}/service.yaml (59%) rename templates/{deployment-worker.yaml => worker/deployment.yaml} (95%) rename templates/{worker-hpa.yaml => worker/hpa.yaml} (100%) diff --git a/templates/NOTES.txt b/templates/NOTES.txt index cee67c0..db1c870 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -1,20 +1,20 @@ 1. Get the application URL by running these commands: -{{- if .Values.ingress.enabled }} -{{- range $host := .Values.ingress.hosts }} +{{- if .Values.web.ingress.enabled }} +{{- range $host := .Values.web.ingress.hosts }} {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} -{{- else if contains "NodePort" .Values.service.type }} +{{- else if contains "NodePort" .Values.web.service.type }} export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "glitchtip.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT -{{- else if contains "LoadBalancer" .Values.service.type }} +{{- else if contains "LoadBalancer" .Values.web.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "glitchtip.fullname" . }}' export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "glitchtip.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") - echo http://$SERVICE_IP:{{ .Values.service.port }} -{{- else if contains "ClusterIP" .Values.service.type }} + echo http://$SERVICE_IP:{{ .Values.web.service.port }} +{{- else if contains "ClusterIP" .Values.web.service.type }} export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "glitchtip.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80 diff --git a/templates/deployment-beat.yaml b/templates/beat/deployment-beat.yaml similarity index 94% rename from templates/deployment-beat.yaml rename to templates/beat/deployment-beat.yaml index 1f17584..e6d05f8 100644 --- a/templates/deployment-beat.yaml +++ b/templates/beat/deployment-beat.yaml @@ -4,11 +4,13 @@ metadata: name: {{ include "glitchtip.fullname" . }}-beat labels: {{- include "glitchtip.labels" . | nindent 4 }} + app.kubernetes.io/component: beat spec: replicas: 1 selector: matchLabels: {{- include "glitchtip.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: beat template: metadata: annotations: @@ -17,6 +19,7 @@ spec: tag: "{{ .Values.image.tag }}" labels: {{- include "glitchtip.selectorLabels" . | nindent 8 }} + app.kubernetes.io/component: beat spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -38,10 +41,6 @@ spec: cpu: 1m memory: 32Mi env: - - name: DEBUG - value: "False" - - name: STATIC_URL - value: / - name: SERVER_ROLE value: "beat" {{- if .Values.redisURL }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index 07b2921..747e8a8 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -4,5 +4,9 @@ kind: ServiceAccount metadata: name: {{ include "glitchtip.serviceAccountName" . }} labels: -{{ include "glitchtip.labels" . | nindent 4 }} -{{- end -}} + {{- include "glitchtip.labels" . | nindent 4 }} + {{- with .Values.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/templates/tests/test-connection.yaml b/templates/tests/test-connection.yaml index 2288891..bee5224 100644 --- a/templates/tests/test-connection.yaml +++ b/templates/tests/test-connection.yaml @@ -5,11 +5,11 @@ metadata: labels: {{ include "glitchtip.labels" . | nindent 4 }} annotations: - "helm.sh/hook": test-success + "helm.sh/hook": test spec: containers: - name: wget image: busybox command: ['wget'] - args: ['{{ include "glitchtip.fullname" . }}:{{ .Values.service.port }}'] + args: ['{{ include "glitchtip.fullname" . }}:{{ .Values.web.service.port }}'] restartPolicy: Never diff --git a/templates/deployment.yaml b/templates/web/deployment.yaml similarity index 92% rename from templates/deployment.yaml rename to templates/web/deployment.yaml index 097e367..94fbdcd 100644 --- a/templates/deployment.yaml +++ b/templates/web/deployment.yaml @@ -1,15 +1,18 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "glitchtip.fullname" . }}-web labels: {{- include "glitchtip.labels" . | nindent 4 }} + app.kubernetes.io/component: web spec: + {{- if not .Values.web.autoscaling.enabled }} replicas: {{ .Values.web.replicaCount }} + {{- end }} selector: matchLabels: {{- include "glitchtip.selectorLabels" . | nindent 6 }} - role: web + app.kubernetes.io/component: web template: metadata: annotations: @@ -18,7 +21,7 @@ spec: tag: "{{ .Values.image.tag }}" labels: {{- include "glitchtip.selectorLabels" . | nindent 8 }} - role: web + app.kubernetes.io/component: web spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -31,7 +34,7 @@ spec: - name: {{ .Chart.Name }} securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.image.pullPolicy }} ports: - name: http @@ -54,10 +57,6 @@ spec: resources: {{- toYaml .Values.web.resources | nindent 12 }} env: - - name: DEBUG - value: "False" - - name: STATIC_URL - value: / {{- if .Values.redisURL }} - name: REDIS_URL value: {{ .Values.redisURL }} diff --git a/templates/web-hpa.yaml b/templates/web/hpa.yaml similarity index 94% rename from templates/web-hpa.yaml rename to templates/web/hpa.yaml index d737434..f8c15b9 100644 --- a/templates/web-hpa.yaml +++ b/templates/web/hpa.yaml @@ -9,7 +9,7 @@ spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ template "glitchtip.fullname" . }} + name: {{ template "glitchtip.fullname" . }}-web minReplicas: {{ .Values.web.autoscaling.minReplicas }} maxReplicas: {{ .Values.web.autoscaling.maxReplicas }} metrics: diff --git a/templates/ingress.yaml b/templates/web/ingress.yaml similarity index 65% rename from templates/ingress.yaml rename to templates/web/ingress.yaml index 44cef26..d274e7e 100644 --- a/templates/ingress.yaml +++ b/templates/web/ingress.yaml @@ -1,6 +1,6 @@ -{{- if .Values.ingress.enabled -}} +{{- if .Values.web.ingress.enabled -}} {{- $fullName := include "glitchtip.fullname" . -}} -{{- $svcPort := .Values.service.port -}} +{{- $svcPort := .Values.web.service.port -}} {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 {{- else -}} @@ -11,14 +11,14 @@ metadata: name: {{ $fullName }} labels: {{- include "glitchtip.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} + {{- with .Values.web.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} spec: - {{- if .Values.ingress.tls }} + {{- if .Values.web.ingress.tls }} tls: - {{- range .Values.ingress.tls }} + {{- range .Values.web.ingress.tls }} - hosts: {{- range .hosts }} - {{ . | quote }} @@ -27,13 +27,15 @@ spec: {{- end }} {{- end }} rules: - {{- range .Values.ingress.hosts }} + {{- range .Values.web.ingress.hosts }} - host: {{ .host | quote }} http: paths: - - pathType: ImplementationSpecific + {{- range .paths }} + - path: {{ .path }} backend: - serviceName: {{ $fullName }} + serviceName: {{ $fullName }}-web servicePort: {{ $svcPort }} + {{- end }} {{- end }} {{- end }} diff --git a/templates/pdb.yaml b/templates/web/pdb.yaml similarity index 80% rename from templates/pdb.yaml rename to templates/web/pdb.yaml index 781536f..c6b2d60 100644 --- a/templates/pdb.yaml +++ b/templates/web/pdb.yaml @@ -3,7 +3,7 @@ apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "glitchtip.fullname" . }}-web labels: {{- include "glitchtip.labels" . | nindent 4 }} spec: @@ -11,6 +11,6 @@ spec: selector: matchLabels: {{- include "glitchtip.selectorLabels" . | nindent 6 }} - role: web + app.kubernetes.io/component: web {{- end -}} {{- end -}} diff --git a/templates/service.yaml b/templates/web/service.yaml similarity index 59% rename from templates/service.yaml rename to templates/web/service.yaml index a8c4adc..f3394c7 100644 --- a/templates/service.yaml +++ b/templates/web/service.yaml @@ -1,16 +1,16 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "glitchtip.fullname" . }}-web labels: {{- include "glitchtip.labels" . | nindent 4 }} spec: - type: {{ .Values.service.type }} + type: {{ .Values.web.service.type }} ports: - - port: {{ .Values.service.port }} + - port: {{ .Values.web.service.port }} targetPort: http protocol: TCP name: http selector: {{- include "glitchtip.selectorLabels" . | nindent 4 }} - role: web \ No newline at end of file + app.kubernetes.io/component: web \ No newline at end of file diff --git a/templates/deployment-worker.yaml b/templates/worker/deployment.yaml similarity index 95% rename from templates/deployment-worker.yaml rename to templates/worker/deployment.yaml index f55c8c0..3d43c7e 100644 --- a/templates/deployment-worker.yaml +++ b/templates/worker/deployment.yaml @@ -4,11 +4,13 @@ metadata: name: {{ include "glitchtip.fullname" . }}-worker labels: {{- include "glitchtip.labels" . | nindent 4 }} + app.kubernetes.io/component: worker spec: replicas: {{ .Values.worker.replicaCount }} selector: matchLabels: {{- include "glitchtip.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: worker template: metadata: annotations: @@ -17,6 +19,7 @@ spec: tag: "{{ .Values.image.tag }}" labels: {{- include "glitchtip.selectorLabels" . | nindent 8 }} + app.kubernetes.io/component: worker spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: @@ -33,10 +36,6 @@ spec: resources: {{- toYaml .Values.worker.resources | nindent 12 }} env: - - name: DEBUG - value: "False" - - name: STATIC_URL - value: / - name: SERVER_ROLE value: "worker" {{- if .Values.redisURL }} diff --git a/templates/worker-hpa.yaml b/templates/worker/hpa.yaml similarity index 100% rename from templates/worker-hpa.yaml rename to templates/worker/hpa.yaml diff --git a/values.yaml b/values.yaml index dc36b1a..ec22247 100644 --- a/values.yaml +++ b/values.yaml @@ -31,7 +31,7 @@ web: # targetMemoryUtilizationPercentage: 80 # budget: - # minAvailable: 1 + # minAvailable: 1 resources: {} # limits: @@ -51,6 +51,23 @@ web: failureThreshold: 10 initialDelaySeconds: 5 timeoutSeconds: 2 + service: + type: ClusterIP + port: 80 + + ingress: + enabled: false + annotations: + {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: [] + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local worker: replicaCount: 1 @@ -79,24 +96,6 @@ serviceAccount: # If not set and create is true, a name is generated using the fullname template name: -service: - type: ClusterIP - port: 80 - -ingress: - enabled: false - annotations: - {} - # kubernetes.io/ingress.class: nginx - # kubernetes.io/tls-acme: "true" - hosts: - - host: chart-example.local - paths: [] - tls: [] - # - secretName: chart-example-tls - # hosts: - # - chart-example.local - redis: enabled: true master: From 883d0c6d209175f334299396fb0132da494a2135 Mon Sep 17 00:00:00 2001 From: David Burke Date: Fri, 12 Feb 2021 17:39:59 -0500 Subject: [PATCH 3/6] Use more generic name "django" instead of glitchtip for template variables --- templates/NOTES.txt | 8 +++--- templates/_helpers.tpl | 38 ++++++++++++++-------------- templates/beat/deployment-beat.yaml | 18 ++++++------- templates/configmap.yaml | 4 +-- templates/pre-install-job.yaml | 4 +-- templates/secrets.yaml | 4 +-- templates/serviceaccount.yaml | 4 +-- templates/tests/test-connection.yaml | 6 ++--- templates/web/deployment.yaml | 20 +++++++-------- templates/web/hpa.yaml | 6 ++--- templates/web/ingress.yaml | 4 +-- templates/web/pdb.yaml | 6 ++--- templates/web/service.yaml | 6 ++--- templates/worker/deployment.yaml | 18 ++++++------- templates/worker/hpa.yaml | 6 ++--- 15 files changed, 76 insertions(+), 76 deletions(-) diff --git a/templates/NOTES.txt b/templates/NOTES.txt index db1c870..1f601e1 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -6,16 +6,16 @@ {{- end }} {{- end }} {{- else if contains "NodePort" .Values.web.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "glitchtip.fullname" . }}) + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "django.fullname" . }}) export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") echo http://$NODE_IP:$NODE_PORT {{- else if contains "LoadBalancer" .Values.web.service.type }} NOTE: It may take a few minutes for the LoadBalancer IP to be available. - You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "glitchtip.fullname" . }}' - export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "glitchtip.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "django.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "django.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") echo http://$SERVICE_IP:{{ .Values.web.service.port }} {{- else if contains "ClusterIP" .Values.web.service.type }} - export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "glitchtip.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "django.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") echo "Visit http://127.0.0.1:8080 to use your application" kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:80 {{- end }} diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl index c12e95b..2734712 100644 --- a/templates/_helpers.tpl +++ b/templates/_helpers.tpl @@ -2,7 +2,7 @@ {{/* Expand the name of the chart. */}} -{{- define "glitchtip.name" -}} +{{- define "django.name" -}} {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} {{- end -}} @@ -11,7 +11,7 @@ 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 "glitchtip.fullname" -}} +{{- define "django.fullname" -}} {{- if .Values.fullnameOverride -}} {{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} {{- else -}} @@ -27,16 +27,16 @@ If release name contains chart name it will be used as a full name. {{/* Create chart name and version as used by the chart label. */}} -{{- define "glitchtip.chart" -}} +{{- define "django.chart" -}} {{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{/* Common labels */}} -{{- define "glitchtip.labels" -}} -helm.sh/chart: {{ include "glitchtip.chart" . }} -{{ include "glitchtip.selectorLabels" . }} +{{- define "django.labels" -}} +helm.sh/chart: {{ include "django.chart" . }} +{{ include "django.selectorLabels" . }} {{- if .Chart.AppVersion }} app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} {{- end }} @@ -46,17 +46,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }} {{/* Selector labels */}} -{{- define "glitchtip.selectorLabels" -}} -app.kubernetes.io/name: {{ include "glitchtip.name" . }} +{{- define "django.selectorLabels" -}} +app.kubernetes.io/name: {{ include "django.name" . }} app.kubernetes.io/instance: {{ .Release.Name }} {{- end -}} {{/* Create the name of the service account to use */}} -{{- define "glitchtip.serviceAccountName" -}} +{{- define "django.serviceAccountName" -}} {{- if .Values.serviceAccount.create -}} - {{ default (include "glitchtip.fullname" .) .Values.serviceAccount.name }} + {{ default (include "django.fullname" .) .Values.serviceAccount.name }} {{- else -}} {{ default "default" .Values.serviceAccount.name }} {{- end -}} @@ -66,7 +66,7 @@ Create the name of the service account to use 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). */}} -{{- define "glitchtip.postgresql.fullname" -}} +{{- define "django.postgresql.fullname" -}} {{- if .Values.postgresql.fullnameOverride -}} {{- .Values.postgresql.fullnameOverride | trunc 63 | trimSuffix "-" -}} {{- else -}} @@ -74,11 +74,11 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- if contains $name .Release.Name -}} {{- .Release.Name | trunc 63 | trimSuffix "-" -}} {{- else -}} -{{- printf "%s-%s" .Release.Name "glitchtip-postgresql" | trunc 63 | trimSuffix "-" -}} +{{- printf "%s-%s" .Release.Name "django-postgresql" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{- end -}} {{- end -}} -{{- define "glitchtip.redis.fullname" -}} +{{- define "django.redis.fullname" -}} {{- if .Values.redis.fullnameOverride -}} {{- .Values.redis.fullnameOverride | trunc 63 | trimSuffix "-" -}} {{- else -}} @@ -86,7 +86,7 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{- if contains $name .Release.Name -}} {{- .Release.Name | trunc 63 | trimSuffix "-" -}} {{- else -}} -{{- printf "%s-%s" .Release.Name "glitchtip-redis" | trunc 63 | trimSuffix "-" -}} +{{- printf "%s-%s" .Release.Name "django-redis" | trunc 63 | trimSuffix "-" -}} {{- end -}} {{- end -}} {{- end -}} @@ -94,9 +94,9 @@ We truncate at 63 chars because some Kubernetes name fields are limited to this {{/* Set redis host */}} -{{- define "glitchtip.redis.host" -}} +{{- define "django.redis.host" -}} {{- if .Values.redis.enabled -}} -{{- template "glitchtip.redis.fullname" . -}}-redis-master +{{- template "django.redis.fullname" . -}}-redis-master {{- else -}} {{- .Values.redis.host | quote -}} {{- end -}} @@ -105,16 +105,16 @@ Set redis host {{/* Set redis url */}} -{{- define "glitchtip.redis.url" -}} +{{- define "django.redis.url" -}} {{- if .Values.redis.enabled -}} -redis://{{- template "glitchtip.redis.password" -}}{{- template "glitchtip.redis.fullname" . -}}-master +redis://{{- template "django.redis.password" -}}{{- template "django.redis.fullname" . -}}-master {{- end -}} {{- end -}} {{/* Set redis port */}} -{{- define "glitchtip.redis.port" -}} +{{- define "django.redis.port" -}} {{- if .Values.redis.enabled -}} "6379" {{- else -}} diff --git a/templates/beat/deployment-beat.yaml b/templates/beat/deployment-beat.yaml index e6d05f8..5a15e24 100644 --- a/templates/beat/deployment-beat.yaml +++ b/templates/beat/deployment-beat.yaml @@ -1,15 +1,15 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "glitchtip.fullname" . }}-beat + name: {{ include "django.fullname" . }}-beat labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} app.kubernetes.io/component: beat spec: replicas: 1 selector: matchLabels: - {{- include "glitchtip.selectorLabels" . | nindent 6 }} + {{- include "django.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: beat template: metadata: @@ -18,7 +18,7 @@ spec: checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} tag: "{{ .Values.image.tag }}" labels: - {{- include "glitchtip.selectorLabels" . | nindent 8 }} + {{- include "django.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: beat spec: {{- with .Values.imagePullSecrets }} @@ -52,14 +52,14 @@ spec: valueFrom: secretKeyRef: key: redis-password - name: {{ include "glitchtip.fullname" . }}-redis + name: {{ include "django.fullname" . }}-redis - name: REDIS_HOST - value: {{ template "glitchtip.redis.host" . }} + value: {{ template "django.redis.host" . }} - name: REDIS_PORT - value: {{ template "glitchtip.redis.port" . }} + value: {{ template "django.redis.port" . }} {{- end }} envFrom: - secretRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} - configMapRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} diff --git a/templates/configmap.yaml b/templates/configmap.yaml index fe76fc1..6b57ab6 100644 --- a/templates/configmap.yaml +++ b/templates/configmap.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: ConfigMap metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} annotations: "helm.sh/hook-weight": "-1" data: diff --git a/templates/pre-install-job.yaml b/templates/pre-install-job.yaml index 9d55992..e539a9e 100644 --- a/templates/pre-install-job.yaml +++ b/templates/pre-install-job.yaml @@ -1,9 +1,9 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} annotations: "helm.sh/hook": post-install,pre-upgrade "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded diff --git a/templates/secrets.yaml b/templates/secrets.yaml index 9fcb4c0..505738f 100644 --- a/templates/secrets.yaml +++ b/templates/secrets.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Secret metadata: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} type: Opaque data: DATABASE_URL: {{ required "databaseURL is a required value." .Values.databaseURL | b64enc | quote }} diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index 747e8a8..c686c91 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -2,9 +2,9 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "glitchtip.serviceAccountName" . }} + name: {{ include "django.serviceAccountName" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} {{- with .Values.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/templates/tests/test-connection.yaml b/templates/tests/test-connection.yaml index bee5224..e3023e4 100644 --- a/templates/tests/test-connection.yaml +++ b/templates/tests/test-connection.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Pod metadata: - name: "{{ include "glitchtip.fullname" . }}-test-connection" + name: "{{ include "django.fullname" . }}-test-connection" labels: -{{ include "glitchtip.labels" . | nindent 4 }} +{{ include "django.labels" . | nindent 4 }} annotations: "helm.sh/hook": test spec: @@ -11,5 +11,5 @@ spec: - name: wget image: busybox command: ['wget'] - args: ['{{ include "glitchtip.fullname" . }}:{{ .Values.web.service.port }}'] + args: ['{{ include "django.fullname" . }}:{{ .Values.web.service.port }}'] restartPolicy: Never diff --git a/templates/web/deployment.yaml b/templates/web/deployment.yaml index 94fbdcd..8d109d3 100644 --- a/templates/web/deployment.yaml +++ b/templates/web/deployment.yaml @@ -1,9 +1,9 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "glitchtip.fullname" . }}-web + name: {{ include "django.fullname" . }}-web labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} app.kubernetes.io/component: web spec: {{- if not .Values.web.autoscaling.enabled }} @@ -11,7 +11,7 @@ spec: {{- end }} selector: matchLabels: - {{- include "glitchtip.selectorLabels" . | nindent 6 }} + {{- include "django.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: web template: metadata: @@ -20,14 +20,14 @@ spec: checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} tag: "{{ .Values.image.tag }}" labels: - {{- include "glitchtip.selectorLabels" . | nindent 8 }} + {{- include "django.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: web spec: {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} - serviceAccountName: {{ include "glitchtip.serviceAccountName" . }} + serviceAccountName: {{ include "django.serviceAccountName" . }} securityContext: {{- toYaml .Values.podSecurityContext | nindent 8 }} containers: @@ -66,11 +66,11 @@ spec: valueFrom: secretKeyRef: key: redis-password - name: {{ include "glitchtip.fullname" . }}-redis + name: {{ include "django.fullname" . }}-redis - name: REDIS_HOST - value: {{ template "glitchtip.redis.host" . }} + value: {{ template "django.redis.host" . }} - name: REDIS_PORT - value: {{ template "glitchtip.redis.port" . }} + value: {{ template "django.redis.port" . }} {{- end }} - name: POD_IP valueFrom: @@ -78,9 +78,9 @@ spec: fieldPath: status.podIP envFrom: - secretRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} - configMapRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} {{- with .Values.web.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/templates/web/hpa.yaml b/templates/web/hpa.yaml index f8c15b9..1d26cec 100644 --- a/templates/web/hpa.yaml +++ b/templates/web/hpa.yaml @@ -2,14 +2,14 @@ apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ template "glitchtip.fullname" . }} + name: {{ template "django.fullname" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ template "glitchtip.fullname" . }}-web + name: {{ template "django.fullname" . }}-web minReplicas: {{ .Values.web.autoscaling.minReplicas }} maxReplicas: {{ .Values.web.autoscaling.maxReplicas }} metrics: diff --git a/templates/web/ingress.yaml b/templates/web/ingress.yaml index d274e7e..3f9860d 100644 --- a/templates/web/ingress.yaml +++ b/templates/web/ingress.yaml @@ -1,5 +1,5 @@ {{- if .Values.web.ingress.enabled -}} -{{- $fullName := include "glitchtip.fullname" . -}} +{{- $fullName := include "django.fullname" . -}} {{- $svcPort := .Values.web.service.port -}} {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 @@ -10,7 +10,7 @@ kind: Ingress metadata: name: {{ $fullName }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} {{- with .Values.web.ingress.annotations }} annotations: {{- toYaml . | nindent 4 }} diff --git a/templates/web/pdb.yaml b/templates/web/pdb.yaml index c6b2d60..e0376b2 100644 --- a/templates/web/pdb.yaml +++ b/templates/web/pdb.yaml @@ -3,14 +3,14 @@ apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: - name: {{ include "glitchtip.fullname" . }}-web + name: {{ include "django.fullname" . }}-web labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} spec: minAvailable: {{ .Values.web.budget.minAvailable }} selector: matchLabels: - {{- include "glitchtip.selectorLabels" . | nindent 6 }} + {{- include "django.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: web {{- end -}} {{- end -}} diff --git a/templates/web/service.yaml b/templates/web/service.yaml index f3394c7..8eb3fc5 100644 --- a/templates/web/service.yaml +++ b/templates/web/service.yaml @@ -1,9 +1,9 @@ apiVersion: v1 kind: Service metadata: - name: {{ include "glitchtip.fullname" . }}-web + name: {{ include "django.fullname" . }}-web labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} spec: type: {{ .Values.web.service.type }} ports: @@ -12,5 +12,5 @@ spec: protocol: TCP name: http selector: - {{- include "glitchtip.selectorLabels" . | nindent 4 }} + {{- include "django.selectorLabels" . | nindent 4 }} app.kubernetes.io/component: web \ No newline at end of file diff --git a/templates/worker/deployment.yaml b/templates/worker/deployment.yaml index 3d43c7e..da6a4f6 100644 --- a/templates/worker/deployment.yaml +++ b/templates/worker/deployment.yaml @@ -1,15 +1,15 @@ apiVersion: apps/v1 kind: Deployment metadata: - name: {{ include "glitchtip.fullname" . }}-worker + name: {{ include "django.fullname" . }}-worker labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} app.kubernetes.io/component: worker spec: replicas: {{ .Values.worker.replicaCount }} selector: matchLabels: - {{- include "glitchtip.selectorLabels" . | nindent 6 }} + {{- include "django.selectorLabels" . | nindent 6 }} app.kubernetes.io/component: worker template: metadata: @@ -18,7 +18,7 @@ spec: checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} tag: "{{ .Values.image.tag }}" labels: - {{- include "glitchtip.selectorLabels" . | nindent 8 }} + {{- include "django.selectorLabels" . | nindent 8 }} app.kubernetes.io/component: worker spec: {{- with .Values.imagePullSecrets }} @@ -47,17 +47,17 @@ spec: valueFrom: secretKeyRef: key: redis-password - name: {{ include "glitchtip.fullname" . }}-redis + name: {{ include "django.fullname" . }}-redis - name: REDIS_HOST - value: {{ template "glitchtip.redis.host" . }} + value: {{ template "django.redis.host" . }} - name: REDIS_PORT - value: {{ template "glitchtip.redis.port" . }} + value: {{ template "django.redis.port" . }} {{- end }} envFrom: - secretRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} - configMapRef: - name: {{ include "glitchtip.fullname" . }} + name: {{ include "django.fullname" . }} {{- with .Values.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} diff --git a/templates/worker/hpa.yaml b/templates/worker/hpa.yaml index 0e463d2..f93531f 100644 --- a/templates/worker/hpa.yaml +++ b/templates/worker/hpa.yaml @@ -2,14 +2,14 @@ apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ template "glitchtip.fullname" . }} + name: {{ template "django.fullname" . }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} + {{- include "django.labels" . | nindent 4 }} spec: scaleTargetRef: apiVersion: apps/v1 kind: Deployment - name: {{ template "glitchtip.fullname" . }}-worker + name: {{ template "django.fullname" . }}-worker minReplicas: {{ .Values.worker.autoscaling.minReplicas }} maxReplicas: {{ .Values.worker.autoscaling.maxReplicas }} metrics: From 8fbe8a5d02854ad4fe4eb9c9dc87c14d1618992d Mon Sep 17 00:00:00 2001 From: David Burke Date: Fri, 12 Feb 2021 22:23:40 -0500 Subject: [PATCH 4/6] Various fixes including autoscaling --- templates/NOTES.txt | 2 +- templates/web/hpa.yaml | 2 +- templates/worker/deployment.yaml | 6 +++--- templates/worker/hpa.yaml | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/templates/NOTES.txt b/templates/NOTES.txt index 1f601e1..2fddc9e 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -2,7 +2,7 @@ {{- if .Values.web.ingress.enabled }} {{- range $host := .Values.web.ingress.hosts }} {{- range .paths }} - http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + http{{ if $.Values.web.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} {{- else if contains "NodePort" .Values.web.service.type }} diff --git a/templates/web/hpa.yaml b/templates/web/hpa.yaml index 1d26cec..a3cfffe 100644 --- a/templates/web/hpa.yaml +++ b/templates/web/hpa.yaml @@ -2,7 +2,7 @@ apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ template "django.fullname" . }} + name: {{ template "django.fullname" . }}-web labels: {{- include "django.labels" . | nindent 4 }} spec: diff --git a/templates/worker/deployment.yaml b/templates/worker/deployment.yaml index da6a4f6..f114446 100644 --- a/templates/worker/deployment.yaml +++ b/templates/worker/deployment.yaml @@ -58,15 +58,15 @@ spec: name: {{ include "django.fullname" . }} - configMapRef: name: {{ include "django.fullname" . }} - {{- with .Values.nodeSelector }} + {{- with .Values.worker.nodeSelector }} nodeSelector: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.affinity }} + {{- with .Values.worker.affinity }} affinity: {{- toYaml . | nindent 8 }} {{- end }} - {{- with .Values.tolerations }} + {{- with .Values.worker.tolerations }} tolerations: {{- toYaml . | nindent 8 }} {{- end }} diff --git a/templates/worker/hpa.yaml b/templates/worker/hpa.yaml index f93531f..878c6f6 100644 --- a/templates/worker/hpa.yaml +++ b/templates/worker/hpa.yaml @@ -2,7 +2,7 @@ apiVersion: autoscaling/v2beta1 kind: HorizontalPodAutoscaler metadata: - name: {{ template "django.fullname" . }} + name: {{ template "django.fullname" . }}-worker labels: {{- include "django.labels" . | nindent 4 }} spec: From 10628c208562103ee1611601230c921ef3073f4d Mon Sep 17 00:00:00 2001 From: David Burke Date: Sun, 14 Feb 2021 17:14:15 +0000 Subject: [PATCH 5/6] Update values.yaml with better defaults --- values.yaml | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/values.yaml b/values.yaml index ec22247..43733a2 100644 --- a/values.yaml +++ b/values.yaml @@ -22,27 +22,37 @@ environmentVariables: GLITCHTIP_DOMAIN: https://example.com web: - replicaCount: 1 + replicaCount: 2 autoscaling: enabled: false minReplicas: 1 - maxReplicas: 100 + maxReplicas: 10 targetCPUUtilizationPercentage: 80 # targetMemoryUtilizationPercentage: 80 - # budget: - # minAvailable: 1 + budget: + minAvailable: 1 resources: - {} - # limits: - # cpu: 100m - # memory: 256Mi - # requests: - # cpu: 50m - # memory: 128Mi + limits: + cpu: 1000m + memory: 512Mi + requests: + cpu: 100m + memory: 128Mi nodeSelector: {} tolerations: [] - affinity: {} + affinity: + podAntiAffinity: + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchExpressions: + - key: app.kubernetes.io/instance + operator: In + values: + - glitchtip-prod-web + topologyKey: kubernetes.io/hostname livenessProbe: failureThreshold: 5 initialDelaySeconds: 5 @@ -78,13 +88,12 @@ worker: targetCPUUtilizationPercentage: 90 # targetMemoryUtilizationPercentage: 80 resources: - {} - # limits: - # cpu: 500m - # memory: 256Mi - # requests: - # cpu: 100m - # memory: 128Mi + limits: + cpu: 900m + memory: 768Mi + requests: + cpu: 100m + memory: 128Mi nodeSelector: {} tolerations: [] affinity: {} From 25a8efb7c6499730cd366ff1cf680845e1459f1d Mon Sep 17 00:00:00 2001 From: David Burke Date: Mon, 15 Feb 2021 16:43:28 -0500 Subject: [PATCH 6/6] consistent deployment names --- templates/beat/{deployment-beat.yaml => deployment.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename templates/beat/{deployment-beat.yaml => deployment.yaml} (100%) diff --git a/templates/beat/deployment-beat.yaml b/templates/beat/deployment.yaml similarity index 100% rename from templates/beat/deployment-beat.yaml rename to templates/beat/deployment.yaml