New to KubeDB? Please start here.

Monitoring SingleStore with KubeDB

KubeDB has native support for monitoring via Prometheus. You can use builtin Prometheus scraper or Prometheus operator to monitor KubeDB managed databases. This tutorial will show you how database monitoring works with KubeDB and how to configure Database crd to enable monitoring.

Overview

KubeDB uses Prometheus exporter images to export metrics for the respective databases. However, with SingleStore, you can obtain metrics without using an exporter image by configuring monitoring using the memsql-admin binary. We have integrated this configuration into our operator, supporting both TLS and non-TLS setups. To enable monitoring, you simply need to specify it in your SingleStore YAML file. The following diagram illustrates the logical flow of database monitoring with KubeDB.

  Database Monitoring Flow

When a user creates a database crd with spec.monitor section configured, KubeDB operator provisions the respective database and injects an exporter image as sidecar to the database pod. It also creates a dedicated stats service with name {database-crd-name}-stats for monitoring. Prometheus server can scrape metrics using this stats service.

Configure Monitoring

In order to enable monitoring for a database, you have to configure spec.monitor section. KubeDB provides following options to configure spec.monitor section:

FieldTypeUses
spec.monitor.agentRequiredType of the monitoring agent that will be used to monitor this database. It can be prometheus.io/builtin or prometheus.io/operator.
spec.monitor.prometheus.exporter.portOptionalPort number where the exporter side car will serve metrics.
spec.monitor.prometheus.exporter.argsOptionalArguments to pass to the exporter sidecar.
spec.monitor.prometheus.exporter.envOptionalList of environment variables to set in the exporter sidecar container.
spec.monitor.prometheus.exporter.resourcesOptionalResources required by exporter sidecar container.
spec.monitor.prometheus.exporter.securityContextOptionalSecurity options the exporter should run with.
spec.monitor.prometheus.serviceMonitor.labelsOptionalLabels for ServiceMonitor crd.
spec.monitor.prometheus.serviceMonitor.intervalOptionalInterval at which metrics should be scraped.

Sample Configuration

A sample YAML for MySQL crd with spec.monitor section configured to enable monitoring with Prometheus operator is shown below.

apiVersion: kubedb.com/v1alpha2
kind: Singlestore
metadata:
  name: prom-operator-sdb
  namespace: demo
spec:
  version: "8.7.10"
  topology:
    aggregator:
      replicas: 2
      podTemplate:
        spec:
          containers:
          - name: singlestore
            resources:
              limits:
                memory: "2Gi"
                cpu: "600m"
              requests:
                memory: "2Gi"
                cpu: "600m"
      storage:
        storageClassName: "standard"
        accessModes:
        - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
    leaf:
      replicas: 2
      podTemplate:
        spec:
          containers:
            - name: singlestore
              resources:
                limits:
                  memory: "2Gi"
                  cpu: "600m"
                requests:
                  memory: "2Gi"
                  cpu: "600m"                      
      storage:
        storageClassName: "standard"
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 10Gi
  licenseSecret:
    name: license-secret
  storageType: Durable
  deletionPolicy: WipeOut
  monitor:
    agent: prometheus.io/operator
    prometheus:
      serviceMonitor:
        labels:
          release: prometheus
        interval: 10s

Assume that above Redis is configured to use basic authentication. So, exporter image also need to provide password to collect metrics. We have provided it through spec.monitor.args field.

Here, we have specified that we are going to monitor this server using Prometheus operator through spec.monitor.agent: prometheus.io/operator. KubeDB will create a ServiceMonitor crd in monitoring namespace and this ServiceMonitor will have release: prometheus label.

Next Steps