使用 Bitnami Helm Chart 在 Kubernetes 上部署 Grafana:从快速安装到生产级配置实战指南

原创2026-10-03 19:22:281,376 阅读
文章标签:云原生容器编排

使用 Bitnami Helm Chart 在 Kubernetes 上部署 Grafana:从快速安装到生产级配置实战指南

Grafana 是业界广泛使用的开源指标分析与可视化套件,支持时序数据的查询、告警与多数据源接入。本文以当前仓库中 bitnami/grafana 的 Helm Chart 为绝对主体,系统讲解如何在 Kubernetes 集群上通过 Helm 一键部署 Grafana,并深入剖析其架构设计、全部可配置参数、自定义配置挂载、LDAP 集成、Prometheus 指标采集、Grafana Image Renderer 插件安装、高可用与升级迁移等实战内容。读完本文,你将掌握基于 Bitnami Grafana Chart 从零部署到生产加固的完整方案,并能结合仓库源码理解每个参数的底层作用。

Chart 概览与 Helm 快速安装

本 Chart 名为 grafana,当前仓库版本为 12.1.9,对应 Grafana 应用版本 12.1.1(见 Chart.yaml),Chart 通过 common 库 Chart 提供标签、亲和性、资源预设等通用能力(依赖定义同样位于 Chart.yaml)。它会在 Kubernetes 集群上以 Helm 包管理器引导一套完整的 Grafana 部署,核心工作负载由 application.yaml 模板渲染。

TL;DR

使用默认配置部署的最简命令:

helm install my-release oci://registry-1.docker.io/bitnamicharts/grafana

前置条件

  • Kubernetes 1.23+
  • Helm 3.8.0+
  • 底层基础设施支持 PV Provisioner(用于持久化)
  • 若需要 Deployment 水平扩容,需要 ReadWriteMany 卷支持

安装 Chart

以 release 名 my-release 安装:

helm install my-release oci://REGISTRY_NAME/REPOSITORY_NAME/grafana

Note:需要将 REGISTRY_NAME 和 REPOSITORY_NAME 占位符替换为实际的 Helm Chart 仓库地址。例如使用 Bitnami 官方仓库时:REGISTRY_NAME=registry-1.docker.io、REPOSITORY_NAME=bitnamicharts。

上述命令会以默认配置将 Grafana 部署到集群中。Parameters 一节列出了所有可在安装时自定义的参数。

Tip:使用 helm list 可查看所有已部署的 release。

指定参数的两种安装方式

通过 --set key=value[,key=value] 参数方式:

helm install my-release \
  --set admin.user=admin-user oci://REGISTRY_NAME/REPOSITORY_NAME/grafana

以上命令将 Grafana 管理员用户名设置为 admin-user。

通过 -f values.yaml 文件方式:

helm install my-release -f values.yaml oci://REGISTRY_NAME/REPOSITORY_NAME/grafana

Tip:仓库中的默认 values.yaml 即为最权威的配置参考,所有参数均带注释说明。

Note:Chart 部署完成后,无法通过 Helm 修改应用访问凭据(如用户名、密码)。如需变更,需删除 Chart 使用的持久卷(PV)后重新部署,或使用应用内置的管理工具。

Chart 架构:Bitnami Grafana Chart 与 Grafana Operator Chart 的差异

在 Bitnami 目录中同时提供 bitnami/grafana 与 bitnami/grafana-operator 两个 Chart,分别满足不同场景。

bitnami/grafana Chart(本文主体)部署单套 Grafana 实例,使用 Kubernetes Deployment 对象(连同 Service、PVC、ConfigMap 等),或使用 StatefulSet 对象(配合 headless service、volumeClaimTemplate 与 ConfigMap)。执行 helm install 后集群中部署的对象结构如下:

                    +--------------+             +-----+
                    |              |             |     |
 Service & Ingress  |    Grafana   +<------------+ PVC |
<-------------------+              |             |     |
                    |  Deployment/ |             +-----+
                    |  StatefulSet |
                    +-----------+--+
                                ^                +------------+
                                |                |            |
                                +----------------+ Configmaps |
                                                 |   Secrets  |
                                                 |            |
                                                 +------------+

其生命周期由 Helm 管理;在 Grafana 容器层面,以下操作被自动化:持久化管理、基于环境变量的配置、插件初始化。Chart 还支持通过 ConfigMap 部署 Dashboard 与 DataSource。Deployment 不需要具有特殊 RBAC 权限的 ServiceAccount,因此更适合权限受限的 Kubernetes 集群。

bitnami/grafana-operator Chart 则部署一个 Grafana Operator,通过 Deployment 运行:

+--------------------+
|                    |      +---------------+
|  Grafana Operator  |      |               |
|                    |      |     RBAC      |
|    Deployment      |      |   Privileges  |
|                    |      |               |
+-------+------------+      +-------+-------+
        ^                           |
        |   +-----------------+     |
        +---+ Service Account +<----+
            +-----------------+

Operator 会向 Kubernetes API 扩展以下对象:Grafana、GrafanaDashboards 和 GrafanaDataSources。此后用户可直接部署这些对象,由 Operator 负责创建运行 Grafana 实例所需的全部 Deployment、ConfigMap 和 Service。其生命周期通过 kubectl 管理 Grafana/GrafanaDashboards/GrafanaDataSource 对象。部署一个 Grafana 对象后的对象结构如下:

+--------------------+
|                    |      +---------------+
|  Grafana Operator  |      |               |
|                    |      |     RBAC      |
|    Deployment      |      |   Privileges  |
|                    |      |               |
+--+----+------------+      +-------+-------+
   |    ^                           |
   |    |   +-----------------+     |
   |    +---+ Service Account +<----+
   |        +-----------------+
   |
   |
   |
   |
   |                                                   Grafana
   |                     +---------------------------------------------------------------------------+
   |                     |                                                                           |
   |                     |                          +--------------+             +-----+             |
   |                     |                          |              |             |     |             |
   +-------------------->+       Service & Ingress  |    Grafana   +<------------+ PVC |             |
                         |      <-------------------+              |             |     |             |
                         |                          |  Deployment  |             +-----+             |
                         |                          |              |                                 |
                         |                          +-----------+--+                                 |
                         |                                      ^                +------------+      |
                         |                                      |                |            |      |
                         |                                      +----------------+ Configmaps |      |
                         |                                                       |   Secrets  |      |
                         |                                                       |            |      |
                         +---------------------------------------------------------------------------+

