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

Kubernetes Deployment多行注解格式异常排查与解决

解决Kubernetes Deployment多行YAML注解格式无效问题

为Kubernetes Deployment添加多行YAML格式的自定义注解(对应有解析控制器)时,曾多次触发格式无效异常,排查过程及解决方案如下:

  • 最初配置中,autoscale.mars.salesforce.com/metricObjects注解用|标识多行内容,因缩进问题报错
  • 尝试用>替代|,问题依然存在
  • 将注解值包裹引号后虽通过Kubernetes校验,但内容会被转为单行,导致控制器反序列化到结构体失败

最终定位问题根源:注解的多行内容缩进混用了空格与制表符,仅使用空格缩进的格式可被正常解析。

正确配置示例:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    autoscale.mars.salesforce.com/minReplica : "1"
    autoscale.mars.salesforce.com/maxReplica : "5"
    autoscale.mars.salesforce.com/metricObjects : |
      - type: Object
        object:
          metric:
              name: requests-per-second
          describedObject:
              apiVersion: networking.k8s.io/v1
              kind: Ingress
              name: main-route
          target:
              type: Value
              value: 20
        metricQuery : 
          aggregatorWindow : '5m'
          aggregatorFunction : 'sum' 
  labels:
    app: hello-node
  name: hello-node
  namespace: test
spec:

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 13:12:40