Skip to content

Commit

Permalink
[stable/prometheus-adapter] Enhancements (helm#7183)
Browse files Browse the repository at this point in the history
* stable/prometheus-adapter enhancements

* Fix linting issues

Signed-off-by: aba182 <ajwilhel@gmail.com>
  • Loading branch information
Steven Sheehy authored and aba182 committed Sep 7, 2018
1 parent 5e3a0bf commit 710e696
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 37 deletions.
21 changes: 21 additions & 0 deletions stable/prometheus-adapter/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
2 changes: 1 addition & 1 deletion stable/prometheus-adapter/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: prometheus-adapter
version: v0.0.1
version: v0.1.0
appVersion: v0.2.1
description: A Helm chart for k8s prometheus adapter
home: https://github.com/DirectXMan12/k8s-prometheus-adapter
Expand Down
47 changes: 23 additions & 24 deletions stable/prometheus-adapter/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Prometheus Adapter

* Installs [Prometheus-adapter](https://github.com/DirectXMan12/k8s-prometheus-adapter).

## TL;DR;

```console
$ helm install stable/prometheus-adapter
```

## Introduction

This charts install the [Prometheus Adapter](https://github.com/DirectXMan12/k8s-prometheus-adapter) on your kubernetes clutser using the [Helm](https://helm.sh) package manager.
Installs the [Prometheus Adapter](https://github.com/DirectXMan12/k8s-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.

## Prerequisites

Expand All @@ -24,7 +14,11 @@ To install the chart with the release name `my-release`:
$ helm install --name my-release stable/prometheus-adapter
```

This command deploys the prometheus operator with the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.
This command deploys the prometheus adapter with the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation.

## Using the Chart

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).

## Uninstalling the Chart

Expand All @@ -42,24 +36,29 @@ The following table lists the configurable parameters of the Prometheus Adapter

| Parameter | Description | Default |
| ------------------------------- | ------------------------------------------------------------------------------- | --------------------------------------------|
| `affinity` | Node affinity | `{}` |
| `image.repository` | Image repository | `directxman12/k8s-prometheus-adapter-amd64` |
| `image.tag` | Image tag | `latest` |
| `image.tag` | Image tag | `v0.2.1` |
| `image.pullPolicy` | Image pull policy | `IfNotPresent` |
| `resources.limits.cpu` | CPU limit | `100m` |
| `resources.limits.memory` | Memory limit | `128Mi` |
| `resources.requests.cpu` | CPU request | `100m` |
| `resources.requests.memory` | Memory request | `128Mi` |
| `logLevel` | Log level | `4` |
| `metricsRelistInterval` | Interval at which to re-list the set of all available metrics from Prometheus | `30s` |
| `nodeSelector` | Node labels for pod assignment | `{}` |
| `prometheus.url` | Url of where we can find the Prometheus service | `http://prometheus.default.svc` |
| `prometheus.port` | Port of where we can find the Prometheus service | `9090` |
| `rbac.create` | If true, create & use RBAC resources | `true` |
| `serviceaccount.create` | If true, create & use Serviceaccount | `true` |
| `serviceaccount.name` | If not set and create is true, a name is generated using the fullname template | `` |
| `tls.enable` | If true, setup & use secret for TLS | `false` |
| `resources` | CPU/Memory resource requests/limits | `{}` |
| `rules.default` | If `true`, enable a set of default rules in the configmap | `true` |
| `rules.custom` | A list of custom 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` |
| `serviceAccount.create` | If true, create & use Serviceaccount | `true` |
| `serviceAccount.name` | If not set and create is true, a name is generated using the fullname template | `` |
| `tls.enable` | If true, use the provided certificates. If false, generate self-signed certs | `false` |
| `tls.ca` | Public CA file that signed the APIService (ignored if tls.enable=false) | `` |
| `tls.key` | Private key of the APIService (ignored if tls.enable=false) | `` |
| `tls.certificate` | Public key of the APIService (ignored if tls.enable=false) | `` |
| `prometheus.url` | Url of where we can find the Prometheus service | `http://prometheus.default.svc` |
| `prometheus.port` | Port of where we can find the Prometheus service | `9090` |
| `metricsRelistInterval` | Interval at which to re-list the set of all available metrics from Prometheus | `30s` |
| `logLevel` | Log level | `10` |
| `tolerations` | List of node taints to tolerate | `[]` |

Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example,

Expand Down
5 changes: 5 additions & 0 deletions stable/prometheus-adapter/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{{ template "k8s-prometheus-adapter.fullname" . }} has been deployed.
In a few minutes you should be able to list metrics using the following command:

kubectl get --raw /apis/custom.metrics.k8s.io/v1beta1

12 changes: 10 additions & 2 deletions stable/prometheus-adapter/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,19 @@ Expand the name of the chart.
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "k8s-prometheus-adapter.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- $fullname := printf "%s-%s" $name .Release.Name -}}
{{- default $fullname .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ spec:
heritage: {{ .Release.Service }}
name: {{ template "k8s-prometheus-adapter.name" . }}
spec:
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["all"]
runAsNonRoot: true
runAsUser: 10001
serviceAccountName: {{ template "k8s-prometheus-adapter.serviceAccountName" . }}
containers:
- name: {{ .Chart.Name }}
Expand All @@ -43,6 +49,19 @@ spec:
- --config=/etc/adapter/config.yaml
ports:
- containerPort: 6443
name: https
livenessProbe:
httpGet:
path: /healthz
port: https
scheme: HTTPS
initialDelaySeconds: 30
readinessProbe:
httpGet:
path: /healthz
port: https
scheme: HTTPS
initialDelaySeconds: 30
{{- if .Values.resources }}
resources:
{{ toYaml .Values.resources | indent 10 }}
Expand All @@ -56,6 +75,18 @@ spec:
name: volume-serving-cert
readOnly: true
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
volumes:
- name: config
configMap:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
apiVersion: v1
kind: Service
metadata:
annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
label:
app: {{ template "k8s-prometheus-adapter.name" . }}
chart: {{ template "k8s-prometheus-adapter.chart" . }}
Expand All @@ -9,8 +11,11 @@ metadata:
name: {{ template "k8s-prometheus-adapter.fullname" . }}
spec:
ports:
- port: 443
targetPort: 6443
- port: {{ .Values.service.port }}
protocol: TCP
targetPort: https
selector:
app: {{ template "k8s-prometheus-adapter.name" . }}
release: {{ .Release.Name }}
type: {{ .Values.service.type }}

Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ metadata:
data:
config.yaml: |
rules:
{{- if .Values.rules.default }}
- seriesQuery: '{__name__=~"^container_.*",container_name!="POD",namespace!="",pod_name!=""}'
seriesFilters: []
resources:
Expand Down Expand Up @@ -76,3 +77,8 @@ data:
matches: ^(.*)_seconds_total$
as: ""
metricsQuery: sum(rate(<<.Series>>{<<.LabelMatchers>>}[5m])) by (<<.GroupBy>>)
{{- end -}}
{{- if .Values.rules.custom }}
{{ toYaml .Values.rules.custom | indent 4 }}
{{- end -}}

2 changes: 1 addition & 1 deletion stable/prometheus-adapter/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ metadata:
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
name: {{ template "k8s-prometheus-adapter.fullname" . }}
type: Opaque
type: kubernetes.io/tls
data:
tls.crt: {{ b64enc .Values.tls.certificate }}
tls.key: {{ b64enc .Values.tls.key }}
Expand Down
37 changes: 30 additions & 7 deletions stable/prometheus-adapter/values.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# Default values for k8s-prometheus-adapter..
affinity: {}

image:
repository: directxman12/k8s-prometheus-adapter-amd64
tag: v0.2.1
pullPolicy: IfNotPresent

logLevel: 4

metricsRelistInterval: 30s

nodeSelector: {}

# Url to access prometheus
prometheus:
url: http://prometheus.default.svc
port: 9090

replicas: 1

rbac:
Expand All @@ -25,6 +38,22 @@ resources:
# cpu: 100m
# memory: 128Mi

rules:
default: true
custom: {}
# - seriesQuery: '{__name__=~"^some_metric_count$"}'
# resources:
# template: <<.Resource>>
# name:
# matches: ""
# as: "my_custom_metric"
# metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (<<.GroupBy>>)

service:
annotations: {}
port: 443
type: ClusterIP

tls:
enable: false
ca: |-
Expand All @@ -34,10 +63,4 @@ tls:
certificate: |-
# Public key of the APIService
# Url to access prometheus
prometheus:
url: http://prometheus.default.svc
port: 9090

metricsRelistInterval: 30s
logLevel: 10
tolerations: []

0 comments on commit 710e696

Please sign in to comment.