|
| 1 | +# Prometheus Adapter |
| 2 | + |
| 3 | +Installs the [Prometheus Adapter](https://github.com/kubernetes-sigs/prometheus-adapter) for the Custom Metrics API. Custom metrics are used in Kubernetes by [Horizontal Pod Autoscalers](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) to scale workloads based upon your own metric pulled from an external metrics provider like Prometheus. This chart complements the [metrics-server](https://github.com/helm/charts/tree/master/stable/metrics-server) chart that provides resource only metrics. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +Kubernetes 1.14+ |
| 8 | + |
| 9 | +## Get Helm Repositories Info |
| 10 | + |
| 11 | +```console |
| 12 | +helm repo add prometheus-community https://prometheus-community.github.io/helm-charts |
| 13 | +helm repo update |
| 14 | +``` |
| 15 | + |
| 16 | +_See [`helm repo`](https://helm.sh/docs/helm/helm_repo/) for command documentation._ |
| 17 | + |
| 18 | +## Install Helm Chart |
| 19 | + |
| 20 | +```console |
| 21 | +helm install [RELEASE_NAME] prometheus-community/prometheus-adapter |
| 22 | +``` |
| 23 | + |
| 24 | +_See [configuration](#configuration) below._ |
| 25 | + |
| 26 | +_See [helm install](https://helm.sh/docs/helm/helm_install/) for command documentation._ |
| 27 | + |
| 28 | +## Uninstall Helm Chart |
| 29 | + |
| 30 | +```console |
| 31 | +helm uninstall [RELEASE_NAME] |
| 32 | +``` |
| 33 | + |
| 34 | +This removes all the Kubernetes components associated with the chart and deletes the release. |
| 35 | + |
| 36 | +_See [helm uninstall](https://helm.sh/docs/helm/helm_uninstall/) for command documentation._ |
| 37 | + |
| 38 | +## Upgrading Helm Chart |
| 39 | + |
| 40 | +```console |
| 41 | +helm upgrade [RELEASE_NAME] [CHART] --install |
| 42 | +``` |
| 43 | + |
| 44 | +_See [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) for command documentation._ |
| 45 | + |
| 46 | +### To 4.2.0 |
| 47 | + |
| 48 | +Readiness and liveness probes are now fully configurable through values `readinessProbe` and `livenessProbe`. The previous values have been kept as defaults. |
| 49 | + |
| 50 | +### To 4.0.0 |
| 51 | + |
| 52 | +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, 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`. |
| 53 | + |
| 54 | +### To 3.0.0 |
| 55 | + |
| 56 | +Due to a change in deployment labels, the upgrade requires `helm upgrade --force` in order to re-create the deployment. |
| 57 | + |
| 58 | +## Configuration |
| 59 | + |
| 60 | +See [Customizing the Chart Before Installing](https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing). To see all configurable options with detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands: |
| 61 | + |
| 62 | +```console |
| 63 | +helm show values prometheus-community/prometheus-adapter |
| 64 | +``` |
| 65 | + |
| 66 | +### Prometheus Service Endpoint |
| 67 | + |
| 68 | +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`. |
| 69 | + |
| 70 | +### Adapter Rules |
| 71 | + |
| 72 | +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](https://github.com/kubernetes-sigs/prometheus-adapter/blob/master/docs/config.md) for the proper format). |
| 73 | + |
| 74 | +### Horizontal Pod Autoscaler Metrics |
| 75 | + |
| 76 | +Finally, to configure your Horizontal Pod Autoscaler to use the custom metric, see the custom metrics section of the [HPA walkthrough](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-multiple-metrics-and-custom-metrics). |
| 77 | + |
| 78 | +The Prometheus Adapter can serve three different [metrics APIs](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis): |
| 79 | + |
| 80 | +### Custom Metrics |
| 81 | + |
| 82 | +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`: |
| 83 | + |
| 84 | +```yaml |
| 85 | +rules: |
| 86 | + custom: |
| 87 | + - seriesQuery: '{__name__=~"^some_metric_count$"}' |
| 88 | + resources: |
| 89 | + template: <<.Resource>> |
| 90 | + name: |
| 91 | + matches: "" |
| 92 | + as: "my_custom_metric" |
| 93 | + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>) |
| 94 | +``` |
| 95 | +
|
| 96 | +### External Metrics |
| 97 | +
|
| 98 | +Enabling this option will cause external metrics to be served at `/apis/external.metrics.k8s.io/v1beta1`. Can be enabled by populating `rules.external`: |
| 99 | + |
| 100 | +```yaml |
| 101 | +rules: |
| 102 | + external: |
| 103 | + - seriesQuery: '{__name__=~"^some_metric_count$"}' |
| 104 | + resources: |
| 105 | + template: <<.Resource>> |
| 106 | + name: |
| 107 | + matches: "" |
| 108 | + as: "my_external_metric" |
| 109 | + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>) |
| 110 | +``` |
| 111 | + |
| 112 | +### Resource Metrics |
| 113 | + |
| 114 | +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](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/) as well as the `kubectl top` command. Can be enabled by populating `rules.resource`: |
| 115 | + |
| 116 | +```yaml |
| 117 | +rules: |
| 118 | + resource: |
| 119 | + cpu: |
| 120 | + containerQuery: | |
| 121 | + sum by (<<.GroupBy>>) ( |
| 122 | + rate(container_cpu_usage_seconds_total{container!="",<<.LabelMatchers>>}[3m]) |
| 123 | + ) |
| 124 | + nodeQuery: | |
| 125 | + sum by (<<.GroupBy>>) ( |
| 126 | + rate(node_cpu_seconds_total{mode!="idle",mode!="iowait",mode!="steal",<<.LabelMatchers>>}[3m]) |
| 127 | + ) |
| 128 | + resources: |
| 129 | + overrides: |
| 130 | + node: |
| 131 | + resource: node |
| 132 | + namespace: |
| 133 | + resource: namespace |
| 134 | + pod: |
| 135 | + resource: pod |
| 136 | + containerLabel: container |
| 137 | + memory: |
| 138 | + containerQuery: | |
| 139 | + sum by (<<.GroupBy>>) ( |
| 140 | + avg_over_time(container_memory_working_set_bytes{container!="",<<.LabelMatchers>>}[3m]) |
| 141 | + ) |
| 142 | + nodeQuery: | |
| 143 | + sum by (<<.GroupBy>>) ( |
| 144 | + avg_over_time(node_memory_MemTotal_bytes{<<.LabelMatchers>>}[3m]) |
| 145 | + - |
| 146 | + avg_over_time(node_memory_MemAvailable_bytes{<<.LabelMatchers>>}[3m]) |
| 147 | + ) |
| 148 | + resources: |
| 149 | + overrides: |
| 150 | + node: |
| 151 | + resource: node |
| 152 | + namespace: |
| 153 | + resource: namespace |
| 154 | + pod: |
| 155 | + resource: pod |
| 156 | + containerLabel: container |
| 157 | + window: 3m |
| 158 | +``` |
| 159 | + |
| 160 | +**NOTE:** Setting a value for `rules.resource` will also deploy the resource metrics API service, providing the same functionality as [metrics-server](https://github.com/helm/charts/tree/master/stable/metrics-server). As such it is not possible to deploy them both in the same cluster. |
0 commit comments