github.com/grafana/pyroscope@v1.18.0/docs/sources/configure-client/grafana-alloy/ebpf/setup-kubernetes.md (about)

     1  ---
     2  title: "Setup eBPF Profiling on Kubernetes"
     3  menuTitle: "Setting up on Kubernetes"
     4  description: "Setting up eBPF Profiling with Grafana Alloy on Kubernetes"
     5  weight: 10
     6  ---
     7  
     8  # Setup eBPF Profiling on Kubernetes
     9  
    10  To set up eBPF profiling with Grafana Alloy on Kubernetes, you need to:
    11  
    12  - Verify that your cluster meets the prerequisites.
    13  - Add the Grafana helm repository.
    14  - Create an Alloy configuration file. For more information, refer to [Configuration reference][config-reference].
    15  - Install Alloy, refer to the [installation instructions](https://grafana.com/docs/alloy/<ALLOY_VERSION>/set-up/install/kubernetes/)
    16  - Verify that profiles are received.
    17  
    18  ## Before you begin
    19  
    20  Before you begin, you need:
    21  
    22  - [Helm][helm] and [kubectl][kubectl] installed with access to your Kubernetes cluster.
    23  - A Pyroscope server where Alloy can send profiling data.
    24  - Access to Grafana with the [Grafana Pyroscope data source][pyroscope-ds] provisioned.
    25  
    26  {{< admonition type="note" >}}
    27  If you don't have a Grafana or a Pyroscope server, you can use the [Grafana Cloud][gcloud] free plan to get started.
    28  {{< /admonition >}}
    29  
    30  ## Verify that your cluster meets the requirements
    31  
    32  The eBPF profiler requires a Linux kernel version >= 4.9 (due to [BPF_PROG_TYPE_PERF_EVENT](https://lkml.org/lkml/2016/9/1/831)).
    33  
    34  `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.
    35  
    36  To print the kernel version of each node in your cluster, run:
    37  
    38  ```shell
    39  kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.nodeInfo.kernelVersion}{"\n"}{end}'
    40  ```
    41  
    42  Make sure all nodes have a kernel version >= 4.9.
    43  
    44  ## Add the Grafana Helm repository
    45  
    46  Use [Helm][helm] to install Alloy.
    47  To add the Grafana Helm repository, run:
    48  
    49  ```shell
    50  helm repo add grafana https://grafana.github.io/helm-charts
    51  helm repo update
    52  ```
    53  
    54  Verify that the repository was added successfully by running:
    55  
    56  ```shell
    57  helm search repo grafana/alloy
    58  ```
    59  
    60  The command returns a list of available versions of Alloy.
    61  
    62  ## Create an Alloy configuration file
    63  
    64  Create a file named `values.yaml` with the content from the sample configuration file.
    65  
    66  ```yaml
    67  alloy:
    68    configMap:
    69      create: true
    70      content: |
    71        discovery.kubernetes "local_pods" {
    72          selectors {
    73            field = "spec.nodeName=" + env("HOSTNAME")
    74            role = "pod"
    75          }
    76          role = "pod"
    77        }
    78        pyroscope.ebpf "instance" {
    79          forward_to = [pyroscope.write.endpoint.receiver]
    80          targets = discovery.kubernetes.local_pods.targets
    81        }
    82        pyroscope.write "endpoint" {
    83          endpoint {
    84            basic_auth {
    85              password = "<PASSWORD>"
    86              username = "<USERNAME>"
    87            }
    88            url = "<URL>"
    89          }
    90        }
    91  
    92    securityContext:
    93      privileged: true
    94      runAsGroup: 0
    95      runAsUser: 0
    96  
    97  controller:
    98    hostPID: true
    99  ```
   100  
   101  For information about configuring Alloy, refer to [Grafana Alloy on Kubernetes](https://grafana.com/docs/alloy/<ALLOY_VERSION>/configure/kubernetes/).
   102  
   103  For information about the specific blocks used, refer to the [Grafana Alloy Reference](https://grafana.com/docs/alloy/<ALLOY_VERSION>/reference/).
   104  
   105  Replace the `<URL>` placeholder with the appropriate server URL.
   106  This could be the Grafana Cloud URL or your own custom Pyroscope server URL.
   107  
   108  If you need to send data to Grafana Cloud, you'll have to configure HTTP Basic authentication.
   109  Replace `<User>` with your Grafana Cloud stack user and `<Password>` with your Grafana Cloud API key.
   110  
   111  For more information, refer to the [Configure the Grafana Pyroscope data source documentation](/docs/grafana-cloud/connect-externally-hosted/data-sources/pyroscope/configure-pyroscope-data-source/).
   112  
   113  {{% admonition type="note" %}}
   114  If you're using your own Pyroscope server, you can remove the `basic_auth` section altogether.
   115  {{% /admonition %}}
   116  
   117  
   118  ## Install Alloy
   119  
   120  To install Alloy, run:
   121  
   122  ```shell
   123  helm install pyroscope-ebpf grafana/alloy -f values.yaml
   124  ```
   125  
   126  Once configured, Alloy starts collecting eBPF profiles and sends them to the Pyroscope server.
   127  
   128  ## Verify profiles are received
   129  
   130  To verify that the profiles are received by the Pyroscope server:
   131  
   132  1. Go to the Pyroscope UI or [Grafana Pyroscope data source][pyroscope-ds].
   133  1. Select a profile type and a service from the drop-down menu.
   134  
   135  [gcloud]: /products/cloud/
   136  [helm]: https://helm.sh/docs/intro/install/
   137  [kubectl]: https://kubernetes.io/docs/tasks/tools/install-kubectl/
   138  [pyroscope-ds]: /docs/grafana/<GRAFANA_VERSION>/datasources/pyroscope/
   139  [config-reference]: ../configuration/
   140  
   141  ## Considerations for profiling applications in containers
   142  
   143  When profiling Python applications running in containers using the `pyroscope.ebpf` [component in Alloy](/docs/alloy/<ALLOY_VERSION>/reference/components/pyroscope/pyroscope.ebpf/), consider the following:
   144  
   145  - **Kernel version**: Ensure that the host system's kernel version is >= 4.9, as required by eBPF. This is crucial for the profiler to function correctly
   146  
   147  - **Container privileges**: The eBPF profiler requires certain privileges to access kernel features. Ensure that the container running the profiler has the necessary permissions. This typically involves setting the container to run in privileged mode or adjusting security contexts
   148  
   149  - **Host PID namespace**: The profiler may need access to the host's PID namespace to correctly attach to processes. Ensure that the `hostPID` is set to `true` in your Kubernetes configuration
   150  
   151  - **Network access**: Ensure that the container has network access to send profiling data to the Pyroscope server. This may involve configuring network policies or service accounts