thanos

by rayselfs

Helm chartv0.1.5App 0.40.1Verified publisher

Managed Thanos deployment for compactor, query, query-frontend and storegateway components.

About this chart

Thanos Helm Chart

Thanos is a highly available metrics system that can be added on top of existing Prometheus deployments, providing a global query view across all Prometheus installations.

Introduction

This chart bootstraps a Thanos deployment on a Kubernetes cluster using the Helm package manager.

This chart provides managed Thanos deployment for compactor, query, query-frontend and storegateway components.

Prerequisites

  • Kubernetes 1.23+
  • Helm 3.8.0+
  • PV provisioner support in the underlying infrastructure

Installing the Chart

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

# Add the repository
helm repo add rayselfs https://rayselfs.github.io/helm-charts
helm repo update

# Install the chart
helm install my-release rayselfs/thanos

These commands deploy Thanos on the Kubernetes cluster with the default configuration. The configuration section lists the parameters that can be configured during installation.

Architecture

This charts allows you install several Thanos components, so you deploy an architecture as the one below:

Note: Components marked with (*) are provided by external charts or services. This chart uses AWS S3 or compatible object storage (such as GCS, Azure Blob Storage) for long-term metric storage.

Check the section Integrate Thanos with Prometheus and Alertmanager for detailed instructions to deploy this architecture.

Configuration and installation details

Resource requests and limits

This chart allows setting resource requests and limits for all containers inside the chart deployment. These are inside the resources value (check parameter table). Setting requests is essential for production workloads and these should be adapted to your specific use case.

To make this process easier, the chart contains the resourcesPreset values, which automatically sets the resources section according to different presets. However, in production workloads using resourcesPreset is discouraged as it may not fully adapt to your specific needs. Find more information on container resource management in the official Kubernetes documentation.

Prometheus metrics

This chart can be integrated with Prometheus by setting metrics.enabled to true. This will expose Thanos native Prometheus endpoint in the service. It will have the necessary annotations to be automatically scraped by Prometheus.

Prometheus requirements

It is necessary to have a working installation of Prometheus or Prometheus Operator for the integration to work. You can use any Prometheus installation that supports Thanos sidecar integration.

Integration with Prometheus Operator

The chart can deploy ServiceMonitor objects for integration with Prometheus Operator installations. To do so, set the value metrics.serviceMonitor.enabled=true. Ensure that the Prometheus Operator CustomResourceDefinitions are installed in the cluster or it will fail with the following error:

no matches for kind "ServiceMonitor" in version "monitoring.coreos.com/v1"

Install Prometheus Operator or kube-prometheus stack for having the necessary CRDs and the Prometheus Operator.

Securing traffic using TLS

Thanos can encrypt communications by setting *.tls.enabled=true (under the query.grpc.client, query.grpc.server, storegateway.grpc.server and receive.grpc.server sections) value. The chart allows three configuration options:

  • Provide the content of the certificates using the *.tls.ca, *.tls.cert, *.tls.key (under the query.grpc.client, query.grpc.server, storegateway.grpc.server and receive.grpc.server sections) values.
  • Provide your own secrets using the *.tls.existingSecret (under the query.grpc.client, query.grpc.server, storegateway.grpc.server and receive.grpc.server sections) values. Apart from providing the secret name also set a key mapping to the ca-cert, tls-cert and tls-key elements. For example:
receive:
  grpc:
    server:
      tls:
        existingSecret:
          name: foo
          keyMapping:
            ca-cert: ca.pem
            tls-cert: cert.pem
            tls-key: key.pem
  • Have the chart auto-generate the certificates using *.tls.autoGenerated=true (under the query.grpc.client, query.grpc.server, storegateway.grpc.server and receive.grpc.server sections).

Rolling VS Immutable tags

It is strongly recommended to use immutable tags in a production environment. This ensures your deployment does not change automatically if the same tag is updated with a different image.

Adding extra flags

In case you want to add extra flags to any Thanos component, you can use XXX.extraFlags parameter(s), where XXX is placeholder you need to replace with the actual component(s). For instance, to add extra flags to Thanos Store Gateway, use:

storegateway:
  extraFlags:
    - --sync-block-duration=3m
    - --chunk-pool-size=2GB

This also works for multi-line flags. This can be useful when you want to configure caching for a particular component without using a configMap. For example, to configure the query-range response cache of the Thanos Query Frontend, use:

queryFrontend:
  extraFlags:
    - |
      --query-range.response-cache-config=
      type: MEMCACHED
      config:
        addresses:
          - <MEMCACHED_SERVER>:11211
        timeout: 500ms
        max_idle_connections: 100
        max_async_concurrency: 10
        max_async_buffer_size: 10000
        max_get_multi_concurrency: 100
        max_get_multi_batch_size: 0
        dns_provider_update_interval: 10s
        expiration: 24h

Using custom Objstore configuration

This helm chart supports using custom Objstore configuration.

You can specify the Objstore configuration using the objstoreConfig parameter.

In addition, you can also set an external Secret with the configuration file. This is done by setting the existingObjstoreSecret parameter. Note that this will override the previous option. If needed you can also provide a custom Secret Key with existingObjstoreSecretItems, please be aware that the Path of your Secret should be objstore.yml.

Using custom Query Service Discovery configuration

This helm chart supports using custom Service Discovery configuration for Query.

You can specify the Service Discovery configuration using the query.sdConfig parameter.

In addition, you can also set an external ConfigMap with the Service Discovery configuration file. This is done by setting the query.existingSDConfigmap parameter. Note that this will override the previous option.

Using custom Ruler configuration

This helm chart supports using custom Ruler configuration.

You can specify the Ruler configuration using the ruler.config parameter.

In addition, you can also set an external ConfigMap with the configuration file. This is done by setting the ruler.existingConfigmap parameter. Note that this will override the previous option.

Running Thanos with HTTPS and basic authentication

This helm charts supports using HTTPS and basic authentication. The underlying feature is experimental and might change in the future, so are the associated settings in the chart. For more information, please refer to Thanos documentation.

This feature can be enabled by using the following values:

  • https.enabled=true. Enabling HTTPS requires the user to provide the TLS certificate and Key for Thanos, which can be done using one of the following options:

    • Provide a secret using https.existingSecret. The secret must contain the keys tls.crt or tls.key (key names can be renamed using the values https.keyFilename and https.certFilename).
    • Provide the certificate and key in your values.yaml under the values https.cert and https.key.
    • Use https.autoGenerated=true, using this value Helm will generate a self-signed key pair during the chart initialization. Not recommended for production environments.
  • auth.basicAuthUsers.*. An dictionary of key / values, where the keys corresponds to the users that will have access to Thanos and the values are the plaintext passwords. Passwords will be later encrypted with bcrypt.

  • Alternatively, provide your own Thanos http config file using the value httpConfig or existingHttpConfigSecret. This may cause any settings under https.* or auth.* to be ignored, except for the settings related to the TLS certificates. When providing a configuration file using these parameters, the chart Probes will fail to initialize unless one of the following fixes are applied:

    • Set https.enabled or auth.basicAuthUsers with at least one user, matching the configuration file you provided. That way Probes will be configured with HTTPS and/or basic authentication accordingly.
    • Configure your own Probes using <component>.customLivenessProbe, <component>.customReadinessProbe and <component>.customStartupProbe.
    • Not recommended. Disable the Probes.

Store time partitions

Thanos store supports partion based on time.

Setting time partitions will create N number of store statefulsets based on the number of items in the timePartitioning list. Each item must contain the min and max time for querying in the supported format (find more details at Thanos documentation).

Note: leaving the timePartitioning list empty ([]) will create a single store for all data.

For instance, to use 3 stores you can use a values.yaml like the one below:

timePartitioning:
  # One store for data older than 6 weeks
  - min: ""
    max: -6w
  # One store for data newer than 6 weeks and older than 2 weeks
  - min: -6w
    max: -2w
  # One store for data newer than 2 weeks
  - min: -2w
    max: ""

You can also specify different resources and limits configurations for each storegateway statefulset. This is done by adding a resources.requests and resources.limits to each item you wish to change, as shown below:

timePartitioning:
  # One store for data older than 6 weeks
  - min: ""
    max: -6w
  # One store for data newer than 6 weeks and older than 2 weeks
  - min: -6w
    max: -2w
    resources: #optional resources declaration for partition
      requests:
        cpu: 10m
        memory: 100Mi
      limits:
        cpu: 20m
        memory: 100Mi
  # One store for data newer than 2 weeks
  - min: -2w
    max: ""

Integrate Thanos with Prometheus and Alertmanager

You can integrate Thanos with Prometheus & Alertmanager using this chart and a Prometheus Operator installation following the steps below:

Note: in this example we will use AWS S3 as the Objstore. Every component will be deployed in the "monitoring" namespace.

  • Create a values.yaml like the one below:
objstoreConfig: |-
  type: s3
  config:
    bucket: your-thanos-bucket
    region: us-east-1
    access_key: YOUR_AWS_ACCESS_KEY
    secret_key: YOUR_AWS_SECRET_KEY
query:
  dnsDiscovery:
    sidecarsService: kube-prometheus-prometheus-thanos
    sidecarsNamespace: monitoring
bucketweb:
  enabled: true
compactor:
  enabled: true
storegateway:
  enabled: true
ruler:
  enabled: true
  alertmanagers:
    - http://kube-prometheus-alertmanager.monitoring.svc.cluster.local:9093
  config: |-
    groups:
      - name: "metamonitoring"
        rules:
          - alert: "PrometheusDown"
            expr: absent(up{prometheus="monitoring/kube-prometheus"})
metrics:
  enabled: true
  serviceMonitor:
    enabled: true
  • Install Prometheus Operator and Thanos charts:

For Helm 3:

# Create namespace
kubectl create namespace monitoring

# Install Prometheus Operator (example using kube-prometheus-stack)
helm install kube-prometheus \
    --set prometheus.thanos.create=true \
    --namespace monitoring \
    prometheus-community/kube-prometheus-stack

# Install Thanos
helm install thanos \
    --values values.yaml \
    --namespace monitoring \
    <repo-name>/thanos

That's all! Now you have Thanos fully integrated with Prometheus and Alertmanager.

Deploy extra resources

There are cases where you may want to deploy extra objects, such a ConfigMap containing your app's configuration or some extra deployment with a micro service used by your app. For covering this case, the chart allows adding the full specification of other objects using the extraDeploy parameter.

Setting Pod's affinity

This chart allows you to set your custom affinity using the XXX.affinity parameter(s). Find more information about Pod's affinity in the kubernetes documentation.

You can also use preset configurations for pod affinity, pod anti-affinity, and node affinity. To do so, set the XXX.podAffinityPreset, XXX.podAntiAffinityPreset, or `XXX.

Deploy thanos with OpenTenant

Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has thanos 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 chartthanos is pinned at v0.1.5 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