Nat*_*ger 9 kubernetes kubernetes-helm
所以我试图建立一个掌舵图.
在我的模板文件中,我有一个文件,如:
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map
data:
{{ Do something here to load up a set of files | indent 2 }}
Run Code Online (Sandbox Code Playgroud)
我的图表中有另一个目录:configmaps
其中有一组json文件,它们本身将包含模板化变量:
a.json
b.json
c.json
Run Code Online (Sandbox Code Playgroud)
最后,我想在我的图表中确定我可以参考:
volumes:
- name: config-a
configMap:
name: config-map
items:
- key: a.json
path: a.json
Run Code Online (Sandbox Code Playgroud)
几个星期前我有同样的问题,直接向容器添加文件和模板.
查找示例语法:
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-configmap-{{ .Release.Name }}
namespace: {{ .Release.Namespace }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
data:
nginx_conf: {{ tpl (.Files.Get "files/nginx.conf") . | quote }}
ssl_conf: {{ tpl (.Files.Get "files/ssl.conf") . | quote }}
dhparam_pem: {{ .Files.Get "files/dhparam.pem" | quote }}
fastcgi_conf: {{ .Files.Get "files/fastcgi.conf" | quote }}
mime_types: {{ .Files.Get "files/mime.types" | quote }}
proxy_params_conf: {{ .Files.Get "files/proxy_params.conf" | quote }}
Run Code Online (Sandbox Code Playgroud)
第二步是从部署中引用它:
volumes:
- name: {{ $.Release.Name }}-configmap-volume
configMap:
name:nginx-configmap-{{ $.Release.Name }}
items:
- key: dhparam_pem
path: dhparam.pem
- key: fastcgi_conf
path: fastcgi.conf
- key: mime_types
path: mime.types
- key: nginx_conf
path: nginx.conf
- key: proxy_params_conf
path: proxy_params.conf
- key: ssl_conf
path: ssl.conf
Run Code Online (Sandbox Code Playgroud)
这是现在的实际情况.在这里您可以找到两种类型的导入:
请不要忘记阅读官方文档:https: //github.com/helm/helm/blob/master/docs/chart_template_guide/accessing_files.md
祝好运!
我假设 a.json、b.json、c.json 等是一个已定义的列表,并且您知道所有内容(除了您想要通过模板变量设置为值的位之外)。我还假设您只想向用户公开文件的部分内容,而不是让用户配置整个文件内容。(但是,如果我假设错误并且您确实想让用户设置整个文件内容,那么 @hypnoglow 遵循 datadog 图表的建议对我来说似乎是一个很好的建议。)如果是这样,我建议最简单的方法要做的是:
apiVersion: v1
kind: ConfigMap
metadata:
name: config-map
data:
a.json:
# content of a.json in here, including any templated stuff with {{ }}
b.json:
# content of b.json in here, including any templated stuff with {{ }}
c.json:
# content of c.json in here, including any templated stuff with {{ }}
Run Code Online (Sandbox Code Playgroud)
我猜您想安装到同一目录。使用不同的配置映射对于清洁度来说是很诱人的,但这对于安装到同一目录来说会是一个问题。能够使用 .Files.Glob 独立加载文件以便能够引用文件而不必将整个内容放入 configmap 中也很好,但我不认为你可以做到这一点并仍然使用模板变量但是,您可以使用 Files.Get 将文件内容作为字符串读取,并将其传递到 tpl 中以将其通过模板引擎,如 @Oleg Mykolaichenko 在https://stackoverflow.com/中建议的那样a/52009992/9705485。我建议每个人都投票支持他的答案,因为这是更好的解决方案。我只是将我的答案留在这里,因为它解释了为什么他的建议如此好,并且有些人可能更喜欢不太抽象的方法。
| 归档时间: |
|
| 查看次数: |
4308 次 |
| 最近记录: |