kube-prometheus

by Helm

Helm chartv9.3.1App 0.38.1

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.

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:

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

  1. Wait for CRDs to be created, which should only take a few seconds

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

ParameterDescriptionDefault
additionalPrometheusRulesMapMap 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
additionalPrometheusRulesDEPRECATED 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.[]
commonLabelsLabels to apply to all resources[]
defaultRules.annotationsAnnotations for default rules for monitoring the cluster{}
defaultRules.appNamespacesTargetSpecify target Namespaces for app alerts".*"
defaultRules.createCreate default rules for monitoring the clustertrue
defaultRules.labelsLabels for default rules for monitoring the cluster{}
defaultRules.runbookUrlURL prefix for default rule runbook_url annotationshttps://github.com/kubernetes-monitoring/kubernetes-mixin/tree/master/runbook.md#
defaultRules.rules.PrometheusOperatorCreate Prometheus Operator default rulestrue
defaultRules.rules.alertmanagerCreate default rules for Alert Managertrue
defaultRules.rules.etcdCreate default rules for ETCDtrue
defaultRules.rules.generalCreate General default rulestrue
defaultRules.rules.k8sCreate K8S default rulestrue
defaultRules.rules.kubeApiserverCreate Api Server default rulestrue
defaultRules.rules.kubeApiserverAvailabilityCreate Api Server Availability default rulestrue
defaultRules.rules.kubeApiserverErrorCreate Api Server Error default rulestrue
defaultRules.rules.kubeApiserverSlosCreate Api Server SLOs default rulestrue
defaultRules.rules.kubeletCreate kubelet default rulestrue
defaultRules.rules.kubePrometheusGeneralCreate general default rulestrue
defaultRules.rules.kubePrometheusNodeAlertingCreate Node Alerting default rulestrue
defaultRules.rules.kubePrometheusNodeRecordingCreate Node Recording default rulestrue
defaultRules.rules.kubeSchedulerCreate Kubernetes Scheduler default rulestrue
defaultRules.rules.kubernetesAbsentCreate Kubernetes Absent (example API Server down) default rulestrue
defaultRules.rules.kubernetesAppsCreate Kubernetes Apps default rulestrue
defaultRules.rules.kubernetesResourcesCreate Kubernetes Resources default rulestrue
defaultRules.rules.kubernetesStorageCreate Kubernetes Storage default rulestrue
defaultRules.rules.kubernetesSystemCreate Kubernetes System default rulestrue
defaultRules.rules.kubeStateMetricsCreate kube-state-metrics default rulestrue
defaultRules.rules.networkCreate networking default rulestrue
defaultRules.rules.nodeCreate Node default rulestrue
defaultRules.rules.prometheusCreate Prometheus default rulestrue
defaultRules.rules.timeCreate time default rulestrue
fullnameOverrideProvide a name to substitute for the full names of resources""
global.imagePullSecretsReference to one or more secrets to be used when pulling images[]
global.rbac.createCreate RBAC resourcestrue
global.rbac.pspEnabledCreate pod security policy resourcestrue
global.rbac.pspAnnotationsAdd annotations to the PSP configurations{}
kubeTargetVersionOverrideProvide a target gitVersion of K8S, in case .Capabilites.KubeVersion is not available (e.g. helm template)""
nameOverrideProvide a name in place of prometheus-operator""
namespaceOverrideOverride the deployment namespace"" (Release.Namespace)
kubeTargetVersionOverrideProvide a k8s version""

Prometheus Operator

ParameterDescriptionDefault
prometheusOperator.admissionWebhooks.enabledCreate PrometheusRules admission webhooks. Mutating webhook will patch PrometheusRules objects indicating they were validated. Validating webhook will check the rules syntax.true
prometheusOperator.admissionWebhooks.failurePolicyFailure policy for admission webhooksFail
prometheusOperator.admissionWebhooks.patch.enabledIf 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.pullPolicyImage pull policy for the webhook integration jobsIfNotPresent
`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.

  1. Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
  2. Place the chartkube-prometheus is pinned at v9.3.1 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
  3. 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