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

如何在Helm中正确配置健康与存活探针?转换后探针报错排查

解决Helm Chart中探针配置引发的503错误

问题定位与修正要点

你的Helm部署配置存在几个关键问题,直接导致探针返回503错误:

1. LivenessProbe缩进语法错误

转换后的配置中,livenessProbe下的httpGet缩进异常,多了多余空格,导致YAML结构解析失败,kubelet无法正确识别探针规则,这是核心问题。

2. Pod Metadata存在无效乱码

template.metadata.labels里有一行无效内容ano 5.4 mychart/templates/deployment.yaml,需删除该行以保证Pod标签配置合法。

3. 遗漏原配置的优雅终止参数

原Deployment中的terminationGracePeriodSeconds: 30未在Helm配置中保留,需补全以维持一致的服务终止逻辑。

4. 资源配置需与原定义匹配

转换后的资源配置依赖Values.yaml,需确保该文件中的resources字段和原配置完全一致,避免因资源不足导致服务启动失败触发探针错误:

resources:
  limits:
    cpu: 10m
    memory: 30Mi
  requests:
    cpu: 10m
    memory: 30Mi

5. 探针端口配置优化(可选)

将探针的port值改为端口名称http(与ports字段定义的名称对应),替代硬编码的8000,提升配置可维护性。

修正后的完整Helm deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mychart.fullname" . }}
  labels:
    {{- include "mychart.labels" . | nindent 4 }}
spec:
  {{- if not .Values.autoscaling.enabled }}
  replicas: {{ .Values.replicaCount }}
  {{- end }}
  selector:
    matchLabels:
      {{- include "mychart.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      {{- with .Values.podAnnotations }}
      annotations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "mychart.selectorLabels" . | nindent 8 }}
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "mychart.serviceAccountName" . }}
      securityContext:
        {{- toYaml .Values.podSecurityContext | nindent 8 }}
      terminationGracePeriodSeconds: 30
      containers:
        - name: {{ .Chart.Name }}
          securityContext:
            {{- toYaml .Values.securityContext | nindent 12 }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            - name: http
              containerPort: 8000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /healthz
              port: http
          readinessProbe:
            httpGet:
              path: /readyz
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}

验证步骤

  1. 执行helm upgrade --install <release-name> ./mychart重新部署
  2. 用kubectl get pods查看Pod状态,等待进入Running状态
  3. 用kubectl describe pod <pod-name>检查探针事件,确认无503错误提示

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 14:10:37