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

Google Cloud负载均衡器未应用BackendConfig配置的健康检查

问题:BackendConfig配置的健康检查参数未生效

我部署了一个Deployment,Pod容器未配置readinessProbe,计划通过BackendConfig来配置健康检查。

对应的Service配置如下:

---
apiVersion: v1
kind: Service
metadata:
  name: my-app-service
  namespace: my-namespace
  annotations:
    cloud.google.com/neg: '{"ingress": true}'
    cloud.google.com/backend-config: '{"default": "my-app-backendconfig"}'
spec:
  type: NodePort  
  externalTrafficPolicy: Local  
  ports:
  - name: flower-nodeport-port
    port: 80
    targetPort: 5555
    protocol: TCP
  selector:
    app: my-app

用于创建健康检查的BackendConfig配置如下:

apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
  name: my-app-backendconfig
  namespace: my-namespace
  labels:
    app: my-app
spec:
  healthCheck:
    checkIntervalSec: 20
    timeoutSec: 1
    healthyThreshold: 1
    unhealthyThreshold: 5
    type: TCP        

问题:Google Cloud并未按照上述配置应用健康检查,“不健康阈值”“超时时间”等参数未被生效,请问哪里配置错误?


问题原因及解决方法

1. 未指定健康检查的目标端口

你的BackendConfig的healthCheck部分没有明确指定port字段,GCP默认会使用Service的port(80)作为健康检查的目标端口,但你的Pod容器实际监听的是targetPort:5555,端口不匹配导致健康检查无法按预期配置,GCP会自动 fallback 到默认参数。

修改BackendConfig,在healthCheck下添加port: 5555:

spec:
  healthCheck:
    checkIntervalSec: 20
    timeoutSec: 1
    healthyThreshold: 1
    unhealthyThreshold: 5
    type: TCP
    port: 5555  # 指定Pod的实际监听端口

2. 确认参数符合GCP限制

GCP对TCP健康检查的参数有硬性要求,你的当前配置虽然符合,但需要确保:

  • timeoutSec必须小于checkIntervalSec(1<20符合要求)
  • unhealthyThreshold必须大于等于healthyThreshold(5>=1符合要求)

如果参数不符合限制,GCP会直接忽略自定义配置,使用默认值。

3. 确保配置生效

修改BackendConfig后,需要删除并重新创建关联的Service,确保GCP重新加载健康检查配置:

kubectl delete service my-app-service -n my-namespace
kubectl apply -f your-service-config.yaml

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 06:35:28