New to KubeDB? Please start here.

Using Prometheus (CoreOS operator) with KubeDB

This tutorial will show you how to monitor KubeDB databases using Prometheus via CoreOS Prometheus Operator.

Before You Begin

  • At first, you need to have a Kubernetes cluster, and the kubectl command-line tool must be configured to communicate with your cluster. If you do not already have a cluster, you can create one by using Minikube.

  • Now, install KubeDB cli on your workstation and KubeDB operator in your cluster following the steps here.

  • To keep things isolated, this tutorial uses a separate namespace called demo throughout this tutorial.

    $ kubectl create ns demo
    namespace "demo" created
    $ kubectl get ns
    NAME          STATUS    AGE
    demo          Active    10s

Note: The yaml files used in this tutorial are stored in docs/examples/redis folder in GitHub repository kubedb/cli.

Deploy CoreOS-Prometheus Operator

Run the following command to deploy CoreOS-Prometheus operator.

$ kubectl create -f
namespace/demo created created
serviceaccount/prometheus-operator created created
deployment.extensions/prometheus-operator created

Wait for running the Deployment’s Pods.

$ kubectl get pods -n demo
NAME                                   READY     STATUS    RESTARTS   AGE
prometheus-operator-857455484c-45clv   1/1       Running   0          5m

This CoreOS-Prometheus operator will create some supported Custom Resource Definition (CRD).

$ kubectl get crd
NAME                                          CREATED AT
...           2018-09-24T12:42:22Z            2018-09-24T12:42:22Z         2018-09-24T12:42:22Z

Once the Prometheus operator CRDs are registered, run the following command to create a Prometheus.

$ kubectl create -f created
serviceaccount/prometheus created created created
service/prometheus created

# Verify RBAC stuffs
$ kubectl get clusterroles
NAME                  AGE
prometheus            48s
prometheus-operator   1m

$ kubectl get clusterrolebindings
NAME                  AGE
prometheus            7s
prometheus-operator   25s

$ kubectl get serviceaccounts -n demo
NAME                  SECRETS   AGE
default               1         5m
prometheus            1         4m
prometheus-operator   1         5m

Prometheus Dashboard

Now to open prometheus dashboard on Browser:

$ kubectl get svc -n demo
NAME                  TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
prometheus            LoadBalancer   <pending>     9090:30900/TCP   7s
prometheus-operated   ClusterIP      None            <none>        9090/TCP         6s

$ minikube ip

$ minikube service prometheus -n demo --url

Now, open your browser and go to the following URL: http://{minikube-ip}:{prometheus-svc-nodeport} to visit Prometheus Dashboard. According to the above example, this URL will be

If you are not using minikube, browse prometheus dashboard using following address http://{Node's ExternalIP}:{NodePort of prometheus-service}.

Create a Redis database

KubeDB implements a Redis CRD to define the specification of a Redis database. Below is the Redis object created in this tutorial.

kind: Redis
  name: redis-mon-coreos
  namespace: demo
  version: "4.0-v1"
    storageClassName: "standard"
    - ReadWriteOnce
        storage: 50Mi
      namespace: demo
        app: kubedb
      interval: 10s

The Redis CRD object contains monitor field in it’s spec. It is also possible to add CoreOS-Prometheus monitor to an existing Redis database by adding the below part in it’s spec field.

      namespace: demo
        app: kubedb
      interval: 10s
spec.monitor.agentstringRequired. Indicates the monitoring agent used. Only valid value currently is coreos-prometheus-operator
spec.monitor.prometheus.namespacestringRequired. Indicates namespace where service monitors are created. This must be the same namespace of the Prometheus instance.
spec.monitor.prometheus.labelsmapRequired. Indicates labels applied to service monitor.
spec.monitor.prometheus.intervalstringOptional. Indicates the scrape interval for database exporter endpoint (eg, ‘10s’)
spec.monitor.prometheus.portintOptional. Indicates the port for database exporter endpoint (default is 56790)

