diff --git a/charts/universal-chart/CHANGELOG.md b/charts/universal-chart/CHANGELOG.md index d3d99e7..b2c05bf 100644 --- a/charts/universal-chart/CHANGELOG.md +++ b/charts/universal-chart/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## 3.2.0 - May 2, 2022 + +* feat: add HPA support and tests + ## 3.1.0 - April 24, 2022 * feat: add PDB support and tests diff --git a/charts/universal-chart/Chart.yaml b/charts/universal-chart/Chart.yaml index ebb2637..c6a1e5d 100644 --- a/charts/universal-chart/Chart.yaml +++ b/charts/universal-chart/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 description: Nixys universal Helm chart for deploy your apps to Kubernetes name: universal-chart -version: 3.1.0 +version: 3.2.0 maintainers: - name: Roman Andreev email: r.andreev@nixys.ru diff --git a/charts/universal-chart/README.md b/charts/universal-chart/README.md index fc576a8..0ef8daf 100644 --- a/charts/universal-chart/README.md +++ b/charts/universal-chart/README.md @@ -420,6 +420,30 @@ Secret `data` object is a map where value can be a string, json or base64 encode | `maxUnavailable` | Pods that can be unavailable after the eviction | `""` | | `extraSelectorLabels` | Extra selectorLabels for select workload | `{}` | +### HorizontalPodAutoscaler parameters + +`hpas` is map of HPA parameters, where key is a name + +| Name | Description | Value | +|------------------|-------------------------------------------------------------------------|-------------------------| +| `labels` | Extra HPA labels | `{}` | +| `annotations` | Extra HPA annotations | `{}` | +| `apiVersion` | apiVersion for HPA object | `"autoscaling/v2beta1"` | +| `minReplicas` | minimum replicas for HPA | `2` | +| `maxReplicas` | maximum replicas for HPA | `3` | +| `scaleTargetRef` | Required [scaleTargetRef](#hpa-scaletargetref-object-parameters) object | | +| `targetCPU` | target CPU utilization percentage | `""` | +| `targetMemory` | target memory utilization percentage | `""` | +| `metrics` | list of custom metrics | `[]` | + +### HPA `scaleTargetRef` object parameters + +| Name | Description | Value | +|------------|----------------------------------|--------------| +| apiVersion | apiVersion for target HPA object | "apps/v1" | +| kind | kind for target HPA object | "Deployment" | +| name | Required name of target object | "" | + ## Configuration and installation details ### Using private registries diff --git a/charts/universal-chart/results/hpas.yaml b/charts/universal-chart/results/hpas.yaml new file mode 100644 index 0000000..df02307 --- /dev/null +++ b/charts/universal-chart/results/hpas.yaml @@ -0,0 +1,84 @@ +--- +# Source: universal-chart/templates/hpa.yaml +kind: HorizontalPodAutoscaler +apiVersion: autoscaling/v2beta1 +metadata: + name: test-hpa0 + namespace: "default" + labels: + app.kubernetes.io/name: test + app.kubernetes.io/instance: test + app.kubernetes.io/managed-by: Helm + annotations: +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: test-dep + minReplicas: 2 + maxReplicas: 3 + metrics: + - type: Resource + resource: + name: cpu + targetAverageUtilization: 50 + - type: Resource + resource: + name: memory + targetAverageUtilization: 50 +--- +# Source: universal-chart/templates/hpa.yaml +kind: HorizontalPodAutoscaler +apiVersion: autoscaling/v2 +metadata: + name: test-hpa1 + namespace: "default" + labels: + app.kubernetes.io/name: test + app.kubernetes.io/instance: test + app.kubernetes.io/managed-by: Helm + foo: bar + annotations: + bar.io/bar: foo +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: test-deploy + minReplicas: 1 + maxReplicas: 2 + metrics: + - resource: + name: cpu + target: + averageUtilization: 50 + type: Utilization + type: Resource + - pods: + metric: + name: packets-per-second + target: + averageValue: 1k + type: AverageValue + type: Pods + - object: + describedObject: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: main-route + metric: + name: requests-per-second + target: + type: Value + value: 10k + type: Object + - external: + metric: + name: queue_messages_ready + selector: + matchLabels: + queue: worker_tasks + target: + averageValue: 30 + type: AverageValue + type: External diff --git a/charts/universal-chart/samples/hpas.yaml b/charts/universal-chart/samples/hpas.yaml new file mode 100644 index 0000000..20b7d98 --- /dev/null +++ b/charts/universal-chart/samples/hpas.yaml @@ -0,0 +1,53 @@ +hpas: + hpa0: + scaleTargetRef: + name: dep + targetCPU: 50 + targetMemory: 50 + hpa1: + apiVersion: autoscaling/v2 + labels: + foo: bar + annotations: + bar.io/bar: foo + minReplicas: 1 + maxReplicas: 2 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: deploy + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 + - type: Pods + pods: + metric: + name: packets-per-second + target: + type: AverageValue + averageValue: 1k + - type: Object + object: + metric: + name: requests-per-second + describedObject: + apiVersion: networking.k8s.io/v1 + kind: Ingress + name: main-route + target: + type: Value + value: 10k + - type: External + external: + metric: + name: queue_messages_ready + selector: + matchLabels: + queue: "worker_tasks" + target: + type: AverageValue + averageValue: 30 diff --git a/charts/universal-chart/templates/hpa.yaml b/charts/universal-chart/templates/hpa.yaml new file mode 100644 index 0000000..abf7e87 --- /dev/null +++ b/charts/universal-chart/templates/hpa.yaml @@ -0,0 +1,38 @@ +{{- range $name, $hpa := .Values.hpas }} +--- +kind: HorizontalPodAutoscaler +apiVersion: {{ .apiVersion | default "autoscaling/v2beta1" }} +metadata: + name: {{ include "helpers.app.fullname" (dict "name" $name "context" $) }} + namespace: {{ $.Release.Namespace | quote }} + labels: + {{- include "helpers.app.labels" $ | nindent 4 }} + {{- with .labels }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{- end }} + annotations: + {{- with .annotations }}{{- include "helpers.tplvalues.render" (dict "value" . "context" $) | nindent 4 }}{{- end }} +spec: + {{- with .scaleTargetRef }} + scaleTargetRef: + apiVersion: {{ .apiVersion | default "apps/v1" }} + kind: {{ .kind | default "Deployment" }} + name: {{ include "helpers.app.fullname" (dict "name" .name "context" $) }} + {{- end }} + minReplicas: {{ .minReplicas | default "2" }} + maxReplicas: {{ .maxReplicas | default "3" }} + metrics: + {{- if not (empty .targetCPU) }} + - type: Resource + resource: + name: cpu + targetAverageUtilization: {{ .targetCPU }} + {{- end }} + {{- if not (empty .targetMemory) }} + - type: Resource + resource: + name: memory + targetAverageUtilization: {{ .targetMemory }} + {{- end }} + {{- if .metrics }} + {{- toYaml .metrics | nindent 4 }} + {{- end }} +{{- end -}}