From 976c6799ddc50652695cabd7625c467fdca34ac5 Mon Sep 17 00:00:00 2001 From: David Burke Date: Fri, 19 Feb 2021 20:20:53 +0000 Subject: [PATCH] Use more generic name "django" instead of glitchtip for template variables --- templates/NOTES.txt | 22 ++--- templates/_helpers.tpl | 38 +++---- .../deployment.yaml} | 25 +++-- templates/configmap.yaml | 4 +- templates/pre-install-job.yaml | 4 +- templates/secrets.yaml | 4 +- templates/service.yaml | 16 --- templates/serviceaccount.yaml | 10 +- templates/tests/test-connection.yaml | 8 +- templates/web-hpa.yaml | 19 ---- templates/{ => web}/deployment.yaml | 33 +++---- templates/web/hpa.yaml | 28 ++++++ templates/{ => web}/ingress.yaml | 22 +++-- templates/{ => web}/pdb.yaml | 8 +- templates/web/service.yaml | 16 +++ templates/worker-hpa.yaml | 19 ---- .../deployment.yaml} | 31 +++--- templates/worker/hpa.yaml | 28 ++++++ values.yaml | 99 ++++++++++--------- 19 files changed, 233 insertions(+), 201 deletions(-) rename templates/{deployment-beat.yaml => beat/deployment.yaml} (71%) delete mode 100644 templates/service.yaml delete mode 100644 templates/web-hpa.yaml rename templates/{ => web}/deployment.yaml (77%) create mode 100644 templates/web/hpa.yaml rename templates/{ => web}/ingress.yaml (56%) rename templates/{ => web}/pdb.yaml (57%) create mode 100644 templates/web/service.yaml delete mode 100644 templates/worker-hpa.yaml rename templates/{deployment-worker.yaml => worker/deployment.yaml} (69%) create mode 100644 templates/worker/hpa.yaml diff --git a/templates/NOTES.txt b/templates/NOTES.txt index cee67c0..2fddc9e 100644 --- a/templates/NOTES.txt +++ b/templates/NOTES.txt @@ -1,21 +1,21 @@ 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.web.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} {{- end }} {{- end }} -{{- else if contains "NodePort" .Values.service.type }} - export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "glitchtip.fullname" . }}) +{{- else if contains "NodePort" .Values.web.service.type }} + 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.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 }} - 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}") + 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 "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/deployment-beat.yaml b/templates/beat/deployment.yaml similarity index 71% rename from templates/deployment-beat.yaml rename to templates/beat/deployment.yaml index 1f17584..5a15e24 100644 --- a/templates/deployment-beat.yaml +++ b/templates/beat/deployment.yaml @@ -1,14 +1,16 @@ 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: annotations: @@ -16,7 +18,8 @@ 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 }} 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 }} @@ -53,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/service.yaml b/templates/service.yaml deleted file mode 100644 index a8c4adc..0000000 --- a/templates/service.yaml +++ /dev/null @@ -1,16 +0,0 @@ -apiVersion: v1 -kind: Service -metadata: - name: {{ include "glitchtip.fullname" . }} - labels: - {{- include "glitchtip.labels" . | nindent 4 }} -spec: - type: {{ .Values.service.type }} - ports: - - port: {{ .Values.service.port }} - targetPort: http - protocol: TCP - name: http - selector: - {{- include "glitchtip.selectorLabels" . | nindent 4 }} - role: web \ No newline at end of file diff --git a/templates/serviceaccount.yaml b/templates/serviceaccount.yaml index 07b2921..c686c91 100644 --- a/templates/serviceaccount.yaml +++ b/templates/serviceaccount.yaml @@ -2,7 +2,11 @@ apiVersion: v1 kind: ServiceAccount metadata: - name: {{ include "glitchtip.serviceAccountName" . }} + name: {{ include "django.serviceAccountName" . }} labels: -{{ include "glitchtip.labels" . | nindent 4 }} -{{- end -}} + {{- include "django.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..e3023e4 100644 --- a/templates/tests/test-connection.yaml +++ b/templates/tests/test-connection.yaml @@ -1,15 +1,15 @@ 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-success + "helm.sh/hook": test spec: containers: - name: wget image: busybox command: ['wget'] - args: ['{{ include "glitchtip.fullname" . }}:{{ .Values.service.port }}'] + args: ['{{ include "django.fullname" . }}:{{ .Values.web.service.port }}'] restartPolicy: Never diff --git a/templates/web-hpa.yaml b/templates/web-hpa.yaml deleted file mode 100644 index f24629d..0000000 --- a/templates/web-hpa.yaml +++ /dev/null @@ -1,19 +0,0 @@ -{{- if .Values.web.hpa.enabled -}} -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ template "glitchtip.fullname" . }} - labels: - app: {{ template "glitchtip.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" -spec: - scaleTargetRef: - kind: Deployment - apiVersion: apps/v1 - name: {{ template "glitchtip.fullname" . }} - minReplicas: {{ .Values.web.hpa.minpods }} - maxReplicas: {{ .Values.web.hpa.maxpods }} - targetCPUUtilizationPercentage: {{ .Values.web.hpa.cputhreshold }} -{{- end }} diff --git a/templates/deployment.yaml b/templates/web/deployment.yaml similarity index 77% rename from templates/deployment.yaml rename to templates/web/deployment.yaml index 097e367..8d109d3 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 "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 }} replicas: {{ .Values.web.replicaCount }} + {{- end }} selector: matchLabels: - {{- include "glitchtip.selectorLabels" . | nindent 6 }} - role: web + {{- include "django.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: web template: metadata: annotations: @@ -17,21 +20,21 @@ spec: checksum/configmap: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }} tag: "{{ .Values.image.tag }}" labels: - {{- include "glitchtip.selectorLabels" . | nindent 8 }} - role: web + {{- 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: - 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 }} @@ -67,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: @@ -79,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 new file mode 100644 index 0000000..a3cfffe --- /dev/null +++ b/templates/web/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.web.autoscaling.enabled -}} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "django.fullname" . }}-web + labels: + {{- include "django.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "django.fullname" . }}-web + 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/ingress.yaml b/templates/web/ingress.yaml similarity index 56% rename from templates/ingress.yaml rename to templates/web/ingress.yaml index 44cef26..3f9860d 100644 --- a/templates/ingress.yaml +++ b/templates/web/ingress.yaml @@ -1,6 +1,6 @@ -{{- if .Values.ingress.enabled -}} -{{- $fullName := include "glitchtip.fullname" . -}} -{{- $svcPort := .Values.service.port -}} +{{- if .Values.web.ingress.enabled -}} +{{- $fullName := include "django.fullname" . -}} +{{- $svcPort := .Values.web.service.port -}} {{- if semverCompare ">=1.14-0" .Capabilities.KubeVersion.GitVersion -}} apiVersion: networking.k8s.io/v1beta1 {{- else -}} @@ -10,15 +10,15 @@ kind: Ingress metadata: name: {{ $fullName }} labels: - {{- include "glitchtip.labels" . | nindent 4 }} - {{- with .Values.ingress.annotations }} + {{- include "django.labels" . | nindent 4 }} + {{- 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 57% rename from templates/pdb.yaml rename to templates/web/pdb.yaml index 781536f..e0376b2 100644 --- a/templates/pdb.yaml +++ b/templates/web/pdb.yaml @@ -3,14 +3,14 @@ apiVersion: policy/v1beta1 kind: PodDisruptionBudget metadata: - name: {{ include "glitchtip.fullname" . }} + 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 }} - role: web + {{- include "django.selectorLabels" . | nindent 6 }} + app.kubernetes.io/component: web {{- end -}} {{- end -}} diff --git a/templates/web/service.yaml b/templates/web/service.yaml new file mode 100644 index 0000000..8eb3fc5 --- /dev/null +++ b/templates/web/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "django.fullname" . }}-web + labels: + {{- include "django.labels" . | nindent 4 }} +spec: + type: {{ .Values.web.service.type }} + ports: + - port: {{ .Values.web.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + {{- include "django.selectorLabels" . | nindent 4 }} + app.kubernetes.io/component: web \ No newline at end of file diff --git a/templates/worker-hpa.yaml b/templates/worker-hpa.yaml deleted file mode 100644 index 237977b..0000000 --- a/templates/worker-hpa.yaml +++ /dev/null @@ -1,19 +0,0 @@ -{{- if .Values.worker.hpa.enabled -}} -apiVersion: autoscaling/v1 -kind: HorizontalPodAutoscaler -metadata: - name: {{ template "glitchtip.fullname" . }}-worker - labels: - app: {{ template "glitchtip.fullname" . }} - chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" - release: "{{ .Release.Name }}" - heritage: "{{ .Release.Service }}" -spec: - scaleTargetRef: - kind: Deployment - apiVersion: apps/v1 - name: {{ template "glitchtip.fullname" . }}-worker - minReplicas: {{ .Values.worker.hpa.minpods }} - maxReplicas: {{ .Values.worker.hpa.maxpods }} - targetCPUUtilizationPercentage: {{ .Values.worker.hpa.cputhreshold }} -{{- end }} diff --git a/templates/deployment-worker.yaml b/templates/worker/deployment.yaml similarity index 69% rename from templates/deployment-worker.yaml rename to templates/worker/deployment.yaml index f55c8c0..f114446 100644 --- a/templates/deployment-worker.yaml +++ b/templates/worker/deployment.yaml @@ -1,14 +1,16 @@ 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: annotations: @@ -16,7 +18,8 @@ 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 }} 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 }} @@ -48,26 +47,26 @@ 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" . }} - {{- with .Values.nodeSelector }} + name: {{ include "django.fullname" . }} + {{- 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 new file mode 100644 index 0000000..878c6f6 --- /dev/null +++ b/templates/worker/hpa.yaml @@ -0,0 +1,28 @@ +{{- if .Values.worker.autoscaling.enabled -}} +apiVersion: autoscaling/v2beta1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "django.fullname" . }}-worker + labels: + {{- include "django.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "django.fullname" . }}-worker + 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..43733a2 100644 --- a/values.yaml +++ b/values.yaml @@ -22,25 +22,37 @@ environmentVariables: GLITCHTIP_DOMAIN: https://example.com web: - replicaCount: 1 - hpa: + replicaCount: 2 + autoscaling: enabled: false - cputhreshold: 70 - minpods: 2 - maxpods: 4 - # budget: - # minAvailable: 1 + minReplicas: 1 + maxReplicas: 10 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + + 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 @@ -49,22 +61,39 @@ 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 - hpa: + autoscaling: enabled: false - cputhreshold: 90 - minpods: 1 - maxpods: 4 + minReplicas: 1 + maxReplicas: 100 + 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: {} @@ -76,24 +105,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: