kube-prometheus
by Helm
Provides easy monitoring definitions for Kubernetes services, and deployment and management of Prometheus instances.
About this chart
prometheus-operator
Installs prometheus-operator to create/configure/manage Prometheus clusters atop Kubernetes. This chart includes multiple components and is suitable for a variety of use-cases.
The default installation is intended to suit monitoring a kubernetes cluster the chart is deployed onto. It closely matches the kube-prometheus project.
- prometheus-operator
- prometheus
- alertmanager
- node-exporter
- kube-state-metrics
- grafana
- service monitors to scrape internal kubernetes components
- kube-apiserver
- kube-scheduler
- kube-controller-manager
- etcd
- kube-dns/coredns
- kube-proxy
With the installation, the chart also includes dashboards and alerts.
The same chart can be used to run multiple prometheus instances in the same cluster if required. To achieve this, the other components need to be disabled - it is necessary to run only one instance of prometheus-operator and a pair of alertmanager pods for an HA configuration.
TL;DR;
$ helm install stable/prometheus-operator
Introduction
This chart bootstraps a prometheus-operator deployment on a Kubernetes cluster using the Helm package manager. The chart can be installed multiple times to create separate Prometheus instances managed by Prometheus Operator.
Prerequisites
- Kubernetes 1.10+ with Beta APIs
- Helm 2.12+ (If using Helm < 2.14, see below for CRD workaround)
Installing the Chart
To install the chart with the release name my-release:
$ helm install --name my-release stable/prometheus-operator
The command deploys prometheus-operator on the Kubernetes cluster in the default configuration. The configuration section lists the parameters that can be configured during installation.
The default installation includes Prometheus Operator, Alertmanager, Grafana, and configuration for scraping Kubernetes infrastructure.
Uninstalling the Chart
To uninstall/delete the my-release deployment:
$ helm delete my-release
The command removes all the Kubernetes components associated with the chart and deletes the release.
CRDs created by this chart are not removed by default and should be manually cleaned up:
kubectl delete crd prometheuses.monitoring.coreos.com
kubectl delete crd prometheusrules.monitoring.coreos.com
kubectl delete crd servicemonitors.monitoring.coreos.com
kubectl delete crd podmonitors.monitoring.coreos.com
kubectl delete crd alertmanagers.monitoring.coreos.com
kubectl delete crd thanosrulers.monitoring.coreos.com
Work-Arounds for Known Issues
Running on private GKE clusters
When Google configure the control plane for private clusters, they automatically configure VPC peering between your Kubernetes cluster’s network and a separate Google managed project. In order to restrict what Google are able to access within your cluster, the firewall rules configured restrict access to your Kubernetes pods. This means that in order to use the webhook component with a GKE private cluster, you must configure an additional firewall rule to allow the GKE control plane access to your webhook pod.
You can read more information on how to add firewall rules for the GKE control plane nodes in the GKE docs
Alternatively, you can disable the hooks by setting prometheusOperator.admissionWebhooks.enabled=false.
Helm fails to create CRDs
You should upgrade to Helm 2.14 + in order to avoid this issue. However, if you are stuck with an earlier Helm release you should instead use the following approach: Due to a bug in helm, it is possible for the 5 CRDs that are created by this chart to fail to get fully deployed before Helm attempts to create resources that require them. This affects all versions of Helm with a potential fix pending. In order to work around this issue when installing the chart you will need to make sure all 5 CRDs exist in the cluster first and disable their previsioning by the chart:
- Create CRDs
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_alertmanagers.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_podmonitors.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_prometheusrules.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_servicemonitors.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/release-0.38/example/prometheus-operator-crd/monitoring.coreos.com_thanosrulers.yaml
-
Wait for CRDs to be created, which should only take a few seconds
-
Install the chart, but disable the CRD provisioning by setting
prometheusOperator.createCustomResource=false
$ helm install --name my-release stable/prometheus-operator --set prometheusOperator.createCustomResource=false
Upgrading an existing Release to a new major version
A major chart version change (like v1.2.3 -> v2.0.0) indicates that there is an incompatible breaking change needing manual actions.
Upgrading from 8.x.x to 9.x.x
Version 9 of the helm chart removes the existing additionalScrapeConfigsExternal in favour of additionalScrapeConfigsSecret. This change lets users specify the secret name and secret key to use for the additional scrape configuration of prometheus. This is useful for users that have prometheus-operator as a subchart and also have a template that creates the additional scrape configuration.
Upgrading from 7.x.x to 8.x.x
Due to new template functions being used in the rules in version 8.x.x of the chart, an upgrade to Prometheus Operator and Prometheus is necessary in order to support them. First, upgrade to the latest version of 7.x.x
helm upgrade <your-release-name> stable/prometheus-operator --version 7.4.0
Then upgrade to 8.x.x
helm upgrade <your-release-name> stable/prometheus-operator
Minimal recommended Prometheus version for this chart release is 2.12.x
Upgrading from 6.x.x to 7.x.x
Due to a change in grafana subchart, version 7.x.x now requires Helm >= 2.12.0.
Upgrading from 5.x.x to 6.x.x
Due to a change in deployment labels of kube-state-metrics, the upgrade requires helm upgrade --force in order to re-create the deployment. If this is not done an error will occur indicating that the deployment cannot be modified:
invalid: spec.selector: Invalid value: v1.LabelSelector{MatchLabels:map[string]string{"app.kubernetes.io/name":"kube-state-metrics"}, MatchExpressions:[]v1.LabelSelectorRequirement(nil)}: field is immutable
If this error has already been encountered, a helm history command can be used to determine which release has worked, then helm rollback to the release, then helm upgrade --force to this new one
prometheus.io/scrape
The prometheus operator does not support annotation-based discovery of services, using the serviceMonitor CRD in its place as it provides far more configuration options. For information on how to use servicemonitors, please see the documentation on the coreos/prometheus-operator documentation here: Running Exporters
By default, Prometheus discovers ServiceMonitors within its namespace, that are labeled with the same release tag as the prometheus-operator release.
Sometimes, you may need to discover custom ServiceMonitors, for example used to scrape data from third-party applications. An easy way of doing this, without compromising the default ServiceMonitors discovery, is allowing Prometheus to discover all ServiceMonitors within its namespace, without applying label filtering. To do so, you can set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues to false.
Configuration
The following tables list the configurable parameters of the prometheus-operator chart and their default values.
General
| Parameter | Description | Default |
|---|---|---|
additionalPrometheusRulesMap | Map of prometheusRule objects to create with the key used as the name of the rule spec. If defined, this will take precedence over additionalPrometheusRules. See https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#prometheusrulespec. | nil |
additionalPrometheusRules | DEPRECATED Will be removed in a future release. Please use additionalPrometheusRulesMap instead. List of prometheusRule objects to create. See https://github.com/coreos/prometheus-operator/blob/master/Documentation/api.md#prometheusrulespec. | [] |
commonLabels | Labels to apply to all resources | [] |
defaultRules.annotations | Annotations for default rules for monitoring the cluster | {} |
defaultRules.appNamespacesTarget | Specify target Namespaces for app alerts | ".*" |
defaultRules.create | Create default rules for monitoring the cluster | true |
defaultRules.labels | Labels for default rules for monitoring the cluster | {} |
defaultRules.runbookUrl | URL prefix for default rule runbook_url annotations | https://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md# |
defaultRules.rules.PrometheusOperator | Create Prometheus Operator default rules | true |
defaultRules.rules.alertmanager | Create default rules for Alert Manager | true |
defaultRules.rules.etcd | Create default rules for ETCD | true |
defaultRules.rules.general | Create General default rules | true |
defaultRules.rules.k8s | Create K8S default rules | true |
defaultRules.rules.kubeApiserver | Create Api Server default rules | true |
defaultRules.rules.kubeApiserverAvailability | Create Api Server Availability default rules | true |
defaultRules.rules.kubeApiserverError | Create Api Server Error default rules | true |
defaultRules.rules.kubeApiserverSlos | Create Api Server SLOs default rules | true |
defaultRules.rules.kubelet | Create kubelet default rules | true |
defaultRules.rules.kubePrometheusGeneral | Create general default rules | true |
defaultRules.rules.kubePrometheusNodeAlerting | Create Node Alerting default rules | true |
defaultRules.rules.kubePrometheusNodeRecording | Create Node Recording default rules | true |
defaultRules.rules.kubeScheduler | Create Kubernetes Scheduler default rules | true |
defaultRules.rules.kubernetesAbsent | Create Kubernetes Absent (example API Server down) default rules | true |
defaultRules.rules.kubernetesApps | Create Kubernetes Apps default rules | true |
defaultRules.rules.kubernetesResources | Create Kubernetes Resources default rules | true |
defaultRules.rules.kubernetesStorage | Create Kubernetes Storage default rules | true |
defaultRules.rules.kubernetesSystem | Create Kubernetes System default rules | true |
defaultRules.rules.kubeStateMetrics | Create kube-state-metrics default rules | true |
defaultRules.rules.network | Create networking default rules | true |
defaultRules.rules.node | Create Node default rules | true |
defaultRules.rules.prometheus | Create Prometheus default rules | true |
defaultRules.rules.time | Create time default rules | true |
fullnameOverride | Provide a name to substitute for the full names of resources | "" |
global.imagePullSecrets | Reference to one or more secrets to be used when pulling images | [] |
global.rbac.create | Create RBAC resources | true |
global.rbac.pspEnabled | Create pod security policy resources | true |
global.rbac.pspAnnotations | Add annotations to the PSP configurations | {} |
kubeTargetVersionOverride | Provide a target gitVersion of K8S, in case .Capabilites.KubeVersion is not available (e.g. helm template) | "" |
nameOverride | Provide a name in place of prometheus-operator | "" |
namespaceOverride | Override the deployment namespace | "" (Release.Namespace) |
kubeTargetVersionOverride | Provide a k8s version | "" |
Prometheus Operator
| Parameter | Description | Default |
|---|---|---|
prometheusOperator.admissionWebhooks.enabled | Create PrometheusRules admission webhooks. Mutating webhook will patch PrometheusRules objects indicating they were validated. Validating webhook will check the rules syntax. | true |
prometheusOperator.admissionWebhooks.failurePolicy | Failure policy for admission webhooks | Fail |
prometheusOperator.admissionWebhooks.patch.enabled | If true, will use a pre and post install hooks to generate a CA and certificate to use for the prometheus operator tls proxy, and patch the created webhooks with the CA. | true |
prometheusOperator.admissionWebhooks.patch.image.pullPolicy | Image pull policy for the webhook integration jobs | IfNotPresent |
| `prometheusOperator.admissionWebhook |
Deploy kube-prometheus with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has kube-prometheus 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 chartkube-prometheus is pinned at v9.3.1 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