Operator 方案可以更轻松地部署多个 Grafana 实例(对比 bitnami/grafana Chart)。由于 Operator 自动部署 Grafana 实例,其 Pod 需要具备创建和销毁多个 Kubernetes 对象的 ServiceAccount 权限,这在具有严格基于角色的访问控制策略的集群中可能存在问题。

从 application.yaml 的源码可印证上述架构:模板通过 eq (lower .Values.grafana.kind) "deployment" 三目判断渲染 Deployment 还是 StatefulSet,StatefulSet 分支会额外声明 serviceName(<fullname>-headless)与 podManagementPolicy,并在持久化启用时通过 volumeClaimTemplates 声明 data 卷(accessMode、storage 大小均来自 persistence.* 参数)。

配置与安装细节

资源请求与限制(Resource requests and limits)

Bitnami Charts 允许通过 resources 值为 Chart 内的所有容器设置资源请求与限制(详见参数表)。对于生产工作负载,设置 requests 至关重要,并应适配你的具体使用场景。

为简化此过程,Chart 提供了 resourcesPreset 值,可依据不同预设自动生成 resources 段(预设定义可参考 bitnami/common 库的 _resources.tpl,取值为 none、nano、micro、small、medium、large、xlarge、2xlarge)。但在生产环境不建议使用 resourcesPreset,因为它可能无法完全适配你的需求。

从 application.yaml 的容器渲染逻辑可以看到优先级关系:当 grafana.resources 被显式设置时使用自定义值,否则才回退到 common.resources.preset 预设;volumePermissions init 容器同样遵循这一优先级。仓库默认 values.yaml 中 grafana.resourcesPreset 默认值为 nano,推荐生产环境直接显式配置 grafana.resources,例如:

grafana:
  resources:
    requests:
      cpu: 2
      memory: 512Mi
    limits:
      cpu: 3
      memory: 1024Mi

更新管理员凭据

本 Chart 在升级时,会复用 Chart 之前渲染的 Secret 或 admin.existingSecret 指定的 Secret。要更新凭据,可使用以下任一方式:

  • 执行 helm upgrade 并在 admin.password 中指定新密码
  • 执行 helm upgrade 并在 admin.existingSecret 中指定新 Secret

从 application.yaml 可看到密码注入的实现细节:当 usePasswordFiles 为 true(默认)时,通过 GF_SECURITY_ADMIN_PASSWORD_FILE 环境变量指向 Secret 挂载的密码文件路径;否则通过 GF_SECURITY_ADMIN_PASSWORD 环境变量以 secretKeyRef 方式引用 Secret。两种模式对应的 Secret 由 secret.yaml 模板渲染,admin.existingSecretPasswordKey 默认值为 password。

Rolling VS Immutable tags(滚动标签 vs 不可变标签)

强烈建议在生产环境使用不可变标签(immutable tags)。这可以确保当同一标签被更新为不同镜像时,你的部署不会自动变化。

当主容器发布新版本、出现重大变更或存在关键漏洞时,Bitnami 会发布新版本 Chart 并更新其容器镜像。

Prometheus 指标集成

通过设置 metrics.enabled 为 true,本 Chart 可与 Prometheus 集成。这会在 Service 上暴露 Grafana 原生的 Prometheus 端点(/metrics 端口 3000),并自动添加必要的注解以便被 Prometheus 抓取。默认注解在 values.yaml 的 metrics.service.annotations 中定义:prometheus.io/scrape: "true"、prometheus.io/port: "3000"、prometheus.io/path: "/metrics"。

Prometheus 前提条件

要使集成生效,集群中需要有可用的 Prometheus 或 Prometheus Operator。可安装 Bitnami Prometheus Helm Chart 或 Bitnami Kube Prometheus Helm Chart 快速获得可用的 Prometheus。

与 Prometheus Operator 集成

Chart 可以部署 ServiceMonitor 对象以集成 Prometheus Operator。设置 metrics.serviceMonitor.enabled=true 即可。请确保集群中已安装 Prometheus Operator 的 CustomResourceDefinitions,否则会报如下错误:

no matches for kind "ServiceMonitor" in version "monitoring.coreos.com/v1"

可安装 Bitnami Kube Prometheus Helm Chart 以获得所需 CRD 与 Prometheus Operator。

从 servicemonitor.yaml 源码可见 ServiceMonitor 的实现要点:仅当 metrics.enabled 与 metrics.serviceMonitor.enabled 同时为真时才渲染;endpoints 指向 http 端口、/metrics 路径,并支持 interval、scrapeTimeout、honorLabels、metricRelabelings、relabelings 等字段;selector 通过 app.kubernetes.io/component: grafana 标签匹配目标 Service;namespaceSelector.matchNames 固定为 release 所在命名空间。若需要自定义告警规则,可同时启用 metrics.prometheusRule.enabled 并通过 metrics.prometheusRule.rules 定义 PrometheusRule,模板由 prometheusrules.yaml 渲染,示例规则如下:

metrics:
  prometheusRule:
    enabled: true
    rules:
      - alert: Grafana-Down
        annotations:
          message: 'Grafana instance is down'
          summary: Grafana instance is down
        expr: absent(up{job="grafana"} == 1)
        labels:
          severity: warning
          service: grafana
        for: 5m

使用自定义配置(挂载自定义 grafana.ini)

Grafana 支持多个配置文件。在 Kubernetes 中可以通过 ConfigMap 或 Secret 挂载文件。例如,要挂载自定义的 grafana.ini 或 custom.ini 文件,可创建如下 ConfigMap:

apiVersion: v1
kind: ConfigMap
metadata:
  name: myconfig
data:
  grafana.ini: |-
    # Raw text of the file

然后将 ConfigMap 名称传给对应参数:config.useGrafanaIniFile=true 和 config.grafanaIniConfigMap=myconfig。

从 application.yaml 的卷与挂载逻辑可见:当 config.useGrafanaIniFile 为真时,grafana-ini 卷会挂载到 /opt/bitnami/grafana/conf/grafana.ini(subPath 为 grafana.ini),卷来源优先取 config.grafanaIniConfigMap(ConfigMap),否则取 config.grafanaIniSecret(Secret),两者均未指定时不渲染卷。

此外,Chart 默认通过 configmap.yaml 生成一份名为 <fullname>-envvars 的 ConfigMap,将 Grafana 的关键路径以环境变量注入,例如 GF_PATHS_CONFIG=/opt/bitnami/grafana/conf/grafana.ini、GF_PATHS_DATA=/opt/bitnami/grafana/data、GF_PATHS_LOGS=/opt/bitnami/grafana/logs、GF_PATHS_PROVISIONING=/opt/bitnami/grafana/conf/provisioning、GF_PATHS_PLUGINS=/opt/bitnami/grafana/data/plugins,以及 GF_INSTALL_PLUGINS、GF_AUTH_LDAP_* 等。理解这些路径环境变量,有助于你定位自定义挂载的目标目录。

在部署时提供 Dashboard 与 DataSource

要在部署时提供 Dashboard,Grafana 需要 dashboards provider 和 dashboard 文件本身。启用后 Chart 会创建一个默认 provider,或者你也可以通过 ConfigMap 挂载自定义 provider,但注意 dashboard 文件夹路径必须为 /opt/bitnami/grafana/dashboards。

操作要点(注意 datasource 与 dashboard 的创建方式不同):

  1. 创建 Dashboard 之前需要先有 DataSource。DataSource 必须通过 Secret 挂载(因为其中可能包含敏感信息),而不是 ConfigMap。
  2. 每个 Dashboard 需要单独一个 ConfigMap,内含定义该 Dashboard 的 json 文件,并把 ConfigMap 名称填入 dashboardsConfigMaps 参数数组。

例如,按如下方式创建 Dashboard ConfigMap 与 DataSource Secret:

kubectl create secret generic datasource-secret --from-file=datasource-secret.yaml
kubectl create configmap my-dashboard-1 --from-file=my-dashboard-1.json
kubectl create configmap my-dashboard-2 --from-file=my-dashboard-2.json

Note:以上命令假设你已把 Dashboard 导出为 JSON 文件 my-dashboard-1.json 和 my-dashboard-2.json,并已创建 datasource 配置文件 datasource-secret.yaml(其格式参考 Grafana 官方 provisioning 文档中的 datasource 示例配置)。

创建完成后,使用以下参数部署带 2 个自定义 Dashboard 的 Grafana:

dashboardsProvider.enabled=true
datasources.secretName=datasource-secret
dashboardsConfigMaps[0].configMapName=my-dashboard-1
dashboardsConfigMaps[0].fileName=my-dashboard-1.json
dashboardsConfigMaps[1].configMapName=my-dashboard-2
dashboardsConfigMaps[1].fileName=my-dashboard-2.json

源码实现印证:默认 provider 由 dashboard-provider.yaml 渲染(dashboardsProvider.enabled=true 且未指定 configMapName 时),其 options.path 固定为 /opt/bitnami/grafana/dashboards,默认 10 秒扫描一次 dashboard 变更(updateIntervalSeconds: 10),并支持通过取消注释 foldersFromFilesStructure: true 按文件结构自动创建文件夹。在 application.yaml 中,dashboardsConfigMaps 数组中的每个 ConfigMap 会以 subPath: <fileName> 的方式挂载到 /opt/bitnami/grafana/dashboards/<fileName>(或带 folderName 的子目录);DataSource Secret 挂载到 /opt/bitnami/grafana/conf.default/provisioning/datasources。

DataSource 还有第二种方式:直接通过 datasources.secretDefinition 在 values 中内联定义内容(仅当 datasources.secretName 为空时生效)。此时 datasources-secret.yaml 会生成一个 <fullname>-datasources Secret,将内容以 datasources.yaml 键、base64 编码存放。例如:

datasources:
  secretDefinition:
    apiVersion: 1
    datasources:
    - name: Prometheus
      type: prometheus
      url: http://prometheus-prometheus-server
      access: proxy
      isDefault: true

LDAP 配置

要启用 LDAP 认证,需要提供一个包含 Grafana LDAP 配置文件(ldap.toml)的 ConfigMap。例如:

configmap.yaml:

apiVersion: v1
kind: ConfigMap
metadata:
  name: ldap-config
data:
  ldap.toml: |-
      [[servers]]
      # Ldap server host (specify multiple hosts space separated)
      host = "ldap"
      # Default port is 389 or 636 if use_ssl = true
      port = 389
      # Set to true if ldap server supports TLS
      use_ssl = false
      # Set to true if connect ldap server with STARTTLS pattern (create connection in insecure, then upgrade to secure connection with TLS)
      start_tls = false
      # set to true if you want to skip ssl cert validation
      ssl_skip_verify = false
      # set to the path to your root CA certificate or leave unset to use system defaults
      # root_ca_cert = "/path/to/certificate.crt"
      # Authentication against LDAP servers requiring client certificates
      # client_cert = "/path/to/client.crt"
      # client_key = "/path/to/client.key"

      # Search user bind dn
      bind_dn = "cn=admin,dc=example,dc=org"
      # Search user bind password
      # If the password contains # or ; you have to wrap it with triple quotes. Ex """#password;"""
      bind_password = 'admin'

      # User search filter, for example "(cn=%s)" or "(sAMAccountName=%s)" or "(uid=%s)"
      # Allow login from email or username, example "(|(sAMAccountName=%s)(userPrincipalName=%s))"
      search_filter = "(uid=%s)"

      # An array of base dns to search through
      search_base_dns = ["ou=People,dc=support,dc=example,dc=org"]

      # group_search_filter = "(&(objectClass=posixGroup)(memberUid=%s))"
      # group_search_filter_user_attribute = "distinguishedName"
      # group_search_base_dns = ["ou=groups,dc=grafana,dc=org"]

      # Specify names of the ldap attributes your ldap uses
      [servers.attributes]
      name = "givenName"
      surname = "sn"
      username = "cn"
      member_of = "memberOf"
      email =  "email"

将 ConfigMap 创建到集群中,然后使用现有 ConfigMap 部署 Grafana Helm Chart,并传入以下参数:

ldap.enabled=true
ldap.configMapName=ldap-config
ldap.allowSignUp=true

源码层面的补充说明(见 ldap-secret.yaml 与 application.yaml):

  • LDAP 配置文件来源有三种优先级:ldap.configMapName(ConfigMap)→ ldap.secretName(Secret)→ 未指定时由 Chart 自动生成 <fullname>-ldap-conf Secret(内容来自 ldap.configuration 或由 ldap.uri、ldap.binddn、ldap.bindpw、ldap.basedn、ldap.searchFilter/ldap.searchAttribute 等字段渲染出的 grafana.ldap.config)。
  • 无论来源如何,文件都会挂载到 /opt/bitnami/grafana/conf.default/ldap.toml(subPath ldap.toml),与 configmap.yaml 中注入的 GF_AUTH_LDAP_CONFIG_FILE=/opt/bitnami/grafana/conf/ldap.toml 保持一致。
  • 若需要 TLS 连接(LDAPS 或 STARTTLS),配置 ldap.tls.enabled=true、ldap.tls.certificatesSecret 指向含证书的 Secret,证书会挂载到 ldap.tls.certificatesMountPath(默认 /opt/bitnami/grafana/conf/ldap/),并通过 ldap.tls.CAFilename、ldap.tls.certFilename、ldap.tls.certKeyFilename 指定与 Secret 键名匹配的文件名。

安装 Grafana Image Renderer Plugin

要安装 Grafana Image Renderer 插件,让图像渲染由独立服务承担、节省 Grafana Pod 内存,请按以下步骤操作:

  1. 使用下面 K8s 清单创建 Grafana Image Renderer 的 Deployment 与 Service:
# deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: grafana-image-renderer
  namespace: default
  labels:
    app.kubernetes.io/name: grafana-image-renderer
    app.kubernetes.io/instance: grafana-image-renderer
    app.kubernetes.io/component: image-renderer-plugin
    app.kubernetes.io/part-of: grafana
spec:
  replicas: 1
  strategy:
    type: RollingUpdate
  selector:
    matchLabels:
      app.kubernetes.io/name: grafana-image-renderer
      app.kubernetes.io/instance: grafana-image-renderer
      app.kubernetes.io/component: image-renderer-plugin
  template:
    metadata:
      labels:
        app.kubernetes.io/name: grafana-image-renderer
        app.kubernetes.io/instance: grafana-image-renderer
        app.kubernetes.io/component: image-renderer-plugin
        app.kubernetes.io/part-of: grafana
    spec:
      securityContext:
        fsGroup: 1001
        runAsNonRoot: true
        runAsUser: 1001
      containers:
        - name: grafana-image-renderer
          image: docker.io/bitnami/grafana-image-renderer:3
          securityContext:
            runAsUser: 1001
          env:
            - name: HTTP_HOST
              value: "::"
            - name: HTTP_PORT
              value: "8080"
          ports:
            - name: http
              containerPort: 8080
              protocol: TCP
# service.yaml
apiVersion: v1
kind: Service
metadata:
  name: grafana-image-renderer
  namespace: default
  labels:
    app.kubernetes.io/name: grafana-image-renderer
    app.kubernetes.io/instance: grafana-image-renderer
    app.kubernetes.io/component: image-renderer-plugin
    app.kubernetes.io/part-of: grafana
spec:
  type: ClusterIP
  sessionAffinity: None
  ports:
    - port: 8080
      targetPort: http
      protocol: TCP
      name: http
  selector:
    app.kubernetes.io/name: grafana-image-renderer
    app.kubernetes.io/instance: grafana-image-renderer
    app.kubernetes.io/component: image-renderer-plugin
  1. 升级你的 Chart release,在 values.yaml 中添加以下配置块:
imageRenderer:
  enabled: true
  serverURL: "http://grafana-image-renderer.default.svc.cluster.local:8080/render"
  callbackURL: "http://grafana.default.svc.cluster.local:3000/"

Note:以上步骤假设安装在 default 命名空间。如果在其他命名空间安装,请相应调整清单以及 serverURL 和 callbackURL 的值。

从 configmap.yaml 源码可见,imageRenderer.enabled=true 时 Chart 会向 Grafana 注入 GF_RENDERING_SERVER_URL 与 GF_RENDERING_CALLBACK_URL 两个环境变量,其值分别取自 imageRenderer.serverURL 与 imageRenderer.callbackURL,从而让 Grafana 主实例把渲染请求转发到远程渲染服务。

支持高可用(HA)

要支持 HA,Grafana 需要一个外部数据库来存储 Dashboard、用户及其他持久化数据。配置外部数据库时,需要提供包含 Grafana 配置文件中 database 段的配置文件(可通过上文"自定义配置"方式挂载 grafana.ini 实现)。

同时建议使用 StatefulSet 而非 Deployment,以利用 volumeClaimTemplates:

grafana:
  kind: StatefulSet
  replicaCount: 3
  podManagementPolicy: Parallel

注意:StatefulSet 模式下 persistence.existingClaim 会被忽略(该限制同时记录在参数表与 values.yaml 中)。

HA 模式下由于默认 persistence.accessMode 为 ReadWriteOnce,多副本需要自行评估存储方案;同时 application.yaml 在 StatefulSet 分支会渲染 headless Service(<fullname>-headless,模板见 service-headless.yaml)以支持 Pod 间稳定网络身份。

设置 Pod 的亲和性

Chart 允许通过 affinity 参数设置自定义亲和性(Pod affinity/anti-affinity 的详细语义参见 Kubernetes 官方文档)。

作为替代方案,可以使用 bitnami/common 提供的预设配置:设置 podAffinityPreset、podAntiAffinityPreset 或 nodeAffinityPreset 参数。取值可为 soft 或 hard。从 application.yaml 可见其实现:当显式设置了 grafana.affinity 时直接渲染自定义值;否则依次通过 common.affinities.pods 渲染 podAffinity、podAntiAffinity(默认 soft),并通过 common.affinities.nodes 渲染 nodeAffinity(取自 nodeAffinityPreset.type/key/values)。

备份与恢复

要在 Kubernetes 上备份和恢复 Helm Chart 部署,需要备份源部署的持久卷,并使用 Velero 将其挂载到新部署中。Velero 是 Kubernetes 的备份/恢复工具,其完整操作说明可参考 Velero 官方文档及 Bitnami 的 Velero 备份恢复部署指南。

持久化

Bitnami Grafana 镜像将 Grafana 数据和配置存储在容器内的 /opt/bitnami/grafana/data 路径。

