Skip to content

Commit

Permalink
add autoscaling for deployment to helm chart (#3221)
Browse files Browse the repository at this point in the history
  • Loading branch information
therealmanny authored and clayton-cornell committed Aug 14, 2023
1 parent e53732d commit 6a2997d
Show file tree
Hide file tree
Showing 13 changed files with 360 additions and 2 deletions.
4 changes: 4 additions & 0 deletions operations/helm/charts/grafana-agent/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ internal API changes are not present.
Unreleased
----------

0.10.0 (2023-03-09)
-------------------

### Enhancements

- Add Horizontal Pod Autoscaling for controller type deployment. (@therealmanny)
- Add affinity values. (@therealmanny)

0.9.0 (2023-03-14)
Expand Down
2 changes: 1 addition & 1 deletion operations/helm/charts/grafana-agent/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ apiVersion: v2
name: grafana-agent
description: 'Grafana Agent'
type: application
version: 0.9.0
version: 0.10.0
appVersion: 'v0.32.1'
19 changes: 18 additions & 1 deletion operations/helm/charts/grafana-agent/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Grafana Agent Helm chart

![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.9.0](https://img.shields.io/badge/Version-0.9.0-informational?style=flat-square) ![AppVersion: v0.32.1](https://img.shields.io/badge/AppVersion-v0.32.1-informational?style=flat-square)
![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![Version: 0.10.0](https://img.shields.io/badge/Version-0.10.0-informational?style=flat-square) ![AppVersion: v0.32.1](https://img.shields.io/badge/AppVersion-v0.32.1-informational?style=flat-square)

Helm chart for deploying [Grafana Agent][] to Kubernetes.

Expand Down Expand Up @@ -64,6 +64,11 @@ use the older mode (called "static mode"), set the `agent.mode` value to
| configReloader.image.repository | string | `"jimmidyson/configmap-reload"` | Repository to get config reloader image from. |
| configReloader.image.tag | string | `"v0.8.0"` | Tag of image to use for config reloading. |
| controller.affinity | object | `{}` | Affinity configuration for pods. |
| controller.autoscaling.enabled | bool | `false` | Creates a HorizontalPodAutoscaler for controller type deployment. |
| controller.autoscaling.maxReplicas | int | `5` | The upper limit for the number of replicas to which the autoscaler can scale up. |
| controller.autoscaling.minReplicas | int | `1` | The lower limit for the number of replicas to which the autoscaler can scale down. |
| controller.autoscaling.targetCPUUtilizationPercentage | int | `0` | Average CPU utilization across all relevant pods, a percentage of the requested value of the resource for the pods. Setting `targetCPUUtilizationPercentage` to 0 will disable CPU scaling. |
| controller.autoscaling.targetMemoryUtilizationPercentage | int | `80` | Average Memory utilization across all relevant pods, a percentage of the requested value of the resource for the pods. Setting `targetMemoryUtilizationPercentage` to 0 will disable Memory scaling. |
| controller.podAnnotations | object | `{}` | Extra pod annotations to add. |
| controller.podLabels | object | `{}` | Extra pod labels to add. |
| controller.priorityClassName | string | `""` | priorityClassName to apply to Grafana Agent pods. |
Expand Down Expand Up @@ -154,6 +159,18 @@ components like [discovery.kubernetes][] to work properly.

[discovery.kubernetes]: https://grafana.com/docs/agent/latest/flow/reference/components/discovery.kubernetes/

### controller.autoscaling

`controller.autoscaling.enabled` enables the creation of a HorizontalPodAutoscaler. It is only used when `controller.type` is set to `deployment`.

`controller.autoscaling` is intended to be used with an
[app_agent_receiver-configured][app_agent_receiver] Grafana Agent.

> **WARNING**: Using `controller.autoscaling` for any other Grafana Agent
> configuration could lead to redundant or double telemetry collection.
[app_agent_receiver]: https://grafana.com/docs/agent/latest/configuration/integrations/integrations-next/app-agent-receiver-config/

## Collecting logs from other containers

There are two ways to collect logs from other containers within the cluster
Expand Down
12 changes: 12 additions & 0 deletions operations/helm/charts/grafana-agent/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,18 @@ components like [discovery.kubernetes][] to work properly.

[discovery.kubernetes]: https://grafana.com/docs/agent/latest/flow/reference/components/discovery.kubernetes/

### controller.autoscaling

`controller.autoscaling.enabled` enables the creation of a HorizontalPodAutoscaler. It is only used when `controller.type` is set to `deployment`.

`controller.autoscaling` is intended to be used with an
[app_agent_receiver-configured][app_agent_receiver] Grafana Agent.

> **WARNING**: Using `controller.autoscaling` for any other Grafana Agent
> configuration could lead to redundant or double telemetry collection.

[app_agent_receiver]: https://grafana.com/docs/agent/latest/configuration/integrations/integrations-next/app-agent-receiver-config/

## Collecting logs from other containers

There are two ways to collect logs from other containers within the cluster
Expand Down
34 changes: 34 additions & 0 deletions operations/helm/charts/grafana-agent/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if and (eq .Values.controller.type "deployment") .Values.controller.autoscaling.enabled }}
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "grafana-agent.fullname" . }}
labels:
{{- include "grafana-agent.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "grafana-agent.fullname" . }}
{{- with .Values.controller.autoscaling }}
minReplicas: {{ .minReplicas }}
maxReplicas: {{ .maxReplicas }}
metrics:
{{- with .targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- with .targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: {{ . }}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Test rendering of the chart with the controller explicitly set to Deployment and autoscaling enabled.
controller:
type: deployment
autoscaling:
enabled: true
12 changes: 12 additions & 0 deletions operations/helm/charts/grafana-agent/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ controller:
# -- Extra pod labels to add.
podLabels: {}

autoscaling:
# -- Creates a HorizontalPodAutoscaler for controller type deployment.
enabled: false
# -- The lower limit for the number of replicas to which the autoscaler can scale down.
minReplicas: 1
# -- The upper limit for the number of replicas to which the autoscaler can scale up.
maxReplicas: 5
# -- Average CPU utilization across all relevant pods, a percentage of the requested value of the resource for the pods. Setting `targetCPUUtilizationPercentage` to 0 will disable CPU scaling.
targetCPUUtilizationPercentage: 0
# -- Average Memory utilization across all relevant pods, a percentage of the requested value of the resource for the pods. Setting `targetMemoryUtilizationPercentage` to 0 will disable Memory scaling.
targetMemoryUtilizationPercentage: 80

# -- Affinity configuration for pods.
affinity: {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
# Source: grafana-agent/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-agent
labels:
helm.sh/chart: grafana-agent
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
data:
config.river: |-
logging {
level = "info"
format = "logfmt"
}
discovery.kubernetes "pods" {
role = "pod"
}
discovery.kubernetes "nodes" {
role = "node"
}
discovery.kubernetes "services" {
role = "service"
}
discovery.kubernetes "endpoints" {
role = "endpoints"
}
discovery.kubernetes "endpointslices" {
role = "endpointslice"
}
discovery.kubernetes "ingresses" {
role = "ingress"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
---
# Source: grafana-agent/templates/controllers/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: grafana-agent
labels:
helm.sh/chart: grafana-agent
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
spec:
replicas: 1
minReadySeconds: 10
selector:
matchLabels:
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
template:
metadata:
labels:
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
spec:
serviceAccount: grafana-agent
containers:
- name: grafana-agent
image: grafana/agent:v0.32.1
imagePullPolicy: IfNotPresent
args:
- run
- /etc/agent/config.river
- --storage.path=/tmp/agent
- --server.http.listen-addr=0.0.0.0:80
env:
- name: AGENT_MODE
value: flow
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
ports:
- containerPort: 80
name: http-metrics
- containerPort: 12347
name: faro
readinessProbe:
httpGet:
path: /-/ready
port: 80
initialDelaySeconds: 10
timeoutSeconds: 1
volumeMounts:
- name: config
mountPath: /etc/agent
- name: config-reloader
image: jimmidyson/configmap-reload:v0.8.0
args:
- --volume-dir=/etc/agent
- --webhook-url=http://localhost:80/-/reload
volumeMounts:
- name: config
mountPath: /etc/agent
volumes:
- name: config
configMap:
name: grafana-agent
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
# Source: grafana-agent/templates/hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: grafana-agent
labels:
helm.sh/chart: grafana-agent
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: grafana-agent
minReplicas: 1
maxReplicas: 5
metrics:
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
---
# Source: grafana-agent/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: grafana-agent
labels:
helm.sh/chart: grafana-agent
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
rules:
# Rules which allow discovery.kubernetes to function.
- apiGroups:
- ""
- "discovery.k8s.io"
- "networking.k8s.io"
resources:
- endpoints
- endpointslices
- ingresses
- nodes
- nodes/proxy
- pods
- services
verbs:
- get
- list
- watch
# Rules which allow loki.source.kubernetes and loki.source.podlogs to work.
- apiGroups:
- ""
resources:
- pods
- pods/log
- namespaces
verbs:
- get
- list
- watch
- apiGroups:
- "monitoring.grafana.com"
resources:
- podlogs
verbs:
- get
- list
- watch
# Rules which allow mimir.rules.kubernetes to work.
- apiGroups: ["monitoring.coreos.com"]
resources:
- prometheusrules
verbs:
- get
- list
- watch
- nonResourceURLs:
- /metrics
verbs:
- get
# Rules for prometheus.kubernetes.*
- apiGroups: ["monitoring.coreos.com"]
resources:
- podmonitors
- servicemonitors
- probes
verbs:
- get
- list
- watch
# Rules which allow eventhandler to work.
- apiGroups:
- ""
resources:
- events
verbs:
- get
- list
- watch
---
# Source: grafana-agent/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: grafana-agent
labels:
helm.sh/chart: grafana-agent
app.kubernetes.io/name: grafana-agent
app.kubernetes.io/instance: grafana-agent
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: grafana-agent
subjects:
- kind: ServiceAccount
name: grafana-agent
namespace: default
Loading

0 comments on commit 6a2997d

Please sign in to comment.