From 15af2f4f36e344e2d478f48e2ceeea9122b24bfc Mon Sep 17 00:00:00 2001 From: Philipp Born Date: Sat, 9 Dec 2023 11:03:41 +0100 Subject: [PATCH] bump appVersion, allow multiple replicas (+HPA) for Deployment, allow setting externalService annotations, allow disabling allocateLoadBalancerNodePorts --- charts/traccar/Chart.lock | 7 ++-- charts/traccar/Chart.yaml | 8 +++-- charts/traccar/ci/ha-with-redis-values.yaml | 14 ++++++++ charts/traccar/templates/configmap.yaml | 4 +++ charts/traccar/templates/deployment.yaml | 25 ++++++++++--- charts/traccar/templates/hpa.yaml | 32 +++++++++++++++++ charts/traccar/templates/service.yaml | 7 ++++ charts/traccar/values.yaml | 39 +++++++++++++++++++++ ct.yaml | 1 + 9 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 charts/traccar/ci/ha-with-redis-values.yaml create mode 100644 charts/traccar/templates/hpa.yaml diff --git a/charts/traccar/Chart.lock b/charts/traccar/Chart.lock index a0425c1..252512f 100644 --- a/charts/traccar/Chart.lock +++ b/charts/traccar/Chart.lock @@ -2,5 +2,8 @@ dependencies: - name: mysql repository: https://charts.bitnami.com/bitnami version: 9.4.8 -digest: sha256:c54ca45ec9055b33d96c582be62d5c4afd9501f2edfee0afaa73876b7ae13cfa -generated: "2023-01-28T11:57:35.495179799+01:00" +- name: redis-ha + repository: https://dandydeveloper.github.io/charts + version: 4.23.0 +digest: sha256:91b7dd321c826a5721204763f11ac8a641c60cc23690250ca2eecd8c368cdac8 +generated: "2023-12-09T13:20:23.900368+01:00" diff --git a/charts/traccar/Chart.yaml b/charts/traccar/Chart.yaml index 179628a..4788553 100644 --- a/charts/traccar/Chart.yaml +++ b/charts/traccar/Chart.yaml @@ -2,13 +2,17 @@ apiVersion: v2 name: traccar description: A Helm chart for Traccar GPS Server type: application -version: 1.6.0 -appVersion: "5.6" +version: 1.7.0 +appVersion: "5.10" dependencies: - name: mysql version: 9.4.8 repository: https://charts.bitnami.com/bitnami condition: mysql.enabled + - name: redis-ha + version: 4.23.0 + repository: https://dandydeveloper.github.io/charts + condition: redis-ha.enabled maintainers: - email: laszlo.kondas@gmail.com name: kondas diff --git a/charts/traccar/ci/ha-with-redis-values.yaml b/charts/traccar/ci/ha-with-redis-values.yaml new file mode 100644 index 0000000..c5c82a8 --- /dev/null +++ b/charts/traccar/ci/ha-with-redis-values.yaml @@ -0,0 +1,14 @@ +replicaCount: 2 + +deploymentStrategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + +redis-ha: + enabled: true + # defaults to 3. but we wan't CI to run through in a reasonable time. + replicas: 1 + haproxy: + replicas: 1 diff --git a/charts/traccar/templates/configmap.yaml b/charts/traccar/templates/configmap.yaml index e625dd9..021584a 100644 --- a/charts/traccar/templates/configmap.yaml +++ b/charts/traccar/templates/configmap.yaml @@ -401,6 +401,10 @@ data: {{ .Values.traccar.notificator.telegram.sendLocation }} {{- end }} {{- end }} +{{- end }} +{{- if (index .Values "redis-ha").enabled }} + redis + redis://{{ include "traccar.fullname" . }}-redis-ha-haproxy:6379 {{- end }} {{- end }} diff --git a/charts/traccar/templates/deployment.yaml b/charts/traccar/templates/deployment.yaml index fd80a4e..46e8679 100644 --- a/charts/traccar/templates/deployment.yaml +++ b/charts/traccar/templates/deployment.yaml @@ -5,12 +5,16 @@ metadata: labels: {{- include "traccar.labels" . | nindent 4 }} spec: - replicas: 1 + {{- if not .Values.autoscaling.enabled }} + replicas: {{ .Values.replicaCount }} + {{- end }} selector: matchLabels: {{- include "traccar.selectorLabels" . | nindent 6 }} + {{- with .Values.deploymentStrategy }} strategy: - type: Recreate + {{- toYaml . | nindent 4 }} + {{- end }} template: metadata: annotations: @@ -32,13 +36,13 @@ spec: - name: config configMap: name: {{ include "traccar.fullname" . }} -{{- if or .Values.mysql.enabled .Values.initContainers }} +{{- if or .Values.mysql.enabled (index .Values "redis-ha").enabled .Values.initContainers }} initContainers: {{- if .Values.mysql.enabled }} - name: wait-for-db securityContext: {{- toYaml .Values.securityContext | nindent 12 }} - image: "alpine:3.6" + image: "alpine:3.19" command: - 'sh' - '-c' @@ -47,6 +51,19 @@ spec: do sleep 2; done {{- end }} +{{- if (index .Values "redis-ha").enabled }} + - name: wait-for-redis + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "alpine:3.19" + command: + - 'sh' + - '-c' + - > + until nc -z -w 2 {{ include "traccar.fullname" . }}-redis-ha-haproxy 6379 && echo redis ok; + do sleep 2; + done +{{- end }} {{- with .Values.initContainers }} {{- if eq (typeOf .) "string" }} {{- tpl . $ | nindent 8 }} diff --git a/charts/traccar/templates/hpa.yaml b/charts/traccar/templates/hpa.yaml new file mode 100644 index 0000000..a0fa418 --- /dev/null +++ b/charts/traccar/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.autoscaling.enabled }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "traccar.fullname" . }} + labels: + {{- include "traccar.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "traccar.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: + {{- if .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/charts/traccar/templates/service.yaml b/charts/traccar/templates/service.yaml index fb6b142..1f1f25b 100644 --- a/charts/traccar/templates/service.yaml +++ b/charts/traccar/templates/service.yaml @@ -25,6 +25,10 @@ metadata: name: {{ $externalfullname }} labels: {{- include "traccar.labels" . | nindent 4 }} + {{- with .Values.externalService.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} spec: type: {{ .Values.externalService.type }} {{- if .Values.externalService.loadBalancerIP }} @@ -32,6 +36,9 @@ spec: {{- end }} {{- if .Values.externalService.loadBalancerSourceRanges }} loadBalancerSourceRanges: {{ toYaml .Values.externalService.loadBalancerSourceRanges | nindent 4 }} +{{- end }} +{{- if hasKey .Values.externalService "allocateLoadBalancerNodePorts" }} + allocateLoadBalancerNodePorts: {{ .Values.externalService.allocateLoadBalancerNodePorts }} {{- end }} ports: {{- toYaml .Values.externalService.protocolPorts | nindent 4 }} diff --git a/charts/traccar/values.yaml b/charts/traccar/values.yaml index 363e4b2..788aa87 100644 --- a/charts/traccar/values.yaml +++ b/charts/traccar/values.yaml @@ -115,6 +115,19 @@ mysql: persistence: enabled: false +# NOTE: When using multiple replicas, you must configure broadcast.type and broadcast.address +# This can be done via configOverride. See https://www.traccar.org/configuration-file/#:~:text=attributes%20to%20log.-,broadcast.type,-config +# Or by setting redis.enabled=true +replicaCount: 1 + +deploymentStrategy: + # Recreate has been the default until chart version 1.6.0 and is required if running a non-HA compatible setup + type: Recreate + # rollingUpdate: + # maxSurge: 25% + # maxUnavailable: 25% + # type: RollingUpdate + image: repository: traccar/traccar pullPolicy: IfNotPresent @@ -193,8 +206,15 @@ service: externalService: type: LoadBalancer enabled: false + annotations: {} + # metallb.universe.tf/loadBalancerIPs: 192.168.1.100 # loadBalancerIP: "" # loadBalancerSourceRanges: [] + + # -- Enable node port allocation for the external controller service or not. Applies to type `LoadBalancer` only. + # Ref: https://kubernetes.io/docs/concepts/services-networking/service/#load-balancer-nodeport-allocation + # allocateLoadBalancerNodePorts: true + protocolPorts: - name: gps103 port: 5001 @@ -876,8 +896,27 @@ externalService: resources: {} +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + nodeSelector: tolerations: [] affinity: {} + +redis-ha: + # enables the redis subchart + enabled: false + persistentVolume: + enabled: false + redis: + masterGroupName: traccar + config: + save: '""' + haproxy: + enabled: true diff --git a/ct.yaml b/ct.yaml index 1ae8f4e..3e486cf 100644 --- a/ct.yaml +++ b/ct.yaml @@ -5,4 +5,5 @@ chart-dirs: - charts chart-repos: - bitnami=https://charts.bitnami.com/bitnami + - dandydeveloper=https://dandydeveloper.github.io/charts helm-extra-args: --timeout 600s