如何在helmfile中为变量赋值?

问题描述 投票:0回答:1

如何在helmfile中分配变量?

context: example.com                # kube-context (--kube-context)

releases:
  # Published chart example
  - name: controller-pod-nginx                  # Name of this release
    namespace: ingress-nginx                    # Target namespace
    chart: stable/nginx-ingress                 # The chart being installed to create this release, referenced by `repository/chart` syntax
    set:                                        # Values (--set)
      - name: rbac.create
        value: true
      - name: controller.service.annotations
        value: 'service.beta.kubernetes.io/aws-load-balancer-ssl-ports:https'

Error message

 helmfile -f deploy_cp_ns_ingress-nginx.yaml sync
exec: helm repo add roboll http://roboll.io/charts --kube-context example.com
"roboll" has been added to your repositories
exec: helm repo update --kube-context example.com
Hang tight while we grab the latest from your chart repositories...
...Skip local chart repository
...Successfully got an update from the "roboll" chart repository
...Successfully got an update from the "stable" chart repository
Update Complete. ⎈ Happy Helming!⎈
exec: helm upgrade --install controller-pod-nginx stable/nginx-ingress --namespace ingress-nginx --set rbac.create=true,controller.service.annotations=service.beta.kubernetes.io/aws-load-balancer-ssl-ports:https --kube-context example.com
Error: UPGRADE FAILED: YAML parse error on nginx-ingress/templates/controller-service.yaml: error unmarshaling JSON: json: cannot unmarshal string into Go struct field .annotations of type map[string]string
err: exit status 1

如果我使用纯舵安装,没有问题:

helm install stable/nginx-ingress --set rbac.create=true --set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-backend-protocol"=http --namespace=ingress-nginx

这没有问题。我需要添加许多注释。

kubernetes kubernetes-helm kubernetes-ingress helmfile
1个回答
0
投票

通常,如果在set中使用helmfile.yaml参数,则可以这样指定:

set:
  - name: 'controller.service.annotations.service\.beta\.kubernetes\.io/aws-load-balancer-ssl-ports'
    value: 'https'

注意反斜杠用于逃避键service.beta.kubernetes.io/aws-load-balancer-ssl-ports中的点。 YAML选择器中的点具有特殊含义,因此我们需要将它们转义。

但是,由于这非常不直观,我建议使用内联值。然后它看起来像这样:

values:
  - rbac:
      create: true
    controller:
      service:
        annotations:
          "service.beta.kubernetes.io/aws-load-balancer-ssl-ports": true

注意最后,使用helm总是很棘手,因为没有关于如何使用values.yaml的通用规范 - 也就是说,结构可以是任意的。我假设它是一个map,因为我们使用的大多数图表都将annotations定义为一个简单的地图(而不是列表)。

这是我们为replica.annotations.iam\.amazonaws\.com/role定义注释的示例

https://github.com/cloudposse/geodesic/blob/0.12.0/rootfs/conf/kops/helmfile.yaml#L104-L105

以下是我们如何为内联值执行此操作:(我们切换到使用此处无处不在)https://github.com/cloudposse/helmfiles/blob/0.2.4/helmfile.d/0300.chartmuseum.yaml#L52-L55

© www.soinside.com 2019 - 2024. All rights reserved.