Grafana Cloud

Configure remote_write with Helm and kube-prometheus-stack

In this guide, you’ll learn how to configure Prometheus’s remote_write feature to ship cluster metrics to Grafana Cloud using Helm and kube-prometheus-stack.

The kube-prometheus-stack Helm chart installs the kube-prometheus stack. The kube-prometheus stack configures Prometheus Operator with a default Prometheus-Alertmanager-Grafana stack and sets up preconfigured Grafana dashboards and Alertmanager alerts. It also configures a set of Prometheus scrape targets and sets up node-exporter and kube-state-metrics. Prometheus Operator is a sub-component of the kube-prometheus stack.

Prometheus Operator implements the Kubernetes Operator pattern for managing a Prometheus-based Kubernetes monitoring stack. A Kubernetes Operator consists of Kubernetes custom resources and controller code that abstract away the management and implementation details of running a given service on Kubernetes. To learn more about Kubernetes Operators, see Operator pattern from the Kubernetes docs.

The Prometheus Operator provides a set of Kubernetes Custom Resources that simplify Prometheus, Grafana and Alertmanager deployment and configuration. For example, using the ServiceMonitor custom resource, you can configure how to monitor groups of Kubernetes services in YAML manifests. The Operator controller then communicates with the Kubernetes API server to monitor service endpoints and automatically generate the required Prometheus scrape configurations for the configured services. To learn more about Prometheus Operator, refer to the Prometheus Operator GitHub repository.

Before you begin

This guide assumes you have installed kube-prometheus-stack in your Kubernetes cluster using the Helm package manager.

  • To learn how to install Helm on your local machine, see Install Helm from the Helm documentation.
  • To learn how to install kube-prometheus-stack, see Install Chart from the kube-prometheus-stack GitHub repo.

If you did not use Helm to install kube-prometheus, see Configure remote_write with Prometheus Operator.

Create a Kubernetes Secret to store Grafana Cloud credentials

To begin, you’ll create a Kubernetes Secret to store your Grafana Cloud Metrics username and password.

To create your Kubernetes Secret:

  1. Find your username by navigating to your stack in the Cloud Portal and clicking Details next to the Prometheus panel.

    Your password corresponds to an API key that you can generate by clicking Generate now in the same panel. To learn how to create a Grafana Cloud API key, see Create a Grafana Cloud API key

  2. Once you’ve noted your Cloud Prometheus username and password, run the following command to create a Secret, in this example, kubepromsecret:

    kubectl create secret generic kubepromsecret \
     -n default

    Note: If you deployed your monitoring stack in a namespace other than default, change the -n default flag to the appropriate namespace in the above command. To learn more about this command, see Managing Secrets using kubectl from the official Kubernetes docs.

    kubectl create secret generic kubepromsecret \
     -n default

    Instead of creating the secret directly as in this example, alternatively you can use a manifest file. To learn more about Kubernetes Secrets, refer to Secrets from the Kubernetes docs.

Now that you’ve created a Secret to store your Grafana Cloud credentials, you can move on to modifying Prometheus’s configuration using a Helm values file.

Create a Helm values file with Prometheus remote_write configuration

Next, you’ll create a Helm values file to define parameters for Prometheus’s remote_write configuration. A Helm values file allows you to set configuration variables that are passed in to Helm’s object templates. To see the default values file for kube-prometheus-stack, refer to values.yaml from the kube-prometheus-stack GitHub repository.

You’ll first create a values.yaml file defining Prometheus’s remote_write configuration, and then you’ll apply the new configuration to kube-prometheus-stack.

  1. Open a file named new_values.yaml in an editor and paste in the following values:

        - url: "<Your Metrics instance remote_write endpoint>"
                name: kubepromsecret
                key: username
                name: kubepromsecret
                key: password

    Set the remote_write URL and basic_auth username and password using the Secret created in the previous section.

  2. When you’re done editing the file, save and close it.

  3. Roll out the changes using the following command:

    helm upgrade -f new_values.yaml [your_release_name] prometheus-community/kube-prometheus-stack

    Replace [your_release_name] with the name of the release you used to install kube-prometheus-stack. You can get a list of installed releases using helm list.

  4. After running helm upgrade, you should see the following output:

    Release "your_release_name" has been upgraded. Happy Helming!
    NAME: your_release_name
    LAST DEPLOYED: Mon Dec  7 17:29:03 2020
    NAMESPACE: default
    STATUS: deployed
    kube-prometheus-stack has been installed. Check its status by running:
      kubectl --namespace default get pods -l "release=your_release_name"
    Visit for instructions on how to create & configure Alertmanager and Prometheus instances using the Operator.

Verify your updates

At this point, you’ve successfully configured your Prometheus instances to remote_write scraped metrics to Grafana Cloud. You can verify that your changes have propagated to your running Prometheus instances using port-forward.

To verify your changes:

  1. Use port-forward by running this command:

    kubectl --namespace default port-forward svc/<your_release_name>-kube-prometheus-sta-prometheus 9090

    Replace namespace with the appropriate namespace, and <your_release_name> with the Helm release name.

  2. Navigate to http://localhost:9090 in your browser, and then Status and Configuration.

  3. Verify that the remote_write block you appended above has propagated to your running Prometheus instances.

  4. Finally, log in to your Grafana instance to begin querying your cluster data.

    You can use the Billing/Usage dashboard to inspect incoming data rates in the last 5 minutes to confirm the flow of data to Grafana Cloud.