prometheus-operator

by joaquinito2051

Helm chartv6.4.0App 0.31.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 <helm-repo>/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.10+ (For a workaround using an earlier version see below)

Installing the Chart

To install the chart with the release name my-release:

$ helm install --name my-release <helm-repo>/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

Work-Arounds for Known Issues

Helm fails to create CRDs

Due to a bug in helm, it is possible for the 4 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 4 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/master/example/prometheus-operator-crd/alertmanager.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/prometheus.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/prometheusrule.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/servicemonitor.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/coreos/prometheus-operator/master/example/prometheus-operator-crd/podmonitor.crd.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 <helm-repo>/prometheus-operator --set prometheusOperator.createCustomResource=false

Helm <2.10 workaround

The crd-install hook is required to deploy the prometheus operator CRDs before they are used. If you are forced to use an earlier version of Helm you can work around this requirement as follows:

  1. Install prometheus-operator by itself, disabling everything but the prometheus-operator component, and also setting prometheusOperator.serviceMonitor.selfMonitor=false
  2. Install all the other components, and configure prometheus.additionalServiceMonitors to scrape the prometheus-operator service.

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

Configuration

The following tables list the configurable parameters of the prometheus-operator chart and their default values.

General

ParameterDescriptionDefault
nameOverrideProvide a name in place of prometheus-operator""
fullNameOverrideProvide a name to substitute for the full names of resources""
commonLabelsLabels to apply to all resources[]
defaultRules.createCreate default rules for monitoring the clustertrue
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.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.nodeCreate Node default rulestrue
defaultRules.rules.networkCreate networking default rulestrue
defaultRules.rules.PrometheusOperatorCreate Prometheus Operator default rulestrue
defaultRules.rules.prometheusCreate Prometheus default rulestrue
defaultRules.rules.timeCreate time default rulestrue
defaultRules.labelsLabels for default rules for monitoring the cluster{}
defaultRules.annotationsAnnotations for default rules for monitoring the cluster{}
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.[]
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
global.rbac.createCreate RBAC resourcestrue
global.rbac.pspEnabledCreate pod security policy resourcestrue
global.imagePullSecretsReference to one or more secrets to be used when pulling images[]

Prometheus Operator

ParameterDescriptionDefault
prometheusOperator.enabledDeploy Prometheus Operator. Only one of these should be deployed into the clustertrue
prometheusOperator.serviceAccount.createCreate a serviceaccount for the operatortrue
prometheusOperator.serviceAccount.nameOperator serviceAccount name""
prometheusOperator.logFormatOperator log output formatting"logfmt"
prometheusOperator.tlsProxy.enabledEnable a TLS proxy container. Only the squareup/ghostunnel command line arguments are currently supported and the secret where the cert is loaded from is expected to be provided by the admission webhooktrue
prometheusOperator.tlsProxy.image.repositoryRepository for the TLS proxy containersquareup/ghostunnel
prometheusOperator.tlsProxy.image.tagRepository for the TLS proxy containerv1.4.1
prometheusOperator.tlsProxy.image.repositoryImage pull policy for the TLS proxy containerIfNotPresent
prometheusOperator.tlsProxy.image.resourcesResource requests and limits for the TLS proxy container{}
prometheusOperator.logLevelOperator log level. Possible values: "all", "debug", "info", "warn", "error", "none""info"
prometheusOperator.createCustomResourceCreate CRDs. Required if deploying anything besides the operator itself as part of the release. The operator will create / update these on startup. If your Helm version < 2.10 you will have to either create the CRDs first or deploy the operator first, then the rest of the resourcestrue
prometheusOperator.crdApiGroupSpecify the API Group for the CustomResourceDefinitionsmonitoring.coreos.com
prometheusOperator.cleanupCustomResourceBeforeInstallRemove CRDs before running the crd-install hook on changes.false
prometheusOperator.cleanupCustomResourceAttempt to delete CRDs when the release is removed. This option may be useful while testing but is not recommended, as deleting the CRD definition will delete resources and prevent the operator from being able to clean up resources that it managesfalse
prometheusOperator.podLabelsLabels to add to the operator pod{}
prometheusOperator.podAnnotationsAnnotations to add to the operator pod{}
prometheusOperator.priorityClassNameName of Priority Class to assign podsnil
prometheusOperator.kubeletService.enabledIf true, the operator will create and maintain a service for scraping kubeletstrue
prometheusOperator.kubeletService.namespaceNamespace to deploy kubelet servicekube-system
prometheusOperator.serviceMonitor.selfMonitorEnable monitoring of prometheus operatortrue
prometheusOperator.serviceMonitor.intervalScrape interval. If not set, the Prometheus default scrape interval is usednil
prometheusOperator.serviceMonitor.metricRelabelingsThe metric_relabel_configs for scraping the operator instance.``
prometheusOperator.serviceMonitor.relabelingsThe relabel_configs for scraping the operator instance.``
prometheusOperator.service.typePrometheus operator service typeClusterIP
prometheusOperator.service.clusterIPPrometheus operator service clusterIP IP""
prometheusOperator.service.nodePortPort to expose prometheus operator service on each node30080
prometheusOperator.service.nodePortTlsTLS port to expose prometheus operator service on each node30443
prometheusOperator.service.annotationsAnnotations to be added to the prometheus operator service{}
prometheusOperator.service.labelsPrometheus Operator Service Labels{}
prometheusOperator.service.externalIPsList of IP addresses at which the Prometheus Operator server service is available[]
prometheusOperator.service.loadBalancerIPPrometheus Operator Loadbalancer IP""
prometheusOperator.service.loadBalancerSourceRangesPrometheus Operator Load Balancer Source Ranges[]
prometheusOperator.resourcesResource limits for prometheus operator{}
prometheusOperator.securityContextSecurityContext for prometheus operator{"runAsNonRoot": true, "runAsUser": 65534}
prometheusOperator.nodeSelectorPrometheus operator node selector https://kubernetes.io/docs/user-guide/node-selection/{}
prometheusOperator.tolerationsTolerations for use with node taints https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/[]
`prometheusOperator.affin

Deploy prometheus-operator with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has prometheus-operator 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 chartprometheus-operator is pinned at v6.4.0 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