【问题标题】:How do I set helm values (not files) in ArgoCD Application spec如何在 ArgoCD 应用程序规范中设置 helm 值(不是文件)
【发布时间】:2023-01-24 07:49:00
【问题描述】:

为此,我查看了 ArgoCD docs,但不知何故我似乎找不到答案。我有一个这样的应用程序规范:

apiVersion: argoproj.io/v1alpha1                                                                                                                                                                                                                                                          
kind: Application                                                                                                                                                                                                                                                                         
metadata:                                                                                                                                                                                                                                                                                 
  name: myapp                                                                                                                                                                                                                                                                            
  namespace: argocd                                                                                                                                                                                                                                                                       
spec:                                                                                                                                                                                                                                                                                     
  destination:                                                                                                                                                                                                                                                                            
    namespace: default                                                                                                                                                                                                                                                                    
    server: https://kubernetes.default.svc                                                                                                                                                                                                                                                
  project: default                                                                                                                                                                                                                                                                        
  source:                                                                                                                                                                                                                                                                                 
    helm:                                                                                                                                                                                                                                                                                 
      valueFiles:                                                                                                                                                                                                                                                                         
      - my-values.yaml                                                                                                                                                                                                                                                     
    path: .                                                                                                                                                                                                                                        
    repoURL: ssh://git@blah.git                                                                                                                                                                                                                        
    targetRevision: HEAD

但是,我还需要指定一个特定的 helm 值(就像您在 helm 命令中使用 --set 所做的那样。我在 ArgoCD 网络用户界面中看到它有一个位置价值观,但我已经尝试了我能想到的所有条目组合(somekey=somevalue,somekey:somevalue,somekey,somevalue)。我也试过直接编辑清单,但我仍然遇到类似的错误。 错误是以error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type map[string]interface {}结尾的一长串废话

通过 Web UI 或清单文件设置单个值的正确语法是什么?

【问题讨论】:

    标签: kubernetes-helm argocd


    【解决方案1】:

    你会通过spec.source.helm.parameters使用parameters

    就像是:

    apiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: my-app
      namespace: argocd
    spec:
      project: my-project
      source:
        repoURL: https://charts.my-company.com
        targetRevision: "1234"
        chart: my-chart
        helm:
          parameters:
            - name: my.helm.key
              value: some-val
      destination:
        name: k8s-dev
        namespace: my-ns
    

    来自 Argo Docs 的示例 - https://argo-cd.readthedocs.io/en/stable/user-guide/helm/#build-environment

    【讨论】:

    • 谢谢你。你碰巧知道上面截图中的“值”框是什么意思吗?
    • Values 是您可以传入的内联值,而 valuesFiles 是图表发布时位于图表旁边的 yml 值文件。
    • 那么值与参数有何不同呢?
    • values 的优先级低于 parameters。参数模仿 helm 命令中的 --set 选项,其中 values 类似于另一个 valuesFile
    • 好的谢谢。所以它只是您通常放入值文件中的内容,但是是内联的。出于某种原因,当我阅读您的最后一条评论时没有注册,我很抱歉。事实上,我最近还需要设置从外部存储库中获取值文件,这有助于我更多地理解这一点。我关注了this guide,您可以在其中从外部值文件中获取内容并将它们用作values的内容。再次感谢。
    【解决方案2】:

    要覆盖值中的几个任意参数,您确实可以使用 parameters: 作为 Helm 的 --set 选项的等价物或 fileParameters: 而不是 --set-file

    ...
        helm:
          # Extra parameters to set (same as setting through values.yaml, but these take precedence)
          parameters:
          - name: "nginx-ingress.controller.service.annotations.external-dns\.alpha\.kubernetes\.io/hostname"
            value: mydomain.example.com
          - name: "ingress.annotations.kubernetes\.io/tls-acme"
            value: "true"
            forceString: true # ensures that value is treated as a string
    
          # Use the contents of files as parameters (uses Helm's --set-file)
          fileParameters:
          - name: config
            path: files/config.json
    

    但是要回答您最初的问题,对于 GUI 中的“值”选项,您可以在清单中传递文字 YAML 块,例如:

        helm:
          # Helm values files for overriding values in the helm chart
          # The path is relative to the spec.source.path directory defined above
          valueFiles:
          - values-prod.yaml
    
          # Values file as block file
          values: |
            ingress:
              enabled: true
              path: /
              hosts:
                - mydomain.example.com
              annotations:
                kubernetes.io/ingress.class: nginx
                kubernetes.io/tls-acme: "true"
              labels: {}
    

    查看ArgoCD sample application了解更多详情。

    【讨论】:

      猜你喜欢
      • 2022-09-28
      • 1970-01-01
      • 2022-07-08
      • 2021-10-08
      • 1970-01-01
      • 1970-01-01
      • 2016-02-07
      • 2019-06-30
      • 1970-01-01
      相关资源
      最近更新 更多