gpt4 book ai didi

elasticsearch - 使用模板通过 Helm 定义子图表值

转载 作者:行者123 更新时间:2023-12-02 11:31:49 29 4
gpt4 key购买 nike

用例

“我想通过使用弹性官方掌 Helm chart 来部署 elasticsearch + kibana。我想创建一个名为 data-viz 的掌 Helm chart 表,并将这些图表作为依赖项。”

运行 helm install data-viz --set cluster=toto必须创建一个elasticsearch集群“toto”,以及一个配置了elasticsearchHosts的kibana = 托托。

问题

我在这里看到 https://github.com/helm/helm/blob/master/docs/chart_template_guide/subcharts_and_globals.md可以从主图表配置子图表 values.yml .但我想从主图表 values.yaml 模板化子图表 values.yml,这可能吗?

我在想一些简单的事情:

.
├── Chart.yaml
├── charts
│   ├── elasticsearch
│   │   ├── Chart.yaml
│   │   └── templates
│   │   └── values.yaml
│   ├── elasticsearch-7.4.0.tgz
│   └── kibana-7.4.0.tgz
├── requirements.lock
├── requirements.yaml
└── values.yaml

破解方案

创建 values.yaml 的小型 Python 脚本文件来自 sub-chart/values-template.yaml + 数据。

最佳答案

PR 6876 “feat(helm): 添加值模板以便使用 go-template 为图表及其依赖项自定义值”可能很有趣:

There have been many requests for a way to use templates for chart values.yaml (#2492, #2133, ...).
The main reason being that it's currently impossible to derive the values of the subcharts from templates.

However, having templates in values.yaml make them unparsable and create a "chicken or the egg" problem when rendering them.

This merge request creates an intuitive solution without such a problem: an optional values/ directory which templates are rendered using values.yaml, and then merge them with it.
Those values/ templates are only required for specific cases, work the same way as templates/ templates, and values.yaml will remain the main parsable source of value.

The rendering order has also been changed to allow those new values to enable or disable dependencies, and to avoid rendering values templates of disabled dependencies.

New possibilities:

Can now customize dependencies values, which was previously totally impossible


值/子图表.yaml
subchart:
fullnameOverride: subchart-{{ .Relese.Name }}
debug: {{ default "false" .Values.debug }}

Can derive dependencies conditions from values


图表文件
dependencies:
- name: subchart
condition: subchart.enabled
值/子图表.yaml
subchart:
{{- if eq .Values.environment "production" -}}
enabled: true
{{- else -}}
enabled: false
{{- end -}}

同样, PR 8580 “增加了通过 map.yaml 将值传递给子图表的支持”很有趣

This PR allows developers to declare a map.yaml file on their chart, which can be used to map values in values.yaml to derived values that are used in templating, including sub-charts (see #8576 for the long explanation).

This allows developers to write e.g.


apiVersion: v1
description: Chart with map and subcharts
name: chart-with-map
version: 0.0.1
dependencies:
- name: backend
version: 0.0.1
- name: frontend
version: 0.0.1
值.yaml
domain: example.com
map .yaml
backend:
uri: {{ printf "https://api.%s" .Values.domain }}

frontend:
uri: {{ printf "https://app.%s" .Values.domain }}

other_uri: {{ printf "https://blabla.%s" .Values.domain }}

thereby not having to expose backend: uri, frontend: uri in values.yaml (for the subchart), nor ask chart users to have to pass the same value in multiple keys for consistency (or use global names that lead to naming collisions).

I.e. it allows subcharts to be populated with derived (or maped) values without exposing these values to values.yaml (the public interface of the chart).



这正在实现/评估:
  • PR 8677 :“修复:限制 chartutil.Values 的使用以避免转换错误”
  • PR 8679 :“修复:不合并和导入禁用的依赖项中的值”
  • PR 8690 :“壮举:添加值模板以使用 go-template 自定义值”

  • 但是那个 will likely require HIP (Helm Improvement Proposal) .

    2021 年 2 月更新: PR 6876this comment 中确认需要一份正式提案。

    关于elasticsearch - 使用模板通过 Helm 定义子图表值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58320091/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com