Chart 使用 Persistent Volume Claims(PVC)来跨部署保留数据。该方案已确认可在 GCE、AWS 和 minikube 上正常工作。PVC 相关配置见"Persistence 参数"表,或通过 persistence.enabled=false 禁用持久化。

从 application.yaml 可看到持久化的完整实现路径:

  • Deployment 模式:data 卷在 persistence.enabled=true 时引用 PVC(claimName 默认取 persistence.existingClaim,未指定则用 fullname 生成的 PVC),否则回退为 emptyDir。PVC 本身由 pvc.yaml 渲染。
  • StatefulSet 模式:volumeClaimTemplates 声明 data 卷模板,accessMode 默认 ReadWriteOnce、storage 默认 10Gi,并支持 persistence.annotations 与 persistence.selector。
  • 若底层存储不允许非 root 用户写入,可启用 volumePermissions.enabled=true,此时会注入一个 init 容器,将 /bitnami/grafana 目录属主递归改为 runAsUser:fsGroup(见 application.yaml 中 volume-permissions init 容器定义)。

参数详解

以下为 Chart 全量可配置参数。每个参数均可在安装时通过 --set key=value 指定,或集中写入 values YAML 文件。表格中的"Value"列为 values.yaml 的默认值。

Global 参数(全局)

名称 描述 值
global.imageRegistry 全局 Docker 镜像仓库 ""
global.imagePullSecrets 全局 Docker 仓库 Secret 名称数组 []
global.defaultStorageClass 全局默认持久卷 StorageClass ""
global.storageClass 已弃用:请使用 global.defaultStorageClass ""
global.security.allowInsecureImages 允许跳过镜像校验 false
global.compatibility.openshift.adaptSecurityContext 适配 OpenShift restricted-v2 SCC:移除 runAsUser、runAsGroup 与 fsGroup,交由平台使用默认 ID。可选值:auto(检测到 OpenShift 时应用)、force(始终应用)、disabled(不应用) auto

Common 参数(通用)

名称 描述 值
kubeVersion 强制目标 Kubernetes 版本(未设置时使用 Helm capabilities) ""
extraDeploy 随 release 额外部署的对象数组 []
nameOverride 部分覆盖 grafana.fullname 模板(保留 release 名) ""
fullnameOverride 完全覆盖 grafana.fullname 模板 ""
namespaceOverride 完全覆盖 common.names.namespace ""
clusterDomain 默认 Kubernetes 集群域名 cluster.local
commonLabels 添加到所有部署对象的标签 {}
commonAnnotations 添加到所有部署对象的注解 {}
usePasswordFiles 以文件方式挂载凭据,而非使用环境变量 true

Grafana 参数

名称 描述 值
image.registry Grafana 镜像仓库 REGISTRY_NAME
image.repository Grafana 镜像仓库路径 REPOSITORY_NAME/grafana
image.digest Grafana 镜像 digest(格式 sha256:aa...)。若设置将覆盖 tag ""
image.pullPolicy Grafana 镜像拉取策略 IfNotPresent
image.pullSecrets Grafana 镜像拉取 Secret []
admin.user Grafana 管理员用户名 admin
admin.password 管理员密码。未提供时将生成随机密码 ""
admin.existingSecret 包含管理员密码的现有 Secret 名称 ""
admin.existingSecretPasswordKey 现有 Secret 中的密码键 password
smtp.enabled 启用 SMTP 配置 false
smtp.user SMTP 用户 user
smtp.password SMTP 密码 password
smtp.host SMTP 服务器自定义主机 ""
smtp.fromAddress 发件地址 ""
smtp.fromName 发件人名称 ""
smtp.skipVerify 启用跳过证书校验 false
smtp.existingSecret 包含 SMTP 凭据(user 与 password)的现有 Secret 名称 ""
smtp.existingSecretUserKey 现有 Secret 中的用户键 user
smtp.existingSecretPasswordKey 现有 Secret 中的密码键 password
plugins 部署时安装的 Grafana 插件(逗号分隔) ""
ldap.enabled 为 Grafana 启用 LDAP false
ldap.allowSignUp 允许通过 LDAP 注册 Grafana 用户 false
ldap.configuration 指定 ldap.toml 配置文件内容 ""
ldap.configMapName 含 ldap.toml 配置文件的 ConfigMap 名称 ""
ldap.secretName 含 ldap.toml 配置文件的 Secret 名称 ""
ldap.uri 服务器 URI,如 ldap://ldap_server:389 ""
ldap.binddn 用于在 LDAP 服务器中搜索的账户 DN ""
ldap.bindpw binddn 账户密码 ""
ldap.basedn binddn 账户搜索用户的基础 DN 路径 ""
ldap.searchAttribute 匹配用户名的字段(uid、samAccountName、cn 等)。设置了 ldap.searchFilter 时忽略 uid
ldap.searchFilter 用户搜索过滤器,如 "(cn=%s)" 或 "(sAMAccountName=%s)" ""
ldap.extraConfiguration 额外 LDAP 配置 ""
ldap.tls.enabled 启用 TLS 配置 false
ldap.tls.startTls 使用 STARTTLS 而非 LDAPS false
ldap.tls.skipVerify 跳过任何 SSL 校验(主机名或证书) false
ldap.tls.certificatesMountPath LDAP 证书挂载路径 /opt/bitnami/grafana/conf/ldap/
ldap.tls.certificatesSecret 含 LDAP 证书的 Secret ""
ldap.tls.CAFilename CA 证书文件名,需与 certificatesSecret 中的 CA 键名匹配 ""
ldap.tls.certFilename 客户端证书文件名,需与 certificatesSecret 中的证书键名匹配 ""
ldap.tls.certKeyFilename 客户端私钥文件名,需与 certificatesSecret 中的证书键名匹配 ""
imageRenderer.enabled 启用远程渲染服务渲染 PNG 图片 false
imageRenderer.serverURL 远程渲染服务 URL ""
imageRenderer.callbackURL 回调服务 URL ""
config.useGrafanaIniFile 允许加载 grafana.ini 文件 false
config.grafanaIniConfigMap 含 grafana.ini 文件的 ConfigMap 名称 ""
config.grafanaIniSecret 含 grafana.ini 文件的 Secret 名称 ""
dashboardsProvider.enabled 启用 Grafana dashboard provider false
dashboardsProvider.configMapName 含自定义 dashboard provider 的 ConfigMap 名称 ""
dashboardsConfigMaps 含 dashboard 文件的一系列 ConfigMap 名称数组 []
datasources.secretName 含自定义 datasource 文件的外部管理 Secret 名称 ""
datasources.secretDefinition 定义自定义 datasource 文件的 Secret 内容。仅当 datasources.secretName 为空时使用 {}
notifiers.configMapName 含 Grafana notifiers 配置的 ConfigMap 名称 ""
alerting.configMapName 含 Grafana alerting 配置的 ConfigMap 名称 ""

