{"id":1146,"date":"2020-12-30T19:47:02","date_gmt":"2020-12-30T11:47:02","guid":{"rendered":"http:\/\/blog.axqd.net\/?p=1146"},"modified":"2021-01-05T17:31:17","modified_gmt":"2021-01-05T09:31:17","slug":"base-template-in-helm","status":"publish","type":"post","link":"https:\/\/blog.axqd.net\/?p=1146","title":{"rendered":"Base Template in Helm"},"content":{"rendered":"\n<p>\u6709\u65f6\u6211\u4eec\u9700\u8981\u4f7f\u7528Base Template\u6765\u540c\u65f6\u751f\u6210\u4e24\u4e2a\u7a0d\u5fae\u6709\u70b9\u5dee\u522b\u7684manifest\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u53ea\u9700\u8981\u66f4\u6539Map\u91cc\u9762\u7684\u5185\u5bb9\uff0c\u4e00\u79cd\u5f88\u5bb9\u6613\u7684\u65b9\u5f0f\u662f\u76f4\u63a5\u5408\u5e76\u751f\u6210\u597d\u7684YAML\u3002\u4f46\u5bf9\u4e8e<code>Containers<\/code>\u4ee5\u53ca<code>Volumes<\/code>\u8fd9\u79cd\u6570\u7ec4\u7c7b\u578b\uff0c\u5408\u5e76YAML\u5c31\u4e0d\u662f\u5f88\u5bb9\u6613\u4e86\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\u4e00\u79cd\u65b9\u5f0f\uff0c\u662f\u751f\u6210\u672c\u5730\u4fee\u6539\u7684<code>.Values<\/code>\uff0c\u5177\u4f53\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p><code>templates\/_util.tpl<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{{- \/*\nchart.util.merge will merge a YAML value file with context,\nuse it to generate another YAML file and output the result.\nThis takes an array of three values:\n- the top context\n- the name of the value overrides\n- the name of the target template\n*\/ -}}\n{{- define \"chart.util.merge\" -}}\n{{- $top := first . -}}\n{{- $overrides := fromYaml (include (index . 1) $top) | default (dict ) -}}\n{{- include (index . 2) (merge $overrides $top) -}}\n{{- end -}}<\/code><\/pre>\n\n\n\n<p><code>templates\/_parent.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{{\/*\nParent Base Template\n*\/}}\n{{- define \"chart.parent.tpl\" -}}\nCurrent Value: {{ .Values.test.key.value }}\n{{- end -}}\n{{- define \"chart.parent\" -}}\n{{- include \"chart.util.merge\" (append . \"chart.parent.tpl\") -}}\n{{- end -}}<\/code><\/pre>\n\n\n\n<p><code>templates\/child1.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{{- include \"chart.parent\" (list . \"chart.parent.child1\") -}}\n{{- define \"chart.parent.child1\" -}}\nValues:\n  test:\n    key:\n      value: child1\n{{- end -}}<\/code><\/pre>\n\n\n\n<p><code>templates\/child2.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{{- include \"chart.parent\" (list . \"chart.parent.child2\") -}}\n{{- define \"chart.parent.child2\" -}}\nValues:\n  test:\n    key:\n      value: child2\n{{- end -}}<\/code><\/pre>\n\n\n\n<p><code>values.yaml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>test:\n  key: {}\n    # This value is provided by child1.yaml or child2.yaml\n    #value: parent<\/code><\/pre>\n\n\n\n<p>\u6700\u540e\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>$ helm template test test\n<\/strong>---\n# Source: test\/templates\/child1.yaml\nCurrent Value: child1\n---\n# Source: test\/templates\/child2.yaml\nCurrent Value: child2<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6709\u65f6\u6211\u4eec\u9700\u8981\u4f7f\u7528Base Template\u6765\u540c\u65f6\u751f\u6210\u4e24\u4e2a\u7a0d\u5fae\u6709\u70b9\u5dee\u522b\u7684manifest\u6587\u4ef6\u3002 \u5982\u679c\u4f60\u53ea\u9700\u8981\u66f4\u6539 &hellip; <a href=\"https:\/\/blog.axqd.net\/?p=1146\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u201cBase Template in Helm\u201d<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[207,206],"class_list":["post-1146","post","type-post","status-publish","format-standard","hentry","category-tech","tag-helm","tag-kubernetes"],"_links":{"self":[{"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/posts\/1146","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1146"}],"version-history":[{"count":2,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/posts\/1146\/revisions"}],"predecessor-version":[{"id":1148,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=\/wp\/v2\/posts\/1146\/revisions\/1148"}],"wp:attachment":[{"href":"https:\/\/blog.axqd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1146"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1146"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.axqd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1146"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}