You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Helm中Probes的定义及Kubernetes探针配置标准方式咨询

Helm 中的 Probes 定义与配置方式

什么是 Helm 里的 Probes?

首先明确:Helm 本身并没有独立的 "Probes" 概念——它只是对 Kubernetes 原生探针(livenessProbe、readinessProbe、startupProbe)的模板化封装。Helm Charts 本质是将 Kubernetes 资源配置通过模板语法动态生成,所以这里的 Probes 就是指在 Chart 模板中渲染出来的 Kubernetes 探针配置,用于检测容器的健康状态。

能不能在 Helm Charts 中配置探针?当然可以,而且有标准实现方式

Helm 提供的标准方式是通过 values.yaml 暴露探针的可配置参数,再在资源模板(比如 Deployment、StatefulSet)中引用这些参数来生成对应的 Kubernetes 探针字段。

具体实现示例

  1. 在 values.yaml 中定义探针配置
    可以给探针设置默认值,同时允许用户按需覆盖:
# values.yaml
service:
  probes:
    liveness:
      enabled: true
      httpGet:
        path: /healthz
        port: 8080
      initialDelaySeconds: 10
      periodSeconds: 5
    readiness:
      enabled: true
      httpGet:
        path: /readyz
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 3
  1. 在 Deployment 模板中渲染探针
    在 templates/deployment.yaml 里,通过 Helm 模板语法引用上述配置:
# templates/deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Release.Name }}-app
spec:
  replicas: {{ .Values.replicaCount }}
  template:
    spec:
      containers:
      - name: {{ .Chart.Name }}
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        ports:
        - containerPort: {{ .Values.service.port }}
        {{- if .Values.service.probes.liveness.enabled }}
        livenessProbe:
          httpGet:
            path: {{ .Values.service.probes.liveness.httpGet.path }}
            port: {{ .Values.service.probes.liveness.httpGet.port }}
          initialDelaySeconds: {{ .Values.service.probes.liveness.initialDelaySeconds }}
          periodSeconds: {{ .Values.service.probes.liveness.periodSeconds }}
        {{- end }}
        {{- if .Values.service.probes.readiness.enabled }}
        readinessProbe:
          httpGet:
            path: {{ .Values.service.probes.readiness.httpGet.path }}
            port: {{ .Values.service.probes.readiness.httpGet.port }}
          initialDelaySeconds: {{ .Values.service.probes.readiness.initialDelaySeconds }}
          periodSeconds: {{ .Values.service.probes.readiness.periodSeconds }}
        {{- end }}

额外说明

  • 不同的 Helm Chart 可能会有细节差异(比如有的会把探针配置放在 image.probes 下,或者支持 TCP、Exec 类型的探针),但核心逻辑都是一致的:通过 values.yaml 暴露可配置项,模板动态生成 K8s 探针字段。
  • 如果需要自定义探针类型(比如 Exec 命令式探针),只需要在 values.yaml 中补充对应的配置字段,再在模板中渲染即可,完全遵循 Kubernetes 的探针规范。

内容的提问来源于stack exchange,提问作者TigersEye120

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 17:40:58