diff --git a/README.md b/README.md index 4eb54d3..088fc57 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,12 @@ their default values. | `podDisruptionBudget` | Pod disruption budget | `{}` | | `resources.limits.cpu` | Container requested CPU | `nil` | | `resources.limits.memory` | Container requested memory | `nil` | +| `autoscaling.enabled` | Enable autoscaling using HorizontalPodAutoscaler | `false` | +| `autoscaling.minReplicas` | Minimal number of replicas | `1` | +| `autoscaling.maxReplicas` | Maximal number of replicas | `2` | +| `autoscaling.targetCPUUtilizationPercentage` | Target average utilization of CPU on Pods | `60` | +| `autoscaling.targetMemoryUtilizationPercentage` | (Kubernetes ≥1.23) Target average utilization of Memory on Pods | `60` | +| `autoscaling.behavior` | (Kubernetes ≥1.23) Configurable scaling behavior | `{}` | | `priorityClassName ` | priorityClassName | `""` | | `storage` | Storage system to use | `filesystem` | | `tlsSecretName` | Name of secret for TLS certs | `nil` | diff --git a/templates/hpa.yaml b/templates/hpa.yaml new file mode 100644 index 0000000..0e29c95 --- /dev/null +++ b/templates/hpa.yaml @@ -0,0 +1,42 @@ +{{- if .Values.autoscaling.enabled }} +{{- $apiVersions := .Capabilities.APIVersions -}} +{{- if $apiVersions.Has "autoscaling/v2" }} +apiVersion: autoscaling/v2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "docker-registry.fullname" . }} + labels: + app: {{ template "docker-registry.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "docker-registry.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + metrics: +{{- with .Values.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ . }} +{{- end }} +{{- with .Values.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ . }} +{{- end }} +{{- with .Values.autoscaling.behavior }} + behavior: + {{- toYaml . | nindent 4 }} +{{- end }} +{{- end }} +{{- end }} diff --git a/templates/hpaV1.yaml b/templates/hpaV1.yaml new file mode 100644 index 0000000..3dccb7f --- /dev/null +++ b/templates/hpaV1.yaml @@ -0,0 +1,22 @@ +{{- if .Values.autoscaling.enabled }} +{{- $apiVersions := .Capabilities.APIVersions -}} +{{- if not ($apiVersions.Has "autoscaling/v2") }} +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: {{ template "docker-registry.fullname" . }} + labels: + app: {{ template "docker-registry.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ template "docker-registry.fullname" . }} + minReplicas: {{ .Values.autoscaling.minReplicas }} + maxReplicas: {{ .Values.autoscaling.maxReplicas }} + targetCPUUtilizationPercentage: {{ .Values.autoscaling.targetCPUUtilizationPercentage }} +{{- end }} +{{- end }} diff --git a/values.yaml b/values.yaml index ece8caa..658ba64 100644 --- a/values.yaml +++ b/values.yaml @@ -163,6 +163,30 @@ podDisruptionBudget: {} # maxUnavailable: 1 # minAvailable: 2 +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 2 + targetCPUUtilizationPercentage: 60 + targetMemoryUtilizationPercentage: 60 # available only on Kubernetes ≥1.23 [required "autoscaling/v2"] + behavior: {} # available only on Kubernetes ≥1.23 [required "autoscaling/v2"] +# scaleDown: +# stabilizationWindowSeconds: 300 +# policies: +# - type: Percent +# value: 100 +# periodSeconds: 15 +# scaleUp: +# stabilizationWindowSeconds: 0 +# policies: +# - type: Percent +# value: 100 +# periodSeconds: 15 +# - type: Pods +# value: 4 +# periodSeconds: 15 +# selectPolicy: Max + nodeSelector: {} affinity: {}