github.com/grafana/pyroscope@v1.18.0/docs/sources/deploy-kubernetes/tanka-jsonnet.md (about)

     1  ---
     2  description: Learn how to deploy Pyroscope on Kubernetes with Jsonnet and Tanka.
     3  keywords:
     4    - Pyroscope deployment
     5    - Kubernetes
     6    - Jsonnet
     7    - Tanka
     8  menuTitle: Deploy with Jsonnet and Tanka
     9  title: Deploy Pyroscope with Jsonnet and Tanka
    10  weight: 60
    11  aliases:
    12    - /docs/phlare/latest/operators-guide/deploying-grafana-phlare/jsonnet/
    13    - /docs/phlare/latest/deploy-kubernetes/tanka-jsonnet/
    14  ---
    15  
    16  # Deploy Pyroscope with Jsonnet and Tanka
    17  
    18  Grafana Labs publishes a [Jsonnet](https://jsonnet.org/) library that you can use to deploy Pyroscope.
    19  The Jsonnet files are located in the [Pyroscope repository](https://github.com/grafana/pyroscope/tree/main/operations/pyroscope/jsonnet) and are using the helm charts as a source.
    20  
    21  
    22  ## Install tools and deploy the first cluster
    23  
    24  You can use [Tanka](https://tanka.dev/) and [jsonnet-bundler](https://github.com/jsonnet-bundler/jsonnet-bundler) to generate Kubernetes YAML manifests from the jsonnet files.
    25  
    26  1. Install `tanka` and `jb`:
    27  
    28     Follow the steps at [https://tanka.dev/install](https://tanka.dev/install). If you have `go` installed locally you can also use:
    29  
    30     ```console
    31     # make sure to be outside of GOPATH or a go.mod project
    32     go install github.com/grafana/tanka/cmd/tk@latest
    33     go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest
    34     ```
    35  
    36  1. Set up a Jsonnet project, based on the example that follows:
    37  
    38     - Initialize Tanka
    39     - Install Pyroscope and Kubernetes Jsonnet libraries
    40     - Set up an environment
    41  
    42     ```console
    43     # Initialize a Tanka directory
    44     mkdir jsonnet-example && cd jsonnet-example
    45     tk init --k8s=1.21
    46  
    47     # Install Pyroscope jsonnet
    48     jb install github.com/grafana/pyroscope/operations/pyroscope@main
    49  
    50     # Install required tanka-util
    51     jb install github.com/grafana/jsonnet-libs/tanka-util@master
    52  
    53     # Setup your current cluster as the server for the default environment
    54     tk env set environments/default --server-from-context=$(kubectl config current-context)
    55     ```
    56  
    57  1. Decide if you want to run Pyroscope in the monolithic or the microservices mode
    58  
    59    - Option A) For monolithic mode the file `environments/default/main.jsonnet`, should look like;
    60  
    61      ```jsonnet
    62      local pyroscope = import 'pyroscope/jsonnet/pyroscope/pyroscope.libsonnet';
    63      local tk = import 'tk';
    64  
    65      pyroscope.new(overrides={
    66        namespace: tk.env.spec.namespace,
    67      })
    68      ```
    69  
    70    - Option B) For microservices mode the file `environments/default/main.jsonnet`, should look like;
    71  
    72      ```jsonnet
    73      local pyroscope = import 'pyroscope/jsonnet/pyroscope/pyroscope.libsonnet';
    74      local valuesMicroServices = import 'pyroscope/jsonnet/values-micro-services.json';
    75      local tk = import 'tk';
    76  
    77      pyroscope.new(overrides={
    78        namespace: tk.env.spec.namespace,
    79        values+: valuesMicroServices,
    80      })
    81      ```
    82  1. Generate the Kubernetes YAML manifests and store them in the `./manifests` directory:
    83  
    84     ```console
    85     # Take a look at the generated YAML manifests.
    86     tk show environments/default
    87  
    88     # Export the YAML manifests to the folder `./manifests`:
    89     tk export ./manifests environments/default
    90     ```
    91  
    92  1. Deploy the manifests to a Kubernetes cluster, in one of two ways:
    93  
    94     - **Use the `tk apply` command**.
    95  
    96       Tanka supports commands to show the `diff` and `apply` changes to a Kubernetes cluster:
    97  
    98       ```console
    99       # Show the difference between your Jsonnet definition and your Kubernetes cluster:
   100       tk diff environments/default
   101  
   102       # Apply changes to your Kubernetes cluster:
   103       tk apply environments/default
   104       ```
   105  
   106     - **Use the `kubectl apply` command**.
   107  
   108       You generated the Kubernetes manifests and stored them in the `./manifests` directory in the previous step.
   109  
   110       You can run the following command to directly apply these manifests to your Kubernetes cluster:
   111  
   112       ```console
   113       # Review the changes that will apply to your Kubernetes cluster:
   114       kubectl apply --dry-run=client -k manifests/
   115  
   116       # Apply the changes to your Kubernetes cluster:
   117       kubectl apply -k manifests/
   118       ```
   119  
   120     > **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.