如何使用--set用Prometheus图表设置值?

时间:2018-01-30 14:21:49

标签: json yaml prometheus kubernetes-helm

例如,设置alertmanager.ingress.annotations以添加两个项目,这两种方法都不起作用:

$ helm install stable/prometheus \
  --set alertmanager.ingress.enabled=true \
  --set "alertmanager.ingress.annotations={alb.ingress.kubernetes.io/scheme: internet-facing, alb.ingress.kubernetes.io/tags: Environment=dev,Team=test}"

Error: YAML parse error on prometheus/templates/alertmanager-ingress.yaml: error unmarshaling JSON: json: cannot unmarshal array into Go struct field .annotations of type map[string]string
$ helm install stable/prometheus \
  --set alertmanager.ingress.enabled=true \
  --set "alertmanager.ingress.annotations={'alb.ingress.kubernetes.io/scheme': 'internet-facing', 'alb.ingress.kubernetes.io/tags': 'Environment=dev,Team=test'}"

Error: YAML parse error on prometheus/templates/alertmanager-ingress.yaml: error unmarshaling JSON: json: cannot unmarshal array into Go struct field .annotations of type map[string]string

那么如何使用呢?

1 个答案:

答案 0 :(得分:10)

您希望实现以下目标(从values.yaml掌舵图中prometheus切割):

alertmanager:
  ingress:
    ## If true, alertmanager Ingress will be created
    ##
    enabled: true

    ## alertmanager Ingress annotations
    ##
    annotations: {
      alb.ingress.kubernetes.io/scheme: internet-facing, 
      alb.ingress.kubernetes.io/tags: 'Environment=dev,Team=test'
    }

根据helm documentation,结构:

alertmanager:
  ingress:
    annotations:
      alb.ingress.kubernetes.io/scheme: internet-facing

--set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/scheme"=internet-facing

如果您想再添加一个注释,它将是另外一个--set语句:

--set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/tags"="Environment=dev\,Team=test"

还有一件事,name: "value1,value2"--set name=value1\,value2,因此Environment=dev,Team=test"Environment=dev\,Team=test"

最终的helm命令是:

helm install stable/prometheus --set alertmanager.ingress.enabled=true --set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/scheme"=internet-facing --set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/tags"="Environment=dev\,Team=test"

P.S。上面的命令失败,因为您还需要为alertmanager指定域名。 正确的是:

helm install stable/prometheus --set alertmanager.ingress.enabled=true --set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/scheme"=internet-facing --set alertmanager.ingress.annotations."alb\.ingress\.kubernetes\.io/tags"="Environment=dev\,Team=test" --set alertmanager.ingress.hosts[0]=alertmanager.domain.com