prometheus-adapter
by Prometheus
A Helm chart for k8s prometheus adapter
About this chart
Prometheus Adapter
Installs the Prometheus Adapter for the Custom Metrics API. Custom metrics are used in Kubernetes by Horizontal Pod Autoscalers to scale workloads based upon your own metric pulled from an external metrics provider like Prometheus. This chart complements the metrics-server chart that provides resource only metrics.
Prerequisites
Kubernetes 1.21+
Usage
The chart is distributed as an OCI Artifact as well as via a traditional Helm Repository.
- OCI Artifact:
oci://ghcr.io/prometheus-community/charts/prometheus-adapter - Helm Repository:
https://prometheus-community.github.io/helm-chartswith chartprometheus-adapter
The installation instructions use the OCI registry. Refer to the helm repo command documentation for information on installing charts via the traditional repository.
Install Helm Chart
helm install [RELEASE_NAME] oci://ghcr.io/prometheus-community/charts/prometheus-adapter
See configuration below.
See helm install for command documentation.
Uninstall Helm Chart
helm uninstall [RELEASE_NAME]
This removes all the Kubernetes components associated with the chart and deletes the release.
See helm uninstall for command documentation.
Upgrading Helm Chart
helm upgrade [RELEASE_NAME] [CHART] --install
See helm upgrade for command documentation.
To 5.0.0
This version removes support for the deprecated Kubernetes API policy/v1beta1 for PodDisruptionBudgets. It also removes the deprecated PodSecurityPolicy resource. Minimum Kubernetes version >= 1.21 is now required.
To 4.2.0
Readiness and liveness probes are now fully configurable through values readinessProbe and livenessProbe. The previous values have been kept as defaults.
To 4.0.0
Previously, security context of the container was set directly in the deployment template. This release makes it configurable through the new configuration variable securityContext whilst keeping the previously set values as defaults. Furthermore, the previous variable runAsUser is now set in securityContext and is not used any longer. Please, use securityContext.runAsUser instead. In the same security context, seccompProfile has been enabled and set to type RuntimeDefault.
To 3.0.0
Due to a change in deployment labels, the upgrade requires helm upgrade --force in order to re-create the deployment.
Configuration
See Customizing the Chart Before Installing. To see all configurable options with detailed comments, visit the chart's values.yaml, or run these configuration commands:
helm show values oci://ghcr.io/prometheus-community/charts/prometheus-adapter
Prometheus Service Endpoint
To use the chart, ensure the prometheus.url and prometheus.port are configured with the correct Prometheus service endpoint. If Prometheus is exposed under HTTPS the host's CA Bundle must be exposed to the container using extraVolumes and extraVolumeMounts.
Adapter Rules
Additionally, the chart comes with a set of default rules out of the box but they may pull in too many metrics or not map them correctly for your needs. Therefore, it is recommended to populate rules.custom with a list of rules (see the config document for the proper format).
Horizontal Pod Autoscaler Metrics
Finally, to configure your Horizontal Pod Autoscaler to use the custom metric, see the custom metrics section of the HPA walkthrough.
The Prometheus Adapter can serve three different metrics APIs:
Custom Metrics
Enabling this option will cause custom metrics to be served at /apis/custom.metrics.k8s.io/v1beta1. Enabled by default when rules.default is true, but can be customized by populating rules.custom:
rules:
custom:
- seriesQuery: '{__name__=~"^some_metric_count$"}'
resources:
template: <<.Resource>>
name:
matches: ""
as: "my_custom_metric"
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
External Metrics
Enabling this option will cause external metrics to be served at /apis/external.metrics.k8s.io/v1beta1. Can be enabled by populating rules.external:
rules:
external:
- seriesQuery: '{__name__=~"^some_metric_count$"}'
resources:
template: <<.Resource>>
name:
matches: ""
as: "my_external_metric"
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
Resource Metrics
Enabling this option will cause resource metrics to be served at /apis/metrics.k8s.io/v1beta1. Resource metrics will allow pod CPU and Memory metrics to be used in Horizontal Pod Autoscalers as well as the kubectl top command. Can be enabled by populating rules.resource:
rules:
resource:
cpu:
containerQuery: |
sum by (<<.GroupBy>>) (
rate(container_cpu_usage_seconds_total{container!="",<<.LabelMatchers>>}[3m])
)
nodeQuery: |
sum by (<<.GroupBy>>) (
rate(node_cpu_seconds_total{mode!="idle",mode!="iowait",mode!="steal",<<.LabelMatchers>>}[3m])
)
resources:
overrides:
node:
resource: node
namespace:
resource: namespace
pod:
resource: pod
containerLabel: container
memory:
containerQuery: |
round(sum by (<<.GroupBy>>) (
avg_over_time(container_memory_working_set_bytes{container!="",<<.LabelMatchers>>}[3m])
))
nodeQuery: |
round(sum by (<<.GroupBy>>) (
avg_over_time(node_memory_MemTotal_bytes{<<.LabelMatchers>>}[3m])
-
avg_over_time(node_memory_MemAvailable_bytes{<<.LabelMatchers>>}[3m])
))
resources:
overrides:
node:
resource: node
namespace:
resource: namespace
pod:
resource: pod
containerLabel: container
window: 3m
NOTE: Setting a value for rules.resource will also deploy the resource metrics API service, providing the same functionality as metrics-server. As such it is not possible to deploy them both in the same cluster.
Deploy prometheus-adapter with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has prometheus-adapter on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartprometheus-adapter is pinned at v5.4.2 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply