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
相关产品推荐
相关产品推荐