smtp.skipVerify 在 values.yaml 中的默认值写法为字符串 "false",启用时 Chart 会向容器注入 GF_SMTP_ENABLED、GF_SMTP_HOST、GF_SMTP_FROM_ADDRESS、GF_SMTP_FROM_NAME、GF_SMTP_SKIP_VERIFY 等环境变量(见 application.yaml),SMTP 凭据同样受 usePasswordFiles 开关影响(GF_SMTP_USER_FILE/GF_SMTP_PASSWORD_FILE 或 secretKeyRef 两种模式)。

Grafana Deployment 参数

名称 描述 值
grafana.replicaCount Grafana 节点数 1
grafana.kind 使用 Deployment 或 StatefulSet Deployment
grafana.podManagementPolicy StatefulSet Pod 管理策略 Parallel
grafana.updateStrategy.type Grafana 安装更新策略 RollingUpdate
grafana.automountServiceAccountToken 在 Pod 中挂载 Service Account token false
grafana.hostAliases 添加 Deployment host aliases []
grafana.schedulerName 备用调度器 ""
grafana.terminationGracePeriodSeconds Grafana Pod 优雅终止等待时间(秒) ""
grafana.priorityClassName 优先级类名 ""
grafana.podLabels Grafana Pod 额外标签 {}
grafana.podAnnotations Grafana Pod 注解 {}
grafana.podAffinityPreset Pod 亲和性预设。设置 affinity 时忽略。可选:soft 或 hard ""
grafana.podAntiAffinityPreset Pod 反亲和性预设。设置 affinity 时忽略。可选:soft 或 hard soft
grafana.containerPorts.grafana Grafana 容器端口 3000
grafana.extraPorts Grafana Deployment 额外端口 []
grafana.nodeAffinityPreset.type 节点亲和性预设类型。设置 affinity 时忽略。可选:soft 或 hard ""
grafana.nodeAffinityPreset.key 节点标签键。设置 affinity 时忽略 ""
grafana.nodeAffinityPreset.values 节点标签值。设置 affinity 时忽略 []
grafana.affinity Pod 分配亲和性 {}
grafana.nodeSelector Pod 分配节点标签 {}
grafana.tolerations Pod 分配容忍度 []
grafana.topologySpreadConstraints 拓扑分布约束 []
grafana.podSecurityContext.enabled 为 Grafana Deployment 启用 securityContext true
grafana.podSecurityContext.fsGroupChangePolicy 设置文件系统组变更策略 Always
grafana.podSecurityContext.sysctls 通过 sysctl 接口设置内核参数 []
grafana.podSecurityContext.supplementalGroups 设置文件系统额外组 []
grafana.podSecurityContext.fsGroup 为卷配置权限的组 1001
grafana.containerSecurityContext.enabled 启用容器 Security Context true
grafana.containerSecurityContext.seLinuxOptions 在容器中设置 SELinux 选项 {}
grafana.containerSecurityContext.runAsUser 容器 Security Context runAsUser 1001
grafana.containerSecurityContext.runAsGroup 容器 Security Context runAsGroup 1001
grafana.containerSecurityContext.runAsNonRoot 容器 Security Context runAsNonRoot true
grafana.containerSecurityContext.privileged 容器 Security Context privileged false
grafana.containerSecurityContext.readOnlyRootFilesystem 容器 Security Context readOnlyRootFilesystem true
grafana.containerSecurityContext.allowPrivilegeEscalation 容器 Security Context allowPrivilegeEscalation false
grafana.containerSecurityContext.capabilities.drop 需丢弃的 capabilities 列表 ["ALL"]
grafana.containerSecurityContext.seccompProfile.type 容器 Security Context seccomp 配置 RuntimeDefault
grafana.resourcesPreset 按通用预设设置容器资源(可选:none、nano、micro、small、medium、large、xlarge、2xlarge)。设置 grafana.resources 时忽略(生产推荐显式配置 resources) nano
grafana.resources 设置容器资源请求与限制(生产工作负载必需) {}
grafana.livenessProbe.enabled 启用 livenessProbe true
grafana.livenessProbe.initialDelaySeconds livenessProbe 初始延迟秒数 120
grafana.livenessProbe.periodSeconds livenessProbe 周期秒数 10
grafana.livenessProbe.timeoutSeconds livenessProbe 超时秒数 5
grafana.livenessProbe.failureThreshold livenessProbe 失败阈值 6
grafana.livenessProbe.successThreshold livenessProbe 成功阈值 1
grafana.readinessProbe.enabled 启用 readinessProbe true
grafana.readinessProbe.path readinessProbe 路径 /api/health
grafana.readinessProbe.scheme readinessProbe 协议 HTTP
grafana.readinessProbe.initialDelaySeconds readinessProbe 初始延迟秒数 30
grafana.readinessProbe.periodSeconds readinessProbe 周期秒数 10
grafana.readinessProbe.timeoutSeconds readinessProbe 超时秒数 5
grafana.readinessProbe.failureThreshold readinessProbe 失败阈值 6
grafana.readinessProbe.successThreshold readinessProbe 成功阈值 1
grafana.startupProbe.enabled 启用 startupProbe false
grafana.startupProbe.path startupProbe 路径 /api/health
grafana.startupProbe.scheme startupProbe 协议 HTTP
grafana.startupProbe.initialDelaySeconds startupProbe 初始延迟秒数 30
grafana.startupProbe.periodSeconds startupProbe 周期秒数 10
grafana.startupProbe.timeoutSeconds startupProbe 超时秒数 5
grafana.startupProbe.failureThreshold startupProbe 失败阈值 6
grafana.startupProbe.successThreshold startupProbe 成功阈值 1
grafana.customLivenessProbe 覆盖默认 livenessProbe 的自定义探针 {}
grafana.customReadinessProbe 覆盖默认 readinessProbe 的自定义探针 {}
grafana.customStartupProbe 覆盖默认 startupProbe 的自定义探针 {}
grafana.lifecycleHooks 用于在容器启动前后自动化配置的 lifecycle hooks {}
grafana.sidecars 为 Grafana Pod 附加额外 sidecar 容器 []
grafana.initContainers 为 Grafana Pod 添加额外 init 容器 []
grafana.enableServiceLinks 是否将服务信息注入 Pod 环境变量 true
grafana.extraVolumes Grafana Pod 额外卷 []
grafana.extraVolumeMounts Grafana 容器额外卷挂载 []
grafana.extraEnvVarsCM 含 Grafana 节点额外环境变量的现有 ConfigMap 名称 ""
grafana.extraEnvVarsCMOptional ConfigMap 不存在时仍运行 Grafana 节点 false
grafana.extraEnvVarsSecret 含 Grafana 节点额外环境变量的现有 Secret 名称 ""
grafana.extraEnvVarsSecretOptional Secret 不存在时仍运行 Grafana 节点 false
grafana.extraEnvVars 配置 Grafana 的额外环境变量数组 []
grafana.extraConfigmaps 挂载额外 ConfigMap 以配置 Grafana 的数组 []
grafana.command 覆盖默认容器命令(使用自定义镜像时有用) []
grafana.args 覆盖默认容器参数(使用自定义镜像时有用) []
grafana.pdb.create 启用/禁用 PodDisruptionBudget 创建 true
grafana.pdb.minAvailable 保持调度的最小 Pod 数量/百分比 ""
grafana.pdb.maxUnavailable 允许不可用的最大 Pod 数量/百分比。若两者均为空,默认 1 ""

