菜单
文档breadcrumb arrow Helm Chartsbreadcrumb arrow Grafana mimir-distributed Helm Chartbreadcrumb arrow 迁移指南breadcrumb arrow 在 Helm 中 NGINX 和 GEM 网关的统一网关部署
企业版 开源 RSS

在 Helm 中 NGINX 和 GEM 网关的统一网关部署

`mimir-distributed` Helm Chart 的 `4.0.0` 版本新增了一种在 Mimir 前部署 NGINX 反向代理的方式。NGINX 配置与 GEM (Grafana Enterprise Metrics) 网关配置进行了统一。使用单个配置段使得从 Mimir 迁移到 GEM 成为可能,且无需停机。

此次统一还为 GEM 网关带来了新功能:OpenShift Route 和网关 Pod 的水平自动伸缩。

统一的配置位于 values 文件的 `gateway` 段中。我们也同时弃用了 `nginx` 段。该段将在 `mimir-distributed` 的 `7.0.0` 版本中移除。

也可以从 `nginx` 配置迁移到 `gateway` 配置,且无需停机。迁移过程预计不到 30 分钟。本文其余部分包含从旧 `nginx` 段迁移到 `gateway` 的步骤。

开始之前

请确保您已安装的 `mimir-distributed` Helm Chart 版本为 `4.0.0` 或更高。

步骤

  1. 扩展 `gateway` 部署

    1. 修改您的 Helm Chart values 文件以启用 `gateway` 并增加其副本数

      1. 将 gateway Deployment 的副本数设置为 NGINX 当前运行的副本数。

      例如,如果您已部署 10 个 NGINX 副本,则将以下配置添加到您的 Helm Chart values 文件 `custom.yaml` 中

      yaml
      gateway:
        enabledNonEnterprise: true
        replicas: 10
    2. 部署您的更改

      bash
      helm upgrade $RELEASE grafana/mimir-distributed -f custom.yaml
  2. 将 `nginx` 部署替换为 `gateway`

    1. 通过在您的 values 文件中添加或合并以下配置来禁用 NGINX

      yaml
      nginx:
        enabled: false
    2. 如果您正在使用 Helm Chart 提供的 Ingress,则将 `ingress` 段从 `nginx` 复制到 `gateway`,并将名称覆盖为 Helm Chart 为 NGINX 或 GEM 网关创建的 Ingress 资源的名称。

      复用名称允许 `helm` 命令保留现有资源,而不是将其删除并以略有不同的名称重新创建。保留现有资源意味着您的 Kubernetes 集群中的 Ingress Controller 无需删除并重新创建 Ingress 的后端资源,这可能需要时间,具体取决于您使用的 Ingress Controller。

      在以下示例中,Ingress 资源的名称为 `mimir-nginx`。使用 `kubectl` 获取现有 Ingress 资源的名称

      bash
      kubectl get ingress
      console
      NAME          CLASS    HOSTS               ADDRESS    PORTS     AGE
      mimir-nginx   <none>   mimir.example.com   10.0.0.1   80, 443   172d

      `gateway` 的 Helm Chart values 应类似于以下内容

      yaml
      gateway:
        ingress:
          enabled: true
          nameOverride: mimir-nginx
          hosts:
            - host: mimir.example.com
              paths:
                - path: /
                  pathType: Prefix
          tls:
            - secretName: mimir-gateway-tls
              hosts:
                - mimir.example.com
        enabledNonEnterprise: true
        replicas: 10
    3. 更新 `service` 段。

      如果您正在覆盖 `nginx.service` 段中的任何内容,则将 `nginx.service` 段的内容从 `nginx` 复制到 `gateway`。

      接下来,将资源名称覆盖为 Chart 为 NGINX 创建的 Service 资源的名称。复用名称允许 `helm` 命令保留现有资源,而不是将其删除并以略有不同的名称重新创建。复用名称还允许 Kubernetes 集群中的现有客户端在不中断的情况下继续使用 nginx Service 地址。

      在以下示例中,Service 资源的名称为 `mimir-nginx`。使用 `kubectl` 获取现有 Service 资源的名称

      bash
      kubecl get service
      console
      NAME          TYPE        CLUSTER-IP    EXTERNAL-IP   PORT(S)             AGE
      mimir-nginx   ClusterIP   10.188.8.32   <none>        8080/TCP,9095/TCP   172d

      完成此步骤后,`gateway` 的 Helm values 应如下所示

      yaml
      gateway:
        service:
          annotations:
            networking.istio.io/exportTo: admin
          nameOverride: mimir-nginx
        ingress:
          enabled: true
          nameOverride: mimir-nginx
          hosts:
            - host: mimir.example.com
              paths:
                - path: /
                  pathType: Prefix
          tls:
            - secretName: mimir-gateway-tls
              hosts:
                - mimir.example.com
        enabledNonEnterprise: true
        replicas: 10
    4. 如果您正在覆盖 `nginx.nginxConfig`,请更新 readiness probe 端点。

      `gateway` 设置中的 readiness probe 使用容器上的 `/ready` 端点。`mimir-distributed` 的 `4.0.0` 版本配置 NGINX 提供此端点。在此版本之前,该端点不存在。如果您在 `4.0.0` 版本之前已将 `nginx.nginxConfig` 的内容复制到您的 values 文件中,则需要更正 readiness probe。

      完成此步骤后,`gateway` 的 Helm values 应如下所示

      yaml
      gateway:
        readinessProbe:
          httpGet:
            path: /
        service:
          annotations:
            networking.istio.io/exportTo: admin
          nameOverride: mimir-nginx
        ingress:
          enabled: true
          nameOverride: mimir-nginx
          hosts:
            - host: mimir.example.com
              paths:
                - path: /
                  pathType: Prefix
          tls:
            - secretName: mimir-gateway-tls
              hosts:
                - mimir.example.com
        enabledNonEnterprise: true
        replicas: 10
    5. 根据下表迁移其余 values

      已弃用字段新字段备注
      nginx.affinitygateway.affinity之前 `affinity` 是字符串。现在应为 YAML 对象。
      nginx.annotationsgateway.annotations
      nginx.autoscalinggateway.autoscaling
      nginx.basicAuthgateway.nginx.basicAuth嵌套在 `proxy.nginx` 下。
      nginx.containerSecurityContextgateway.containerSecurityContext
      nginx.deploymentStrategygateway.strategy从 `deploymentStrategy` 重命名为 `strategy`。
      nginx.enabledgateway.enabled
      nginx.extraArgsgateway.extraArgs
      nginx.extraContainersgateway.extraContainers
      nginx.extraEnvFromgateway.extraEnvFrom
      nginx.extraEnvgateway.env从 `extraEnv` 重命名为 `env`。
      nginx.extraVolumeMountsgateway.extraVolumeMounts
      nginx.extraVolumesgateway.extraVolumes
      nginx.imagegateway.nginx.image嵌套在 `proxy.nginx` 下。
      nginx.ingressgateway.ingress
      nginx.nginxConfiggateway.nginx.config从 `nginxConfig` 重命名为 `config`,并嵌套在 `proxy.nginx` 下。
      nginx.nodeSelectorgateway.nodeSelector
      nginx.podAnnotationsgateway.podAnnotations
      nginx.podDisruptionBudgetgateway.podDisruptionBudget
      nginx.podLabelsgateway.podLabels
      nginx.podSecurityContextgateway.securityContext从 `podSecurityContext` 重命名为 `securityContext`。
      nginx.priorityClassNamegateway.priorityClassName
      nginx.readinessProbegateway.readinessProbe
      nginx.replicasgateway.replicas
      nginx.resourcesgateway.resources
      nginx.routegateway.route
      nginx.servicegateway.service
      nginx.terminationGracePeriodSecondsgateway.terminationGracePeriodSeconds
      nginx.tolerationsgateway.tolerations
      nginx.topologySpreadConstraintsgateway.topologySpreadConstraints
      nginx.verboseLogginggateway.nginx.verboseLogging嵌套在 `proxy.nginx` 下。
    6. 使用迁移后的 values 文件 `custom.yaml` 升级 Helm Release。迁移完成。

      bash
      helm upgrade $RELEASE grafana/mimir-distributed -f custom.yaml

