Skip to content

Commit d813f08

Browse files
Merge pull request #36 from kubeservice-stack/feat-add-adpater
Feat: add prometheus adpater rules and prometheus recoding rules
2 parents 132b388 + 119f119 commit d813f08

32 files changed

Lines changed: 1416 additions & 1 deletion

metrics/Chart.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ dependencies:
4040
name: karma
4141
repository: https://wiremind.github.io/wiremind-helm-charts
4242
version: 1.*.*
43+
- condition: prometheus-adapter.enabled
44+
name: prometheus-adapter
45+
repository: https://prometheus-community.github.io/helm-charts
46+
version: 4.*.*
4347
description: kube-prometheus-stack collects Kubernetes manifests, Grafana dashboards,
4448
and Prometheus rules combined with documentation and scripts to provide easy to
4549
operate end-to-end Kubernetes cluster monitoring with Prometheus using the Prometheus
@@ -71,4 +75,4 @@ sources:
7175
- https://github.com/prometheus-community/helm-charts
7276
- https://github.com/prometheus-operator/kube-prometheus
7377
type: application
74-
version: 41.7.1
78+
version: 41.8.0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Patterns to ignore when building packages.
2+
# This supports shell glob matching, relative path matching, and
3+
# negation (prefixed with !). Only one pattern per line.
4+
.DS_Store
5+
# Common VCS dirs
6+
.git/
7+
.gitignore
8+
.bzr/
9+
.bzrignore
10+
.hg/
11+
.hgignore
12+
.svn/
13+
# Common backup files
14+
*.swp
15+
*.bak
16+
*.tmp
17+
*~
18+
# Various IDEs
19+
.project
20+
.idea/
21+
*.tmproj
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
apiVersion: v1
2+
name: prometheus-adapter
3+
version: 4.7.1
4+
appVersion: v0.11.1
5+
description: A Helm chart for k8s prometheus adapter
6+
home: https://github.com/kubernetes-sigs/prometheus-adapter
7+
keywords:
8+
- hpa
9+
- metrics
10+
- prometheus
11+
- adapter
12+
sources:
13+
- https://github.com/kubernetes/charts
14+
- https://github.com/kubernetes-sigs/prometheus-adapter
15+
maintainers:
16+
- name: mattiasgees
17+
email: mattias.gees@jetstack.io
18+
- name: steven-sheehy
19+
- name: hectorj2f
20+
email: hfernandez@mesosphere.com
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
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.

metrics/charts/prometheus-adapter/ci/default-values.yaml

Whitespace-only changes.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rules:
2+
external:
3+
- seriesQuery: '{__name__=~"^some_metric_count$"}'
4+
resources:
5+
template: <<.Resource>>
6+
name:
7+
matches: ""
8+
as: "my_custom_metric"
9+
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ template "k8s-prometheus-adapter.fullname" . }} has been deployed.
2+
In a few minutes you should be able to list metrics using the following command(s):
3+
{{ if .Values.rules.resource }}
4+
kubectl get --raw /apis/metrics.k8s.io/v1beta1
5+
{{- end }}
6+
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
7+
{{ if .Values.rules.external }}
8+
kubectl get --raw /apis/external.metrics.k8s.io/v1beta1
9+
{{- end }}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
{{/* vim: set filetype=mustache: */}}
2+
{{/*
3+
Expand the name of the chart.
4+
*/}}
5+
{{- define "k8s-prometheus-adapter.name" -}}
6+
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
7+
{{- end -}}
8+
9+
{{/*
10+
Create a default fully qualified app name.
11+
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
12+
If release name contains chart name it will be used as a full name.
13+
*/}}
14+
{{- define "k8s-prometheus-adapter.fullname" -}}
15+
{{- if .Values.fullnameOverride -}}
16+
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
17+
{{- else -}}
18+
{{- $name := default .Chart.Name .Values.nameOverride -}}
19+
{{- if contains $name .Release.Name -}}
20+
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
21+
{{- else -}}
22+
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
23+
{{- end -}}
24+
{{- end -}}
25+
{{- end -}}
26+
27+
{{/*
28+
Allow the release namespace to be overridden for multi-namespace deployments in combined charts
29+
*/}}
30+
{{- define "k8s-prometheus-adapter.namespace" -}}
31+
{{- default .Release.Namespace .Values.namespaceOverride -}}
32+
{{- end -}}
33+
34+
{{/*
35+
Create chart name and version as used by the chart label.
36+
*/}}
37+
{{- define "k8s-prometheus-adapter.chart" -}}
38+
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
39+
{{- end -}}
40+
41+
{{/*
42+
Generate basic labels
43+
*/}}
44+
{{- define "k8s-prometheus-adapter.labels" }}
45+
helm.sh/chart: {{ include "k8s-prometheus-adapter.chart" . }}
46+
app.kubernetes.io/managed-by: {{ .Release.Service }}
47+
app.kubernetes.io/component: metrics
48+
app.kubernetes.io/part-of: {{ template "k8s-prometheus-adapter.name" . }}
49+
{{- include "k8s-prometheus-adapter.selectorLabels" . }}
50+
{{- if .Chart.AppVersion }}
51+
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
52+
{{- end }}
53+
{{- if .Values.customLabels }}
54+
{{ toYaml .Values.customLabels }}
55+
{{- end }}
56+
{{- end }}
57+
58+
{{/*
59+
Selector labels
60+
*/}}
61+
{{- define "k8s-prometheus-adapter.selectorLabels" }}
62+
app.kubernetes.io/name: {{ include "k8s-prometheus-adapter.name" . }}
63+
app.kubernetes.io/instance: {{ .Release.Name }}
64+
{{- end }}
65+
66+
{{/*
67+
Create the name of the service account to use
68+
*/}}
69+
{{- define "k8s-prometheus-adapter.serviceAccountName" -}}
70+
{{- if .Values.serviceAccount.create -}}
71+
{{ default (include "k8s-prometheus-adapter.fullname" .) .Values.serviceAccount.name }}
72+
{{- else -}}
73+
{{ default "default" .Values.serviceAccount.name }}
74+
{{- end -}}
75+
{{- end -}}
76+
77+
{{/* Get Policy API Version */}}
78+
{{- define "k8s-prometheus-adapter.pdb.apiVersion" -}}
79+
{{- if and (.Capabilities.APIVersions.Has "policy/v1") (semverCompare ">= 1.21-0" .Capabilities.KubeVersion.Version) -}}
80+
{{- print "policy/v1" -}}
81+
{{- else -}}
82+
{{- print "policy/v1beta1" -}}
83+
{{- end -}}
84+
{{- end -}}

0 commit comments

Comments
 (0)