New to KubeDB? Please start here.
Monitoring HanaDB with Built-in Prometheus
This tutorial shows how to monitor a HanaDB instance using the built-in Prometheus scraper.
Before You Begin
Prepare a Kubernetes cluster and configure
kubectlto communicate with it. If you do not already have a cluster, you can create one by using kind.Install KubeDB operator in your cluster following the steps here.
If you are not familiar with how to configure Prometheus to scrape metrics from various Kubernetes resources, please read the tutorial from here.
To learn how Prometheus monitoring works with KubeDB in general, please visit here.
This tutorial deploys Prometheus resources in the
monitoringnamespace and the database in thedemonamespace.$ kubectl create ns monitoring namespace/monitoring created $ kubectl create ns demo namespace/demo created
Note: YAML files used in this tutorial are stored in docs/examples/hanadb/monitoring folder in GitHub repository kubedb/docs.
Deploy HanaDB with Monitoring Enabled
Deploy a HanaDB instance with monitoring enabled. The manifest is shown below.
apiVersion: kubedb.com/v1alpha2
kind: HanaDB
metadata:
name: hanadb-builtin-prometheus
namespace: demo
spec:
version: "2.0.82"
replicas: 1
storageType: Durable
storage:
storageClassName: local-path
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 64Gi
deletionPolicy: WipeOut
monitor:
agent: prometheus.io/builtin
prometheus:
exporter:
port: 9668
Here, spec.monitor.agent: prometheus.io/builtin tells KubeDB to use Prometheus annotation-based discovery. spec.monitor.prometheus.exporter.port specifies the exporter port. If omitted, KubeDB defaults it to 9668.
Create the HanaDB object:
$ kubectl apply -f https://github.com/kubedb/docs/raw/v2026.4.27/docs/examples/hanadb/monitoring/builtin-prom-hanadb.yaml
hanadb.kubedb.com/hanadb-builtin-prometheus created
Wait for the database to reach the Ready state.
$ kubectl get hanadb -n demo hanadb-builtin-prometheus
NAME VERSION STATUS AGE
hanadb-builtin-prometheus 2.0.82 Ready 2m
KubeDB creates a separate stats service named {hanadb-name}-stats for metrics scraping.
$ kubectl get svc -n demo --selector="app.kubernetes.io/instance=hanadb-builtin-prometheus"
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
hanadb-builtin-prometheus ClusterIP 10.96.100.10 <none> 39017/TCP 2m
hanadb-builtin-prometheus-stats ClusterIP 10.96.100.11 <none> 9668/TCP 90s
The hanadb-builtin-prometheus-stats service exposes the exporter endpoint. Describe the service:
$ kubectl describe svc -n demo hanadb-builtin-prometheus-stats
Name: hanadb-builtin-prometheus-stats
Namespace: demo
Labels: app.kubernetes.io/name=hanadbs.kubedb.com
app.kubernetes.io/instance=hanadb-builtin-prometheus
Annotations: monitoring.appscode.com/agent: prometheus.io/builtin
prometheus.io/path: /metrics
prometheus.io/port: 9668
prometheus.io/scheme: http
prometheus.io/scrape: true
Selector: app.kubernetes.io/name=hanadbs.kubedb.com,app.kubernetes.io/instance=hanadb-builtin-prometheus
Type: ClusterIP
Port: metrics 9668/TCP
The service contains the following annotations, which are used by Prometheus to discover the endpoint:
prometheus.io/path: /metrics
prometheus.io/port: 9668
prometheus.io/scheme: http
prometheus.io/scrape: true
Configure Prometheus
Configure Prometheus to scrape metrics from this service. Add the following scrape_config to your Prometheus configuration:
scrape_configs:
- job_name: kubedb-hanadbs
honor_labels: true
kubernetes_sd_configs:
- role: endpoints
relabel_configs:
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scrape]
separator: ;
regex: true
target_label: __tmp_prometheus_service_scrape
replacement: $1
action: keep
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_scheme]
separator: ;
regex: (https?)
target_label: __scheme__
replacement: $1
action: replace
- source_labels: [__meta_kubernetes_service_annotation_prometheus_io_path]
separator: ;
regex: (.+)
target_label: __metrics_path__
replacement: $1
action: replace
- source_labels: [__address__, __meta_kubernetes_service_annotation_prometheus_io_port]
separator: ;
regex: ([^:]+)(?::\d+)?;(\d+)
target_label: __address__
replacement: $1:$2
action: replace
Now Prometheus will discover the HanaDB stats service and scrape metrics automatically.
Access Prometheus Dashboard
To access the Prometheus dashboard, port-forward the Prometheus service and visit http://localhost:9090 in your browser.
$ kubectl port-forward -n monitoring svc/prometheus 9090:9090
You should see the HanaDB metrics in the Prometheus dashboard under the kubedb-hanadbs job.
Cleaning up
To clean up the Kubernetes resources created by this tutorial, run:
kubectl patch -n demo hanadb/hanadb-builtin-prometheus -p '{"spec":{"deletionPolicy":"WipeOut"}}' --type="merge"
kubectl delete -n demo hanadb/hanadb-builtin-prometheus
kubectl delete ns demo
kubectl delete ns monitoring