示例

以下示例展示了从 NGINX 设置迁移到 gateway 设置后,您的 Helm values 文件会发生怎样的变化。

yaml
nginx:
  enabled: true
  replicas: 4

  deploymentStrategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 10%

  affinity: |
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
      - labelSelector:
          matchExpressions:
            - key: noisyNeighbour
              operator: In
              values:
                - 'true'
        topologyKey: 'kubernetes.io/hostname'

  extraEnv:
    - name: SPECIAL_TYPE_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_TYPE

  basicAuth:
    enabled: true
    username: user
    password: pass

  image:
    tag: 1.25-alpine

  nginxConfig:
    logFormat: |-
      main '$remote_addr - $remote_user [$time_local]  $status '
      '"$request" $body_bytes_sent "$http_referer" '
      '"$http_user_agent" "$http_x_forwarded_for"';

  podSecurityContext:
    readOnlyRootFilesystem: true

  ingress:
    enabled: true
    hosts:
      - host: mimir.example.com
        paths:
          - path: /
            pathType: Prefix
    tls:
      - secretName: mimir-gateway-tls
        hosts:
          - mimir.example.com

迁移完成后的 Helm values 文件

yaml
nginx:
  enabled: false

gateway:
  enabledNonEnterprise: true
  replicas: 4

  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 10%

  affinity:
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
              - key: noisyNeighbour
                operator: In
                values:
                  - "true"
          topologyKey: "kubernetes.io/hostname"

  env:
    - name: SPECIAL_TYPE_KEY
      valueFrom:
        configMapKeyRef:
          name: special-config
          key: SPECIAL_TYPE

  nginx:
    basicAuth:
      enabled: true
      username: user
      password: pass

    image:
      tag: 1.25-alpine

    nginxConfig:
      logFormat: |-
        main '$remote_addr - $remote_user [$time_local]  $status '
        '"$request" $body_bytes_sent "$http_referer" '
        '"$http_user_agent" "$http_x_forwarded_for"';

  securityContext:
    readOnlyRootFilesystem: true

  ingress:
    enabled: true
    nameOverride: mimir-nginx
    hosts:
      - host: mimir.example.com
        paths:
          - path: /
            pathType: Prefix
    tls:
      - secretName: mimir-gateway-tls
        hosts:
          - mimir.example.com