diff --git a/.github/workflows/helm-charts-test.yaml b/.github/workflows/helm-charts-test.yaml index df84b90..8ddb4b2 100644 --- a/.github/workflows/helm-charts-test.yaml +++ b/.github/workflows/helm-charts-test.yaml @@ -39,7 +39,9 @@ jobs: - name: Prepare library charts run: | cp charts/cron-jobs/library-ci/*.yaml charts/cron-jobs/templates/ + cp charts/horizontal-pod-autoscalers/library-ci/*.yaml charts/horizontal-pod-autoscalers/templates/ sed -i 's/library/application/g' charts/cron-jobs/Chart.yaml + sed -i 's/library/application/g' charts/horizontal-pod-autoscalers/Chart.yaml - name: Test charts uses: helm/chart-testing-action@v1.0.0 diff --git a/README.md b/README.md index 8c1153a..264d484 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ Opinionated helm chats for my personal projects, and OSS Projects that either do ### Library * [`cron-jobs`](https://artifacthub.io/packages/helm/wyrihaximusnet/cron-jobs) +* [`horizontal-pod-autoscalers`](https://artifacthub.io/packages/helm/wyrihaximusnet/horizontal-pod-autoscalers) ## Opinionated decisions shared by all charts diff --git a/charts/horizontal-pod-autoscalers/.helmignore b/charts/horizontal-pod-autoscalers/.helmignore new file mode 100644 index 0000000..50af031 --- /dev/null +++ b/charts/horizontal-pod-autoscalers/.helmignore @@ -0,0 +1,22 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/horizontal-pod-autoscalers/Chart.yaml b/charts/horizontal-pod-autoscalers/Chart.yaml new file mode 100644 index 0000000..705330b --- /dev/null +++ b/charts/horizontal-pod-autoscalers/Chart.yaml @@ -0,0 +1,10 @@ +apiVersion: v2 +name: horizontal-pod-autoscalers +description: Horizontal Pod Autoscalers library +home: https://github.com/wyrihaximusnet/helm-charts +icon: https://helm.wyrihaximus.net/images/charts/horizontal-pod-autoscalers.png +type: library +version: 0.1.0 +maintainers: + - name: WyriHaximus + email: helm@wyrihaximus.net diff --git a/charts/horizontal-pod-autoscalers/README.md b/charts/horizontal-pod-autoscalers/README.md new file mode 100644 index 0000000..3cc4d7f --- /dev/null +++ b/charts/horizontal-pod-autoscalers/README.md @@ -0,0 +1,29 @@ +# Horizontal Pod Autoscalers + +

+ +

+ +Opinionated helm library chart for easy creation of horizontal pod autoscalers. + +# Example + +Very basic example that uses the current apps fullname and replica count as minimum replicate count, defaults to 1024 as the max replica count: + +```gotemplate +{{- include "horizontal-pod-autoscalers.hpa" (dict "name" (include "default-backend.fullname" .) "replicas" (dict "min" .Values.replicas)) -}} +``` + +The following configuration options are available: + +```yaml +name: your-applications-deployment-name # Required, this MUST match the deployment we're autoscaling +replicas: + min: 2 # Optional, defaults to 2, but strongly suggest making it match the deployment replica count + max: 1024 # Optional, defaults to 1024 +``` + +## Opinionated decisions + +* 1024 max replica's +* scales when average CPU usage goes above 50% diff --git a/charts/horizontal-pod-autoscalers/ci/hpa.yaml b/charts/horizontal-pod-autoscalers/ci/hpa.yaml new file mode 100644 index 0000000..eb5c267 --- /dev/null +++ b/charts/horizontal-pod-autoscalers/ci/hpa.yaml @@ -0,0 +1 @@ +replicas: 2 diff --git a/charts/horizontal-pod-autoscalers/library-ci/hpa.yaml b/charts/horizontal-pod-autoscalers/library-ci/hpa.yaml new file mode 100644 index 0000000..8e4c93b --- /dev/null +++ b/charts/horizontal-pod-autoscalers/library-ci/hpa.yaml @@ -0,0 +1,48 @@ +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: default-backend + labels: + app: default-backend +spec: + selector: + matchLabels: + app: default-backend + replicas: {{ .Values.replicas }} + template: + metadata: + annotations: + prometheus.io/scrape: "true" + prometheus.io/port: "9696" + labels: + app: default-backend + spec: + containers: + - name: default-backend + image: "wyrihaximusnet/default-backend:random" + imagePullPolicy: Always + ports: + - name: default-backend + containerPort: 6969 + protocol: TCP + - name: metrics + containerPort: 9696 + protocol: TCP + livenessProbe: + failureThreshold: 6 + httpGet: + path: / + port: metrics + readinessProbe: + failureThreshold: 6 + httpGet: + path: / + port: metrics + startupProbe: + httpGet: + path: / + port: metrics + failureThreshold: 90 + periodSeconds: 1 +{{ include "horizontal-pod-autoscalers.hpa" (dict "name" "default-backend" "replicas" (dict "min" .Values.replicas)) }} diff --git a/charts/horizontal-pod-autoscalers/templates/_hpa.yaml b/charts/horizontal-pod-autoscalers/templates/_hpa.yaml new file mode 100644 index 0000000..634e764 --- /dev/null +++ b/charts/horizontal-pod-autoscalers/templates/_hpa.yaml @@ -0,0 +1,21 @@ +{{- define "horizontal-pod-autoscalers.hpa" }} +--- +apiVersion: autoscaling/v2beta2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ .name }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ .name }} + minReplicas: {{ .replicas.min | default 2 }} + maxReplicas: {{ .replicas.max | default 1024 }} + metrics: + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: 50 +{{- end }} diff --git a/charts/horizontal-pod-autoscalers/values.yaml b/charts/horizontal-pod-autoscalers/values.yaml new file mode 100644 index 0000000..e69de29