Persistence 参数(持久化)

名称 描述 值
persistence.enabled 启用持久化 true
persistence.annotations PVC 注解 {}
persistence.accessMode 持久卷访问模式 ReadWriteOnce
persistence.accessModes 持久卷访问模式(数组) []
persistence.storageClass PVC 使用的 StorageClass ""
persistence.existingClaim 复用已有 PVC 的名称。注意:grafana.kind 为 StatefulSet 时该设置被忽略 ""
persistence.size PV 大小 10Gi

RBAC 参数

名称 描述 值
serviceAccount.create 是否创建 ServiceAccount true
serviceAccount.name 使用的 ServiceAccount 名称。未设置且 create 为 true 时,按 fullname 模板生成 ""
serviceAccount.annotations 添加到 ServiceAccount 元数据的注解 {}
serviceAccount.automountServiceAccountToken 应用控制器 ServiceAccount 自动挂载 token false

流量暴露参数

名称 描述 值
service.type Kubernetes Service 类型 ClusterIP
service.clusterIP Grafana Service Cluster IP ""
service.ports.grafana Grafana Service 端口 3000
service.nodePorts.grafana LoadBalancer 与 NodePort Service 类型的 nodePort 值 ""
service.loadBalancerIP Service 类型为 LoadBalancer 时的 loadBalancerIP(可选,云厂商相关) ""
service.loadBalancerClass Service 类型为 LoadBalancer 时的 loadBalancerClass(可选,云厂商相关) ""
service.loadBalancerSourceRanges Service 类型为 LoadBalancer 时的 loadBalancerSourceRanges(可选,云厂商相关) []
service.annotations 提供任何可能需要的额外注解 {}
service.externalTrafficPolicy Grafana Service 外部流量策略 Cluster
service.extraPorts Grafana Service 暴露的额外端口 []
service.sessionAffinity Kubernetes Service 会话亲和性,可为 "None" 或 "ClientIP" None
service.sessionAffinityConfig sessionAffinity 的附加设置 {}
networkPolicy.enabled 是否创建 NetworkPolicy true
networkPolicy.allowExternal 不要求 server 标签即可连接 true
networkPolicy.allowExternalEgress 允许 Pod 访问任意端口与任意目的地 true
networkPolicy.addExternalClientAccess 允许带 client 标签(值为 "true")的 Pod 访问。networkPolicy.allowExternal 为 true 时忽略 true
networkPolicy.extraIngress 向 NetworkPolicy 添加额外 ingress 规则 []
networkPolicy.extraEgress 向 NetworkPolicy 添加额外 egress 规则 []
networkPolicy.ingressPodMatchLabels 匹配以允许其他 Pod 流量的标签。allowExternal 为 true 时忽略 {}
networkPolicy.ingressNSMatchLabels 匹配以允许其他命名空间流量的标签。allowExternal 为 true 时忽略 {}
networkPolicy.ingressNSPodMatchLabels 匹配以允许其他命名空间 Pod 流量的标签。allowExternal 为 true 时忽略 {}
ingress.enabled 设为 true 启用 ingress 记录生成 false
ingress.pathType Ingress 路径类型 ImplementationSpecific
ingress.apiVersion 覆盖 API 版本(未设置时自动检测) ""
ingress.hostname 启用 ingress 时创建的指向主机 grafana.local
ingress.path ingress 资源默认路径 /
ingress.annotations Ingress 资源额外注解。要启用证书自动生成,可在此放置 cert-manager 注解 {}
ingress.tls 为 ingress.hostname 定义的主机名启用 TLS 配置 false
ingress.extraHosts 此 ingress 记录需覆盖的额外主机名列表 []
ingress.extraPaths 主主机下需添加到 ingress 的额外任意路径 []
ingress.extraTls 此 ingress 记录需覆盖的额外主机名 TLS 配置 []
ingress.secrets 如果提供自己的证书,请使用此项将证书作为 Secret 添加 []
ingress.secrets 也可以在 Helm Chart 之外创建和管理证书 []
ingress.selfSigned 使用 Helm 生成的自签名证书为此 ingress 记录创建 TLS Secret false
ingress.ingressClassName 实现 Ingress 的 IngressClass(Kubernetes 1.18+) ""
ingress.extraRules 此 ingress 记录需覆盖的额外规则 []

Metrics 参数(指标)

