Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Open source

Setup eBPF Profiling on Kubernetes

To set up eBPF profiling with Grafana Agent on Kubernetes, you need to:

  • Verify that your cluster meets the prerequisites.
  • Add the Grafana helm repository.
  • Create a Grafana Agent configuration file. For more information, refer to Configuration reference.
  • Install Grafana Agent.
  • Verify that profiles are received.

Caution

Grafana Alloy is the new name for our distribution of the OTel collector. Grafana Agent has been deprecated and is in Long-Term Support (LTS) through October 31, 2025. Grafana Agent will reach an End-of-Life (EOL) on November 1, 2025. Read more about why we recommend migrating to Grafana Alloy.

Prerequisites

Before you begin, you need:

Note

If you don’t have a Grafana and/or a Pyroscope server, you can use the [Grafana Cloud][gcloud] free plan to get started.

Verify that your cluster meets the requirements

The eBPF profiler requires a Linux kernel version >= 4.9 (due to BPF_PROG_TYPE_PERF_EVENT).

BPF_PROG_TYPE_PERF_EVENT is a type of eBPF program that can be attached to hardware or software events, such as performance monitoring counters or tracepoints, in the Linux kernel.

To print the kernel version of each node in your cluster, run:

shell
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.nodeInfo.kernelVersion}{"\n"}{end}'

Make sure all nodes have a kernel version >= 4.9.

Add the Grafana Helm repository

We recommend using Helm to install Grafana Agent. To add the Grafana Helm repository, run:

shell
helm repo add grafana https://grafana.github.io/helm-charts
helm repo update

Verify that the repository was added successfully by running:

shell
helm search repo grafana/grafana-agent

It should return a list of available versions of Grafana Agent.

Create a Grafana Agent configuration file

Create a file named values.yaml with the following content:

yaml
agent:
  mode: 'flow'
  configMap:
    create: true
    content: |
      discovery.kubernetes "local_pods" {
        selectors {
          field = "spec.nodeName=" + env("HOSTNAME")
          role = "pod"
        }
        role = "pod"
      }
      pyroscope.ebpf "instance" {
        forward_to = [pyroscope.write.endpoint.receiver]
        targets = discovery.kubernetes.local_pods.targets
      }
      pyroscope.write "endpoint" {
        endpoint {
          basic_auth {
            password = "<PASSWORD>"
            username = "<USERNAME>"
          }
          url = "<URL>"
        }
      }

  securityContext:
    privileged: true
    runAsGroup: 0
    runAsUser: 0

controller:
  hostPID: true

Replace the <URL> placeholder with the appropriate server URL. This could be the Grafana Cloud URL or your own custom Pyroscope server URL.

If you need to send data to Grafana Cloud, you’ll have to configure HTTP Basic authentication. Replace <User> with your Grafana Cloud stack user and <Password> with your Grafana Cloud API key.

Note

If you’re using your own Pyroscope server, you can remove the basic_auth section altogether.

For more information, refer to the Configure the Grafana Pyroscope data source documentation.

Install the Grafana Agent

To install the Grafana Agent, run:

shell
helm install pyroscope-ebpf grafana/grafana-agent -f values.yaml

Once configured, the Agent starts collecting eBPF profiles and send them to the Pyroscope server.

Verify profiles are received

To verify that the profiles are received by the Pyroscope server, go to the Pyroscope UI or Grafana Pyroscope datasource. Select a profile type and a service from the drop-down menu.