I installed Kong using a Helm chart in Kubernetes — how do I expose Kong’s metrics to Prometheus?
How to expose Kong metrics with Prometheus in K8s
How do I expose Kong’s metrics to Prometheus when Kong is deployed with Helm in Kubernetes?
Install Prometheus (e.g. via the kube-prometheus-stack Helm chart), set serviceMonitor.enabled: true in the Kong Helm chart’s values.yaml so a ServiceMonitor object is created, and enable the Prometheus plugin globally to scrape Kong’s proxy traffic metrics.
Steps
-
Install Prometheus
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts kubectl create ns monitoring helm upgrade -i prometheus prometheus-community/kube-prometheus-stack \ --namespace monitoring \ --set prometheus.prometheusSpec.serviceMonitorSelectorNilUsesHelmValues=false \ --set fullnameOverride=prometheus kubectl get all -n monitoringThis Prometheus deployment is only for demo purposes and isn’t suitable for a production environment.
-
Install Kong
The following parameter is required in
values.yamlwhen installing Kong with the Helm chart:serviceMonitor: enabled: trueSet this parameter in
values.yamland install Kong.This configuration creates a
ServiceMonitorobject in the same namespace as Kong, as shown in the example below, which tells Prometheus how to scrape metrics from Kong.apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: labels: app.kubernetes.io/instance: kong app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: kong app.kubernetes.io/version: "3.14" helm.sh/chart: kong-2.41.0 name: kong-kong namespace: kong spec: endpoints: - scheme: http targetPort: status - scheme: http targetPort: cmetrics jobLabel: kong namespaceSelector: matchNames: - kong selector: matchLabels: app.kubernetes.io/instance: kong app.kubernetes.io/managed-by: Helm app.kubernetes.io/name: kong app.kubernetes.io/version: "3.14" enable-metrics: "true" helm.sh/chart: kong-2.41.0 -
Enable a global Prometheus plugin
Enable the Prometheus plugin globally, then create
ServiceandRouteobjects in Kong for proxy requests to upstreams. After that, send a few requests to Kong. -
Forward port 9090 of the Prometheus Kubernetes service to localhost and check the metrics
# Execute command to port forward 9090 port of the Prometheus K8S SVC to localhost kubectl port-forward service/prometheus-prometheus -n monitoring 9090:9090Now you can access
http://localhost:9090/to open the Prometheus dashboard. You can see Kong’s metrics on the Prometheus dashboard.