名称 描述 值
metrics.enabled 启用 Prometheus 指标导出 false
metrics.service.annotations Prometheus 指标 Service 注解 {}
metrics.serviceMonitor.enabled 为 true 时创建 Prometheus Operator ServiceMonitor(同时要求 metrics.enabled=true) false
metrics.serviceMonitor.namespace Prometheus 所在命名空间 ""
metrics.serviceMonitor.interval 指标抓取间隔 ""
metrics.serviceMonitor.scrapeTimeout 抓取超时 ""
metrics.serviceMonitor.selector Prometheus 实例选择器标签 {}
metrics.serviceMonitor.relabelings 抓取前应用于样本的 RelabelConfigs []
metrics.serviceMonitor.metricRelabelings 采集前应用于样本的 MetricRelabelConfigs []
metrics.serviceMonitor.honorLabels 添加到抓取端点的 honorLabels false
metrics.serviceMonitor.labels ServiceMonitor 的额外自定义标签 {}
metrics.serviceMonitor.jobLabel 用作 prometheus job 名称的目标 Service 上的标签名 ""
metrics.prometheusRule.enabled 为 true 时创建 Prometheus Operator PrometheusRule(同时要求 metrics.enabled=true 且配置了 rules) false
metrics.prometheusRule.namespace PrometheusRule 资源命名空间(默认 release 命名空间) ""
metrics.prometheusRule.additionalLabels 使 PrometheusRule 可被 Prometheus 发现的额外标签 {}
metrics.prometheusRule.rules PrometheusRule 规则 []

Volume permissions init 容器参数

名称 描述 值
volumePermissions.enabled 启用修改 PV 挂载点属主/属组为 runAsUser:fsGroup 的 init 容器 false
volumePermissions.image.registry OS Shell + Utility 镜像仓库 REGISTRY_NAME
volumePermissions.image.repository OS Shell + Utility 镜像仓库路径 REPOSITORY_NAME/os-shell
volumePermissions.image.digest OS Shell + Utility 镜像 digest(格式 sha256:aa...)。设置后覆盖 tag ""
volumePermissions.image.pullPolicy OS Shell + Utility 镜像拉取策略 IfNotPresent
volumePermissions.image.pullSecrets OS Shell + Utility 镜像拉取 Secret []
volumePermissions.resourcesPreset 按通用预设设置容器资源(可选:none、nano、micro、small、medium、large、xlarge、2xlarge)。设置 resources 时忽略(生产推荐显式配置) nano
volumePermissions.resources 设置容器资源请求与限制 {}
volumePermissions.containerSecurityContext.seLinuxOptions 在 init 容器中设置 SELinux 选项 {}
volumePermissions.containerSecurityContext.runAsUser init 容器 Security Context runAsUser 0

volumePermissions.containerSecurityContext.runAsUser 可设为特殊值 auto,此时 init 容器会通过 id -u 与 id -G | cut -d" " -f2 自动确定用户与组并 chown 数据目录,特别适合使用动态用户 ID 的 OpenShift SCC 场景(该行为记录在 values.yaml 的注释中)。

Diagnostic Mode 参数(诊断模式)

名称 描述 值
diagnosticMode.enabled 启用诊断模式(所有探针禁用,命令被覆盖) false
diagnosticMode.command 覆盖部署中所有容器的命令 ["sleep"]
diagnosticMode.args 覆盖部署中所有容器的参数 ["infinity"]

升级指南

升级至 11.4.0

此版本为安全目的引入镜像校验。要禁用它,设置 global.security.allowInsecureImages 为 true。

升级至 11.0.0

此大版本仅将 Grafana 应用版本升级至 11.x,升级过程中预计无重大问题。

升级至 10.0.0

此大版本更改了以下安全默认值:

  • runAsGroup 从 0 改为 1001
  • readOnlyRootFilesystem 设为 true
  • resourcesPreset 从 none 改为测试套件可运行的最小值(注意:resourcesPreset 不适合生产,应使用适配自身场景的 resources)
  • global.compatibility.openshift.adaptSecurityContext 从 disabled 改为 auto

这可能破坏部署中使用的任何自定义项或 init 脚本。如果遇到这种情况,请将相关默认值改回之前的取值。

升级至 9.4.0

此版本停止在 Chart 中内置 Grafana Image Renderer。要使用该插件,请参考上文"安装 Grafana Image Renderer Plugin"一节。

升级至 8.0.0

此大版本仅将 Grafana 应用版本升级至 9.x,升级过程中预计无重大问题。

升级至 7.0.0

此大版本重命名了本 Chart 中的多个 value,并补充缺失功能,使该 Chart 与 Bitnami Charts 仓库中其余资产保持一致。

由于启用持久化时卷访问模式为 ReadWriteOnce,要升级部署需要改用 Recreate 策略或删除旧 Deployment:

kubectl delete deployment <deployment-name>
helm upgrade <release-name> oci://REGISTRY_NAME/REPOSITORY_NAME/grafana

升级至 4.1.0

此版本引入了 bitnami/common 库 Chart 作为依赖。请在执行任何升级前更新 Chart 依赖。

升级至 4.0.0

此大版本是 Helm v2 支持正式终止后,为使 Chart 适配 Helm v3 特性而应用的变更结果:

  • 旧版本 Chart 使用 apiVersion: v1(Helm 2 与 3 均可安装),此版本更新为 apiVersion: v2(仅 Helm 3 可安装)。
  • Chart.yaml 中的字段已按字母顺序统一排列,与其他 Bitnami Helm Charts 保持一致。

升级注意事项:

  • 从 Helm v3 安装的旧版本升级到本版本不会遇到问题。
  • 使用 Helm v2 升级到本版本不受支持。
  • 若旧版本由 Helm v2 安装、希望用 Helm v3 升级,请参考官方 Helm 文档中 v2 到 v3 迁移的使用场景说明。

升级至 3.0.0

Deployment 标签选择器创建后不可变,因此无法直接 "upgrade"。此版本更新了资源的 Deployment 标签选择器,加入组件名(component name),造成兼容性破坏。要从旧版本 "升级",需要手动卸载现有 Chart。此大版本即标志着这一变更。

Troubleshooting(故障排查)

关于 Bitnami Helm Charts 常见错误的处理方式,请参考 Bitnami 官方发布的 Helm Chart 故障排查指南(其中涵盖了常见升级错误、镜像拉取失败、持久卷与 Secret 复用等问题的一般性排查方法)。

License

Copyright © 2025 Broadcom. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

延伸阅读

如需继续深入本仓库,可重点阅读以下文件:

登录后查看全文
charts