Known Limitations: If the database password is updated, exporter must be restarted to use the new credentials. This issue is tracked here.

Run the following command to deploy the above Redis CRD object.

$ kubedb create -f created


  • spec.monitor specifies that CoreOS Prometheus operator is used to monitor this database instance. A ServiceMonitor should be created in the demo namespace with label app=kubedb. The exporter endpoint should be scrapped every 10 seconds.

KubeDB will create a separate stats service with name <redis-crd-name>-stats for monitoring purpose. KubeDB operator will configure this monitoring service once the Redis is successfully running.

$ kubedb get rd -n demo
NAME               VERSION   STATUS     AGE
redis-mon-coreos   4.0-v1    Creating   24s

$ kubedb describe rd -n demo redis-mon-coreos
Name:               redis-mon-coreos
Namespace:          demo
CreationTimestamp:  Mon, 01 Oct 2018 13:05:15 +0600
Labels:             <none>
Annotations:        <none>
Replicas:           1  total
Status:             Running
  StorageType:      Durable
  StorageClass:  standard
  Capacity:      50Mi
  Access Modes:  RWO

  Name:               redis-mon-coreos
  CreationTimestamp:  Mon, 01 Oct 2018 13:05:18 +0600
  Annotations:        <none>
  Replicas:           824637984636 desired | 1 total
  Pods Status:        1 Running / 0 Waiting / 0 Succeeded / 0 Failed

  Name:         redis-mon-coreos
  Annotations:  <none>
  Type:         ClusterIP
  Port:         db  6379/TCP
  TargetPort:   db/TCP

  Name:         redis-mon-coreos-stats
  Type:         ClusterIP
  Port:         prom-http  56790/TCP
  TargetPort:   prom-http/TCP

Monitoring System:
    Port:       56790
    Namespace:  demo
    Labels:     app=kubedb
    Interval:   10s

No Snapshots.

  Type    Reason      Age   From            Message
  ----    ------      ----  ----            -------
  Normal  Successful  42s   Redis operator  Successfully created Service
  Normal  Successful  9s    Redis operator  Successfully created StatefulSet
  Normal  Successful  9s    Redis operator  Successfully created Redis
  Normal  Successful  7s    Redis operator  Successfully created stats service
  Normal  Successful  5s    Redis operator  Successfully patched StatefulSet
  Normal  Successful  5s    Redis operator  Successfully patched Redis

Since spec.monitoring was configured, a ServiceMonitor object is created accordingly. You can verify it running the following commands:

$ kubectl get servicemonitor -n demo
NAME                           AGE
kubedb-demo-redis-mon-coreos   25s

$ kubectl get servicemonitor -n demo kubedb-demo-redis-mon-coreos -o yaml
kind: ServiceMonitor
  creationTimestamp: 2018-10-01T07:05:54Z
  generation: 1
    app: kubedb redis-mon-coreos-stats.demo
  name: kubedb-demo-redis-mon-coreos
  namespace: demo
  resourceVersion: "12902"
  selfLink: /apis/
  uid: 70100729-c548-11e8-9ba7-0800274bef12
  - interval: 10s
    path: /
    port: prom-http
    targetPort: 0
    - demo
    matchLabels: Redis redis-mon-coreos

Now, if you go the Prometheus Dashboard, you should see that this database endpoint as one of the targets.


Cleaning up

To cleanup the Kubernetes resources created by this tutorial, run:

kubectl patch -n demo rd/redis-mon-coreos -p '{"spec":{"terminationPolicy":"WipeOut"}}' --type="merge"
kubectl delete -n demo rd/redis-mon-coreos

kubectl patch -n demo drmn/redis-mon-coreos -p '{"spec":{"wipeOut":true}}' --type="merge"
kubectl delete -n demo drmn/redis-mon-coreos

kubectl delete -f
kubectl delete -f

kubectl delete ns demo

Next Steps