github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/examples/golang-pull/kubernetes/README.md (about) 1 # Pyroscope pull mode and Kubernetes Discovery 2 3 This example demonstrates how Pyroscope can be used to scrape pprof profiles from Kubernetes pods. 4 5 ### 1. Run minikube kubernetes cluster locally (optional) 6 7 In this example we use minikube for sake of simplicity, visit [minikube documentation](https://minikube.sigs.k8s.io/docs/start/) 8 to learn more. 9 10 ```shell 11 minikube start 12 ``` 13 14 ### 2. Install Pyroscope with Helm chart 15 16 The official [Pyroscope Helm chart](https://github.com/pyroscope-io/helm-chart) deploys Pyroscope server and creates proper RBAC roles: 17 18 ```shell 19 helm repo add pyroscope-io https://pyroscope-io.github.io/helm-chart 20 helm install demo pyroscope-io/pyroscope -f values.yaml 21 ``` 22 23 Note that we apply configuration defined in `values.yaml`: Pyroscope uses the same discovery mechanisms as 24 Prometheus does in order to ensure smooth user experience, and it fully supports 25 [Kubernetes Service Discovery](https://pyroscope.io/docs/golang-pull-mode/#kubernetes-service-discovery): 26 27 28 ```yaml 29 --- 30 pyroscopeConfigs: 31 log-level: debug 32 scrape-configs: 33 - job-name: 'kubernetes-pods' 34 enabled-profiles: [ cpu, mem ] 35 kubernetes-sd-configs: 36 - role: pod 37 relabel-configs: 38 - source-labels: [__meta_kubernetes_pod_annotation_pyroscope_io_scrape] 39 action: keep 40 regex: true 41 - source-labels: 42 [__meta_kubernetes_pod_annotation_pyroscope_io_application_name] 43 action: replace 44 target-label: __name__ 45 - source-labels: [__meta_kubernetes_pod_annotation_pyroscope_io_scheme] 46 action: replace 47 regex: (https?) 48 target-label: __scheme__ 49 - source-labels: 50 [__address__, __meta_kubernetes_pod_annotation_pyroscope_io_port] 51 action: replace 52 regex: ([^:]+)(?::\d+)?;(\d+) 53 replacement: $1:$2 54 target-label: __address__ 55 - action: labelmap 56 regex: __meta_kubernetes_pod_label_(.+) 57 - source-labels: [__meta_kubernetes_namespace] 58 action: replace 59 target-label: kubernetes_namespace 60 - source-labels: [__meta_kubernetes_pod_name] 61 action: replace 62 target-label: kubernetes_pod_name 63 - source-labels: [__meta_kubernetes_pod_phase] 64 regex: Pending|Succeeded|Failed|Completed 65 action: drop 66 - action: labelmap 67 regex: __meta_kubernetes_pod_annotation_pyroscope_io_profile_(.+) 68 replacement: __profile_$1 69 ``` 70 71 ### 3. Deploy Hot R.O.D. application 72 73 As a sample application we use slightly modified Jaeger [Hot R.O.D.](https://github.com/jaegertracing/jaeger/tree/master/examples/hotrod) demo – 74 the only difference is that we enabled built-in Go `pprof` HTTP endpoints. You can find the modified code in the [hotrod-goland](https://github.com/pyroscope-io/hotrod-golang) repository. 75 76 Kubernetes resources are defined in [`manifests.yaml`](manifests.yaml): notice pod labels defined – by this we instruct Pyroscope to 77 scrape cpu and memory profiles at `:6060`: 78 ```yaml 79 pyroscope.io/scrape: "true" 80 pyroscope.io/application-name: "hotrod" 81 pyroscope.io/profile-cpu-enabled: "true" 82 pyroscope.io/profile-mem-enabled: "true" 83 pyroscope.io/port: "6060" 84 ``` 85 86 ```shell 87 kubectl apply -f manifests.yaml 88 ``` 89 90 ### 4. Observe profiling data 91 92 Profiling is more fun when the application does some work. Let's order some rides in our Hot R.O.D. app: 93 ```shell 94 minikube service hotrod-golang 95 ``` 96 97 Now that everything is set up, you can browse profiling data via Pyroscope UI: 98 ```shell 99 minikube service demo-pyroscope 100 ```