- Deploying Prometheus in a CKS cluster using Helm
- Adding Prometheus as a data source in your self-hosted Grafana instance
- Configuring Prometheus to scrape custom metrics from your application pods
Prerequisites
- A CKS cluster with at least one CPU Node available for Prometheus
kubectlinstalled and configured for your clusterhelminstalled- A self-hosted Grafana instance. If you haven’t set one up yet, see Self-hosted Grafana first.
Deploy Prometheus
Prometheus is available via theprometheus-community Helm chart repository. Install it using the kube-prometheus-stack chart, which includes Prometheus and the Prometheus Operator.
This tutorial uses ephemeral storage. Prometheus stores its metrics in an emptyDir volume, so collected history is lost when the Prometheus Pod is deleted or replaced. For a durable deployment, configure persistent storage with prometheus.prometheusSpec.storageSpec before installing the chart.
-
Add the
prometheus-communityHelm chart repository: -
Create a values file named
prometheus-values.yamlwith the following content:These settings disable components that this tutorial does not use:prometheus-values.yamlgrafana.enabled: falseskips the bundled Grafana instance because you use the CoreWeave self-hosted Grafana chart instead.alertmanager.enabled: falseskips Alertmanager.nodeExporter.enabled: falseskips the bundled node exporter. CoreWeave already runs a node exporter on each CKS Node. The bundled exporter cannot bind host port9100because that port is already in use.kubeStateMetrics.enabled: falseskips a second copy of kube-state-metrics, which watches Kubernetes API objects. CoreWeave runs kube-state-metrics on the managed control plane, rather than on each Node.defaultRules.create: falseskips the chart’s default alerting and recording rules. Those rules include checks for components that this configuration does not deploy or scrape, which can produce firing alerts even when your application metrics are available.
kube_pod_infoandnode_cpu_seconds_total. Imported dashboards that depend on those metrics show no data. Use CoreWeave Grafana for the infrastructure metrics collected by CoreWeave. Kubelet and cAdvisor scraping remain enabled in this configuration. -
Install Prometheus in a dedicated
monitoringnamespace:You should see output similar to the following:
Verify the Prometheus deployment
Run the following command to confirm Prometheus is running:Running and all containers are ready (1/1 for the Operator and 2/2 for Prometheus). If they are still starting, rerun the command after a short wait.
You should see output similar to the following:
9090 from the command output. Use this exact name for [PROMETHEUS-SERVICE] in the URL and port-forward command below. The chart can truncate generated names, so do not infer the Service name from the Helm release name.
Add Prometheus as a data source in Grafana
To query your custom application metrics from Grafana, add Prometheus as a data source.-
Open your self-hosted Grafana instance and log in. If you need to access it, first find the namespace of its Service:
Copy the value in the
NAMESPACEcolumn for your Grafana instance. Then run the following port-forward command, replacing[GRAFANA-NAMESPACE]with that value: - In the Grafana left-hand menu, navigate to Connections > Data sources, then click + Add new data source.
- Select Prometheus from the list of available data sources.
-
In the Connection section, set the Prometheus server URL to the Prometheus service address. If Grafana and Prometheus are deployed in different namespaces, use the fully qualified service URL. Replace
[PROMETHEUS-SERVICE]with the Service name you copied in Verify the Prometheus deployment. Replace[PROMETHEUS-NAMESPACE]withmonitoring, the namespace specified in the Helm install command. This is the Prometheus namespace, which can differ from[GRAFANA-NAMESPACE]:For example, the Serviceprometheus-kube-prometheus-prometheusin themonitoringnamespace has the URLhttp://prometheus-kube-prometheus-prometheus.monitoring.svc.cluster.local:9090. - Leave the remaining settings at their defaults, including Authentication method set to No Authentication. This tutorial connects to the in-cluster Prometheus Service without authentication or TLS.
- Scroll to the bottom of the page and click Save & test. You should see a confirmation that the data source is working.
Configure Prometheus to scrape custom metrics
Prometheus Operator usesServiceMonitor resources to configure which services to scrape. Create a ServiceMonitor that targets your application.
Expose metrics from your application
Your application must expose a Prometheus-compatible metrics endpoint, typically at/metrics on a designated port. Many frameworks provide this out of the box, including:
- Python:
prometheus_client - Go:
prometheus/client_golang - Java: Micrometer
prometheus_client might expose metrics at port 8000:
/metrics. Call REQUEST_COUNT.inc() in your application’s request handler once per request you want to count. Creating the counter alone does not increment it.
Create a Service for your application
Create a Kubernetes Service that exposes the metrics port with a named port. Prometheus uses the port name to identify which port to scrape. This example assumes your application is already deployed in the cluster, its Pods have the labelapp: my-app, and its metrics endpoint listens on port 8000. Adjust spec.selector and targetPort to match your application.
app-service.yaml
[APP-NAMESPACE] with your application’s namespace.
Apply the Service:
Create a ServiceMonitor
Create aServiceMonitor resource that tells Prometheus to scrape the Service you just created:
app-servicemonitor.yaml
[APP-NAMESPACE] with your application’s namespace.
The
release: prometheus label on the ServiceMonitor must match the Helm release name used when installing kube-prometheus-stack. If you used a different release name, update this label accordingly.ServiceMonitor:
Verify Prometheus is scraping your application
To confirm Prometheus is scraping your application, port-forward to the Prometheus Service. Replace[PROMETHEUS-SERVICE] with the name you copied in Verify the Prometheus deployment and [PROMETHEUS-NAMESPACE] with monitoring:
http://localhost:9090/targets in your browser. Allow time for Prometheus to discover the ServiceMonitor and complete its first scrape. The configuration above scrapes every 30 seconds. Refresh the page until your application appears in the list of scrape targets with a status of UP.
These custom metrics appear only in your self-hosted Prometheus and Grafana. CoreWeave’s managed observability collects infrastructure metrics and does not surface your application metrics in CoreWeave Grafana.
Query custom metrics in Grafana
With Prometheus configured as a data source in Grafana, you can now query your custom metrics.- In Grafana, navigate to Explore from the left-hand menu.
- Select your data source, such as prometheus, from the dropdown at the top of the page.
-
Select Code to enter a PromQL query using one of your application’s metric names. For example:
- Click Run query. Your custom metric data should appear in the query results. If you see No data, confirm that the target is UP, allow time for a scrape, and run the query again. The counter increases only when your application increments it.
app_requests_total in Grafana Explore for a sample application that increments the counter. Your values depend on your application’s activity.
You can build dashboards with your custom metrics by navigating to Dashboards > New > New dashboard and adding panels that reference your Prometheus data source.
Learn more
- Prometheus documentation on configuring scraping, alerting rules, and PromQL
- Prometheus Operator documentation on
ServiceMonitor,PodMonitor, and other custom resources - Self-hosted Grafana for setup instructions and configuring CoreWeave data sources
- Forward application metrics to send CKS metrics to an external Prometheus instance