Skip to content

Commit

Permalink
add keda
Browse files Browse the repository at this point in the history
  • Loading branch information
juri committed Nov 21, 2024
1 parent 0e3ce4e commit 27d0fc2
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 20 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ command:
- "-c"
- "sleep 60"
environment:
variables:
PORT: "8080"
ports:
- containerPort: 8080
```
Expand Down
2 changes: 1 addition & 1 deletion charts/app/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: app
description: A Helm chart for Kubernetes Deployment
type: application

version: 0.14.0
version: 0.15.0

keywords:
- deployment
Expand Down
1 change: 1 addition & 0 deletions charts/app/templates/base.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{{ include "base.verticalPodAutoscaler" . }}
{{ include "base.podDisruptionBudget" . }}
{{ include "base.horizontalPodAutoscaler" . }}
{{ include "base.keda" . }}
{{ include "base.PriorityClass" . }}
{{ include "base.rbac" . }}
{{ include "base.deployment" . }}
Expand Down
48 changes: 48 additions & 0 deletions charts/app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,54 @@ autoscaling:
# behavior:
# scaleDown:
# stabilizationWindowSeconds: 300
scaleTargetRef: {}

## https://keda.sh/docs/latest/reference/scaledobject-spec/
keda:
enabled: false
# apiVersion: keda.sh/v1alpha1
# annotations:
# scaledobject.keda.sh/transfer-hpa-ownership: "true" # Optional. Use to transfer an existing HPA ownership to this ScaledObject
# validations.keda.sh/hpa-ownership: "true" # Optional. Use to disable HPA ownership validation on this ScaledObject
# autoscaling.keda.sh/paused: "true" # Optional. Use to pause autoscaling of objects explicitly
scaleTargetRef: {}
# scaleTargetRef:
# apiVersion: {api-version-of-target-resource} # Optional. Default: apps/v1
# kind: {kind-of-target-resource} # Optional. Default: Deployment
# name: {name-of-target-resource} # Mandatory. Must be in the same namespace as the ScaledObject
# envSourceContainerName: {container-name} # Optional. Default: .spec.template.spec.containers[0]
# pollingInterval: 30 # Optional. Default: 30 seconds
# cooldownPeriod: 300 # Optional. Default: 300 seconds
# initialCooldownPeriod: 0 # Optional. Default: 0 seconds
# idleReplicaCount: 0 # Optional. Default: ignored, must be less than minReplicaCount
minReplicaCount: 1
maxReplicaCount: 20
# fallback: # Optional. Section to specify fallback options
# failureThreshold: 3 # Mandatory if fallback section is included
# replicas: 6 # Mandatory if fallback section is included
# advanced: # Optional. Section to specify advanced options
# restoreToOriginalReplicaCount: true/false # Optional. Default: false
# horizontalPodAutoscalerConfig: # Optional. Section to specify HPA related options
# name: {name-of-hpa-resource} # Optional. Default: keda-hpa-{scaled-object-name}
# behavior: # Optional. Use to modify HPA's scaling behavior
# scaleDown:
# stabilizationWindowSeconds: 300
# policies:
# - type: Percent
# value: 100
# periodSeconds: 15
# triggers:
# # {list of triggers to activate scaling of the target resource}

# TriggerAuthentication: ## or ClusterTriggerAuthentication
# - name: Name
# spec:
# secretTargetRef:
# - parameter: GoogleApplicationCredentials
# name: cloudtasks-secret # Required. Refers to the name of the secret
# key: GOOGLE_APPLICATION_CREDENTIALS_JSON # Required.
# podIdentity:
# provider: gcp

# ref: https://kubernetes.io/docs/tasks/run-application/configure-pdb/
podDisruptionBudget:
Expand Down
2 changes: 1 addition & 1 deletion charts/argo-applications/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: argo-applications
description: A Helm chart for Kubernetes argo applications
type: application

version: 0.14.0
version: 0.15.0

keywords:
- argocd
Expand Down
2 changes: 1 addition & 1 deletion charts/argo-workflows/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: argo-workflows
description: A Helm chart for Kubernetes argocd workflows
type: application

version: 0.11.6
version: 0.15.0

keywords:
- argocd
Expand Down
2 changes: 1 addition & 1 deletion charts/base/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: base
description: A Helm chart for Kubernetes with helm named templates
type: library

version: 0.14.0
version: 0.15.0

keywords:
- deployment
Expand Down
4 changes: 3 additions & 1 deletion charts/base/templates/_argoRollouts.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ metadata:
labels:
{{- include "base.labels" . | trim | nindent 4 }}
spec:
{{- if .Values.autoscaling.enabled }}
{{- if .Values.keda.enabled }}
replicas: {{ .Values.keda.minReplicaCount | default 0 }}
{{- else if .Values.autoscaling.enabled }}
replicas: {{ .Values.autoscaling.minReplicas }}
{{- else }}
replicas: {{ .Values.replicas }}
Expand Down
2 changes: 1 addition & 1 deletion charts/base/templates/_deployment.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
spec:
{{- if and $deploymentValues.Values.argo.rollouts.enabled ( eq $deploymentValues.Values.argo.rollouts.type "workloadRef" ) }}
replicas: 0
{{- else if not $deploymentValues.Values.autoscaling.enabled }}
{{- else if and (not $deploymentValues.Values.autoscaling.enabled) (not $deploymentValues.Values.keda.enabled) }}
replicas: {{ $deploymentValues.Values.replicas }}
{{- end }}
revisionHistoryLimit: {{ $deploymentValues.Values.revisionHistoryLimit | default 10 }}
Expand Down
10 changes: 5 additions & 5 deletions charts/base/templates/_horizontalPodAutoscaler.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ metadata:
spec:
scaleTargetRef:
{{- if .Values.argo.rollouts.enabled }}
apiVersion: {{ .Values.argo.rollouts.apiVersion }}
kind: {{ .Values.argo.rollouts.kind }}
apiVersion: {{ coalesce .Values.autoscaling.scaleTargetRef.apiVersion .Values.argo.rollouts.apiVersion }}
kind: {{ coalesce .Values.autoscaling.scaleTargetRef.kind .Values.argo.rollouts.kind }}
{{- else }}
apiVersion: {{ .Values.apiVersion | default "apps/v1" }}
kind: {{ .Values.kind | default "Deployment" }}
apiVersion: {{ coalesce .Values.autoscaling.scaleTargetRef.apiVersion .Values.apiVersion "apps/v1" }}
kind: {{ coalesce .Values.autoscaling.scaleTargetRef.kind .Values.kind "Deployment" }}
{{- end }}
name: {{ include "base.fullname" . }}
name: {{ .Values.autoscaling.scaleTargetRef.name | default (include "base.fullname" .) }}
{{- if .Values.autoscaling.minReplicas }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
{{- end }}
Expand Down
89 changes: 89 additions & 0 deletions charts/base/templates/_keda.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
{{- define "base.keda" -}}
{{- if .Values.keda.enabled }}
{{- $labels := include "base.labels" . }}
{{- $keda := .Values.keda }}
---
apiVersion: {{ .Values.keda.apiVersion | default "keda.sh/v1alpha1" }}
kind: ScaledObject
metadata:
name: {{ include "base.fullname" . }}
labels:
{{- $labels | trim | nindent 4 }}
{{- with .Values.keda.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
scaleTargetRef:
{{- if .Values.argo.rollouts.enabled }}
apiVersion: {{ coalesce .Values.keda.scaleTargetRef.apiVersion .Values.argo.rollouts.apiVersion }}
kind: {{ coalesce .Values.keda.scaleTargetRef.kind .Values.argo.rollouts.kind }}
{{- else }}
apiVersion: {{ coalesce .Values.keda.scaleTargetRef.apiVersion .Values.apiVersion "apps/v1" }}
kind: {{ coalesce .Values.keda.scaleTargetRef.kind .Values.kind "Deployment" }}
{{- end }}
name: {{ .Values.keda.scaleTargetRef.name | default (include "base.fullname" .) }}
{{- if .Values.keda.scaleTargetRef.envSourceContainerName }}
envSourceContainerName: {{ .Values.keda.scaleTargetRef.envSourceContainerName }}
{{- end }}
pollingInterval: {{ .Values.keda.pollingInterval | default 30 }}
cooldownPeriod: {{ .Values.keda.cooldownPeriod | default 300 }}
idleReplicaCount: {{ .Values.keda.idleReplicaCount | default 0 }}
minReplicaCount: {{ .Values.keda.minReplicaCount | default 0 }}
maxReplicaCount: {{ .Values.keda.maxReplicaCount | default 100 }}
{{- with .Values.keda.fallback }}
fallback:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.keda.advanced }}
advanced:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.keda.triggers }}
triggers:
{{- toYaml . | nindent 4 }}
{{- end }}

{{- if or .Values.keda.TriggerAuthentication .Values.keda.ClusterTriggerAuthentication }}
{{- range .Values.keda.TriggerAuthentication }}
---
apiVersion: {{ $keda.apiVersion | default "keda.sh/v1alpha1" }}
kind: TriggerAuthentication
metadata:
name: {{ .name }}
{{- with .labels }}
labels:
{{- $labels | trim | nindent 4 }}
{{- end }}
{{- with .annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .spec }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- range .Values.keda.ClusterTriggerAuthentication }}
---
apiVersion: {{ $keda.apiVersion | default "keda.sh/v1alpha1" }}
kind: ClusterTriggerAuthentication
metadata:
name: {{ .name }}
{{- with .labels }}
labels:
{{- $labels | trim | nindent 4 }}
{{- end }}
{{- with .annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- with .spec }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- end }}

{{- end }}
{{- end }}
6 changes: 4 additions & 2 deletions charts/base/templates/_podDisruptionBudget.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ metadata:
spec:
{{- if .Values.podDisruptionBudget.minAvailable }}
minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
{{- else if and $autoscaling.enabled $autoscaling.minReplicas }}
minAvailable: {{ if (lt (int $autoscaling.minReplicas) 2) }}1{{else}}{{ div $autoscaling.minReplicas 2 }}{{end}}
{{- else if and .Values.keda.enabled }}
minAvailable: {{ if (lt (int .Values.keda.minReplicaCount) 2) }}1{{else}}{{ div .Values.keda.minReplicaCount 2 }}{{end}}
{{- else if and .Values.autoscaling.enabled .Values.autoscaling.minReplicas }}
minAvailable: {{ if (lt (int .Values.autoscaling.minReplicas) 2) }}1{{else}}{{ div .Values.autoscaling.minReplicas 2 }}{{end}}
{{- else }}
minAvailable: {{ if (lt (int .Values.replicas) 2) }}1{{else}}{{ div .Values.replicas 2 }}{{end}}
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion charts/cronjob/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: cronjob
description: A Helm chart for Kubernetes cronjob
type: application

version: 0.14.0
version: 0.15.0

keywords:
- cronjob
Expand Down
2 changes: 1 addition & 1 deletion charts/default-base/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: default-base
description: A Helm chart for Kubernetes - default-base for namespaces

version: 0.14.0
version: 0.15.0

keywords:
- BackendConfig
Expand Down
2 changes: 1 addition & 1 deletion charts/ingress/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ingress
description: A Helm chart for Kubernetes ingress
type: application

version: 0.14.0
version: 0.15.0

keywords:
- ingress
Expand Down
2 changes: 1 addition & 1 deletion charts/job/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: job
description: A Helm chart for Kubernetes job
type: application

version: 0.14.0
version: 0.15.0

keywords:
- job
Expand Down
2 changes: 1 addition & 1 deletion charts/prometheus-rules/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: prometheus-rules
description: A Helm chart for Prometheus Rules
type: application

version: 0.14.0
version: 0.15.0

keywords:
- job
Expand Down
2 changes: 1 addition & 1 deletion charts/rbac/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: rbac
description: A Helm chart for Kubernetes rbac
type: application

version: 0.14.0
version: 0.15.0

keywords:
- rbac
Expand Down
2 changes: 1 addition & 1 deletion charts/service/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: service
description: A Helm chart for Kubernetes service
type: application

version: 0.14.0
version: 0.15.0

keywords:
- service
Expand Down

0 comments on commit 27d0fc2

Please sign in to comment.