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

Deploy Pyroscope with Jsonnet and Tanka

Grafana Labs publishes a Jsonnet library that you can use to deploy Pyroscope. The Jsonnet files are located in the Pyroscope repository and are using the helm charts as a source.

Install tools and deploy the first cluster

You can use Tanka and jsonnet-bundler to generate Kubernetes YAML manifests from the jsonnet files.

  1. Install tanka and jb:

    Follow the steps at https://tanka.dev/install. If you have go installed locally you can also use:

    console
    # make sure to be outside of GOPATH or a go.mod project
    go install github.com/grafana/tanka/cmd/tk@latest
    go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
  2. Set up a Jsonnet project, based on the example that follows:

    • Initialize Tanka
    • Install Pyroscope and Kubernetes Jsonnet libraries
    • Set up an environment
    console
    # Initialize a Tanka directory
    mkdir jsonnet-example && cd jsonnet-example
    tk init --k8s=1.21
    
    # Install Pyroscope jsonnet
    jb install github.com/grafana/pyroscope/operations/pyroscope@main
    
    # Install required tanka-util
    jb install github.com/grafana/jsonnet-libs/tanka-util@master
    
    # Setup your current cluster as the server for the default environment
    tk env set environments/default --server-from-context=$(kubectl config current-context)
  3. Decide if you want to run Pyroscope in the monolithic or the microservices mode

  • Option A) For monolithic mode the file environments/default/main.jsonnet, should look like;

    jsonnet
    local pyroscope = import 'pyroscope/jsonnet/pyroscope/pyroscope.libsonnet';
    local tk = import 'tk';
    
    pyroscope.new(overrides={
      namespace: tk.env.spec.namespace,
    })
  • Option B) For microservices mode the file environments/default/main.jsonnet, should look like;

    jsonnet
    local pyroscope = import 'pyroscope/jsonnet/pyroscope/pyroscope.libsonnet';
    local valuesMicroServices = import 'pyroscope/jsonnet/values-micro-services.json';
    local tk = import 'tk';
    
    pyroscope.new(overrides={
      namespace: tk.env.spec.namespace,
      values+: valuesMicroServices,
    })
  1. Generate the Kubernetes YAML manifests and store them in the ./manifests directory:

    console
    # Take a look at the generated YAML manifests.
    tk show environments/default
    
    # Export the YAML manifests to the folder `./manifests`:
    tk export ./manifests environments/default
  2. Deploy the manifests to a Kubernetes cluster, in one of two ways:

    • Use the tk apply command.

      Tanka supports commands to show the diff and apply changes to a Kubernetes cluster:

      console
      # Show the difference between your Jsonnet definition and your Kubernetes cluster:
      tk diff environments/default
      
      # Apply changes to your Kubernetes cluster:
      tk apply environments/default
    • Use the kubectl apply command.

      You generated the Kubernetes manifests and stored them in the ./manifests directory in the previous step.

      You can run the following command to directly apply these manifests to your Kubernetes cluster:

      console
      # Review the changes that will apply to your Kubernetes cluster:
      kubectl apply --dry-run=client -k manifests/
      
      # Apply the changes to your Kubernetes cluster:
      kubectl apply -k manifests/

    Note: The generated Kubernetes manifests create resources in the default namespace. To use a different namespace, change the namespace configuration option in the environments/default/main.jsonnet file, and re-generate the Kubernetes manifests.