Menu
Grafana Cloud

Send Kubernetes metrics, logs, and events to Grafana Cloud with Helm and Ansible

You can use Helm and Ansible to configure Kubernetes Monitoring, and use:

  • The Kubernetes Monitoring GUI
  • Preconfigured dashboards, alerts, and recording rules

Before you begin

Make sure you have the following available:

  • Ansible CLI installed in your system
  • Access to a Kubernetes Cluster
  • The Admin role to install preconfigured components such as dashboards

Configuration steps

The steps to configure Kubernetes Monitoring with Ansible are:

  1. Use a Grafana Cloud Access Policy token.
  2. Install the preconfigured components.
  3. Set up the Ansible Playbook
  4. Run the Ansible Playbook.

Create or gather Grafana Cloud Access Policy token

You can create a new access policy token or look up an existing token. See Grafana Cloud Access Policies for more information.

You’ll use this token in a future step.

Install preconfigured dashboards, alerts, and recording rules

To install preconfigured dashboards, alerts, and recording rules, complete the following steps:

  1. Navigate to your Grafana Cloud account.
  2. Click the upper-left menu icon to open the main menu.
  3. Click Observability.
  4. Click the Kubernetes tile. The Configuration page appears.
  5. Under the heading Dashboards, alerts, and recording rules, click Install to install the dashboards, alerts, and recording rules.

Configure the Ansible Playbook

To install the Kubernetes Monitoring components, complete the following steps.

  1. Copy and paste the following configuration into a terminal:
cat >> grafana-k8s-monitoring.yaml <<'EOF'
- name: Grafana Kubernetes Monitoring
  hosts: localhost

  # Declare variables
  vars:
    namespace: <NAMESPACE>
    cluster_name: <CLUSTER_NAME>
    metrics_username: <METRICS_USERNAME>
    prometheus_url: <PROMETHEUS_URL>
    logs_username: <LOGS_USERNAME>
    loki_url: <LOKI_URL>
    traces_username: <TRACES_USERNAME>
    tempo_url: <TRACES_URL>
    grafana_cloud_token: <GRAFANA_CLOUD_ACCESS_TOKEN>

  tasks:

    - name: Deploy Grafana Kubernetes Monitoring Helm Chart
      kubernetes.core.helm:
        name: grafana-k8s-monitoring
        chart_ref: grafana/k8s-monitoring
        release_namespace: "{{ namespace }}"
        chart_version: 0.2.5
        values:
          cluster:
            name: "{{ cluster_name }}"
          externalServices:
            prometheus:
              host: "{{ prometheus_url }}"
              basicAuth:
                username: "{{ metrics_username }}"
                password: "{{ grafana_cloud_token }}"
            loki:
              host: "{{ loki_url }}"
              basicAuth:
                username: "{{ logs_username }}"
                password: "{{ grafana_cloud_token }}"
            tempo:
              host: "{{ tempo_url }}"
              basicAuth:
                username: "{{ traces_username }}"
                password: "{{ grafana_cloud_token }}"
          opencost:
            opencost:
              exporter:
                defaultClusterId: "{{ cluster_name }}"
              prometheus:
                external:
                  url: "{{ prometheus_url }}/api/prom"
          traces:
            enabled: true
          grafana-agent:
            agent:
              extraPorts:
                - name: otlp-traces
                  port: 4317
                  targetPort: 4317
                  protocol: TCP
EOF
  1. Replace the following in the code:

    • NAMESPACE with your namespace where you want to deploy Kubernetes Monitoring resources
    • CLUSTER_NAME with your Cluster name
    • METRICS_USERNAME with the Prometheus instance ID
    • PROMETHEUS_URL with the push endpoint URL of the Prometheus instance
    • LOGS_USERNAME with Loki Username
    • LOKI_URL with the push endpoint URL of the Loki instance
    • TRACES_USERNAME with Tempo Username
    • TEMPO_URL with the push endpoint URL of the Tempo instance
    • GRAFANA_CLOUD_ACCESS_TOKEN with your Grafana Cloud Access token

Run the Ansible Playbook

Complete the following steps to run the Ansible Playbook and deploy the resources.

  1. Open a terminal or shell.

  2. Navigate to the directory where the Ansible Playbook is located.

  3. Run the following command to run the Ansible Playbook:

    shell
    ansible-playbook grafana-k8s-monitoring.yaml

    This command will run the Ansible Playbook, Installing the Kubernetes Monitoring components in your cluster.

Next steps

  1. Navigate to Kubernetes Monitoring, and click Configuration on the main menu.

  2. Click the Metrics status tab to view the data status. Your data begins populating in the view as the system components begin scraping and sending data to Grafana Cloud.

    Metrics status tab
    Metrics status tab