Skip to content

Commit

Permalink
Merge pull request #37 from fahad-rauf/add-hpa
Browse files Browse the repository at this point in the history
Add hpa support
  • Loading branch information
usamaahmadkhan authored Jun 24, 2020
2 parents 5d6118c + 49102c4 commit 7cfbbbb
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,9 @@ To uninstall the chart:
| serviceMonitor.annotations | Annotations for serviceMonitor | `{}` |
| serviceMonitor.jobLabel | Job Label used for application selector | `k8s-app` |
| serviceMonitor.endpoints | Array of endpoints to be scraped by prometheus | - interval: 5s<br>&nbsp;&nbsp;path: /actuator/prometheus<br>&nbsp;&nbsp;port: http |
| autoscaling.enabled | Enable horizontal pod autoscaler | `false` |
| autoscaling.additionalLabels | Labels for horizontal pod autoscaler | `{}` |
| autoscaling.annotations | Annotations for horizontal pod autoscaler | `{}` |
| autoscaling.minReplicas | Sets minimum replica count when autoscaling is enabled | `1` |
| autoscaling.maxReplicas | Sets maximum replica count when autoscaling is enabled | `10` |
| autoscaling.metrics | Configuration for hpa metrics, set when autoscaling is enabled | `{}` |
25 changes: 25 additions & 0 deletions application/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{- if and .Values.autoscaling.enabled .Values.deployment }}
apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
name: {{ template "application.name" . }}
labels:
{{ include "application.labels.stakater" . | nindent 4 }}
{{ include "application.labels.chart" . | nindent 4 }}
{{- if .Values.autoscaling.additionalLabels }}
{{- toYaml .Values.autoscaling.additionalLabels | nindent 4 }}
{{- end }}
{{- if .Values.autoscaling.annotations }}
annotations:
{{- toYaml .Values.autoscaling.annotations | nindent 4 }}
{{- end }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ template "application.name" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- toYaml .Values.autoscaling.metrics | nindent 4 }}
{{- end }}
27 changes: 26 additions & 1 deletion application/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,29 @@ serviceMonitor:
endpoints:
- interval: 5s
path: /actuator/prometheus
port: http
port: http

# autoscaling is used for horizonal pod autoscaling
autoscaling:
# enabled is a boolean flag for enabling or disabling autoscaling
enabled: false
# additionalLabels defines additional labels
additionalLabels:
# key: value
# annotations defines annotations in key value pair
annotations:
# key: value
# minReplicas sets the minimum number of replicas
minReplicas: 1
# maxReplicas sets the maximum number of replicas
maxReplicas: 10
# metrics is the list of metrics used for hpa
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: 60
- type: Resource
resource:
name: memory
targetAverageUtilization: 60

0 comments on commit 7cfbbbb

Please sign in to comment.