菜单
文档breadcrumb arrow Grafana Pyroscopebreadcrumb arrow 在 Kubernetes 上部署breadcrumb arrow 使用 Jsonnet 和 Tanka 部署
开源

使用 Jsonnet 和 Tanka 部署 Pyroscope

Grafana Labs 发布了一个 Jsonnet 库,您可以使用它来部署 Pyroscope。Jsonnet 文件位于 Pyroscope 仓库中,并使用 helm charts 作为来源。

安装工具并部署第一个集群

您可以使用 Tankajsonnet-bundler 从 jsonnet 文件生成 Kubernetes YAML manifest。

  1. 安装 tankajb

    按照 https://tanka.dev/install 的步骤操作。如果您本地安装了 go,您也可以使用

    控制台
    # 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. 根据以下示例设置一个 Jsonnet 项目

    • 初始化 Tanka
    • 安装 Pyroscope 和 Kubernetes Jsonnet 库
    • 设置环境
    控制台
    # 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. 决定您是要以单体模式还是微服务模式运行 Pyroscope

  • 选项 A) 对于单体模式,environments/default/main.jsonnet 文件应如下所示;

    jsonnet
    local pyroscope = import 'pyroscope/jsonnet/pyroscope/pyroscope.libsonnet';
    local tk = import 'tk';
    
    pyroscope.new(overrides={
      namespace: tk.env.spec.namespace,
    })
  • 选项 B) 对于微服务模式,environments/default/main.jsonnet 文件应如下所示;

    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. 生成 Kubernetes YAML manifest 并将其存储在 ./manifests 目录中

    控制台
    # 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. 通过以下两种方式之一将 manifest 部署到 Kubernetes 集群

    • 使用 tk apply 命令.

      Tanka 支持显示 diff 并将 apply 更改应用到 Kubernetes 集群的命令

      控制台
      # 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
    • 使用 kubectl apply 命令.

      您在上一步中生成了 Kubernetes manifest 并将其存储在 ./manifests 目录中。

      您可以运行以下命令将这些 manifest 直接应用到您的 Kubernetes 集群

      控制台
      # 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/

    注意:生成的 Kubernetes manifest 在 default 命名空间中创建资源。要使用不同的命名空间,请更改 environments/default/main.jsonnet 文件中的 namespace 配置选项,然后重新生成 Kubernetes manifest。