[stable/prometheus-adapter] add new resourceRules in values (#14508)

* [stable/prometheus-adapter] add new resourceRules

prometheus-adapter supports resourceRules. Enabling this allows serving metrics on metrics.k8s.io/v1beta1, where the HPA queries for CPU and mem metrics.

Signed-off-by: Dimitri Koshkin <dimitri.koshkin@gmail.com>

* [stable/prometheus-adapter] bump interval to 3m

Signed-off-by: Dimitri Koshkin <dimitri.koshkin@gmail.com>
This commit is contained in:
Dimitri Koshkin
2019-06-06 09:42:16 -07:00
committed by Kubernetes Prow Robot
parent 5ac4b37ce0
commit a84f6ebb60
8 changed files with 169 additions and 6 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
apiVersion: v1
name: prometheus-adapter
version: 1.0.4
version: 1.1.0
appVersion: v0.5.0
description: A Helm chart for k8s prometheus adapter
home: https://github.com/DirectXMan12/k8s-prometheus-adapter
+65
View File
@@ -20,6 +20,70 @@ This command deploys the prometheus adapter with the default configuration. The
To use the chart, ensure the `prometheus.url` and `prometheus.port` are configured with the correct Prometheus service endpoint. 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/DirectXMan12/k8s-prometheus-adapter/blob/master/docs/config.md) for the proper format). 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).
The Prometheus Adapter can serve three different [metrics APIs](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/#support-for-metrics-apis):
* `/apis/custom.metrics.k8s.io/v1beta1`
Can be enabled using values file as such:
```
rules:
custom:
- seriesQuery: '{__name__=~"^some_metric_count$"}'
resources:
template: <<.Resource>>
name:
matches: ""
as: "my_custom_metric"
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
```
* `/apis/external.metrics.k8s.io/v1beta1`
Can be enabled using values file as such:
```
rules:
external:
- seriesQuery: '{__name__=~"^some_metric_count$"}'
resources:
template: <<.Resource>>
name:
matches: ""
as: "my_external_metric"
metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
```
* `/apis/metrics.k8s.io/v1beta1`
Can be enabled using values file as such, using the configuration below will allow you to use pod CPU and Memory utilization for [Horizontal Pod Autoscalers](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale/), as well as the `kubectl top` command:
```
rules:
resource:
cpu:
containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[3m])) by (<<.GroupBy>>)
nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[3m])) by (<<.GroupBy>>)
resources:
overrides:
instance:
resource: node
namespace:
resource: namespace
pod_name:
resource: pod
containerLabel: container_name
memory:
containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>)
nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>)
resources:
overrides:
instance:
resource: node
namespace:
resource: namespace
pod_name:
resource: pod
containerLabel: container_name
window: 3m
```
**NOTE:** setting a value for `resource:` will also deploy the `v1beta1.metrics.k8s.io` `APIService`, providing the same functionality as the [metrics-server](https://github.com/helm/charts/tree/master/stable/metrics-server), and as such it is not possible to deploy both in the same cluster.
## Uninstalling the Chart
To uninstall/delete the `my-release` deployment:
@@ -52,6 +116,7 @@ The following table lists the configurable parameters of the Prometheus Adapter
| `rules.custom` | A list of custom configmap rules | `[]` |
| `rules.existing` | The name of an existing configMap with rules. Overrides default, custom and external. | `` |
| `rules.external` | A list of custom rules for external metrics API | `[]` |
| `rules.resource` | `resourceRules` to set in configmap rules | `{}` |
| `service.annotations` | Annotations to add to the service | `{}` |
| `service.port` | Service port to expose | `443` |
| `service.type` | Type of service to create | `ClusterIP` |
@@ -1,5 +1,9 @@
{{ template "k8s-prometheus-adapter.fullname" . }} has been deployed.
In a few minutes you should be able to list metrics using the following command:
In a few minutes you should be able to list metrics using the following command(s):
{{ if .Values.rules.resource }}
kubectl get --raw /apis/metrics.k8s.io/v1beta1
{{- end }}
kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1
{{ if .Values.rules.external }}
kubectl get --raw /apis/external.metrics.k8s.io/v1beta1
{{- end }}
@@ -86,4 +86,8 @@ data:
externalRules:
{{ toYaml .Values.rules.external | indent 4 }}
{{- end -}}
{{- if .Values.rules.resource }}
resourceRules:
{{ toYaml .Values.rules.resource | indent 6 }}
{{- end -}}
{{- end -}}
@@ -0,0 +1,23 @@
{{- if .Values.rules.resource}}
apiVersion: apiregistration.k8s.io/v1beta1
kind: APIService
metadata:
labels:
app: {{ template "k8s-prometheus-adapter.name" . }}
chart: {{ template "k8s-prometheus-adapter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: v1beta1.metrics.k8s.io
spec:
service:
name: {{ template "k8s-prometheus-adapter.fullname" . }}
namespace: {{ .Release.Namespace | quote }}
{{ if .Values.tls.enable -}}
caBundle: {{ b64enc .Values.tls.ca }}
{{- end }}
group: metrics.k8s.io
version: v1beta1
insecureSkipTLSVerify: {{ if .Values.tls.enable }}false{{ else }}true{{ end }}
groupPriorityMinimum: 100
versionPriority: 100
{{- end -}}
@@ -0,0 +1,19 @@
{{- if and .Values.rbac.create .Values.rules.resource -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
labels:
app: {{ template "k8s-prometheus-adapter.name" . }}
chart: {{ template "k8s-prometheus-adapter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ template "k8s-prometheus-adapter.name" . }}-hpa-controller-metrics
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ template "k8s-prometheus-adapter.name" . }}-metrics
subjects:
- kind: ServiceAccount
name: {{ template "k8s-prometheus-adapter.serviceAccountName" . }}
namespace: {{ .Release.Namespace | quote }}
{{- end -}}
@@ -0,0 +1,22 @@
{{- if and .Values.rbac.create .Values.rules.resource -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
labels:
app: {{ template "k8s-prometheus-adapter.name" . }}
chart: {{ template "k8s-prometheus-adapter.chart" . }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ template "k8s-prometheus-adapter.name" . }}-metrics
rules:
- apiGroups:
- ""
resources:
- pods
- nodes
- nodes/stats
verbs:
- get
- list
- watch
{{- end -}}
+28 -2
View File
@@ -49,7 +49,7 @@ rules:
# as: "my_custom_metric"
# metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
# Mounts a configMap with pre-generated rules for use. Overrides the
# default, custom and external entries
# default, custom, external and resource entries
existing:
external: []
# - seriesQuery: '{__name__=~"^some_metric_count$"}'
@@ -57,8 +57,34 @@ rules:
# template: <<.Resource>>
# name:
# matches: ""
# as: "my_custom_metric"
# as: "my_external_metric"
# metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)
resource: {}
# cpu:
# containerQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>}[3m])) by (<<.GroupBy>>)
# nodeQuery: sum(rate(container_cpu_usage_seconds_total{<<.LabelMatchers>>, id='/'}[3m])) by (<<.GroupBy>>)
# resources:
# overrides:
# instance:
# resource: node
# namespace:
# resource: namespace
# pod_name:
# resource: pod
# containerLabel: container_name
# memory:
# containerQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>}) by (<<.GroupBy>>)
# nodeQuery: sum(container_memory_working_set_bytes{<<.LabelMatchers>>,id='/'}) by (<<.GroupBy>>)
# resources:
# overrides:
# instance:
# resource: node
# namespace:
# resource: namespace
# pod_name:
# resource: pod
# containerLabel: container_name
# window: 3m
service:
annotations: {}