{"id":1028,"date":"2021-08-20T12:34:28","date_gmt":"2021-08-20T04:34:28","guid":{"rendered":"https:\/\/www.chenqing.work\/?p=1028"},"modified":"2023-02-07T23:31:26","modified_gmt":"2023-02-07T15:31:26","slug":"helm-%e5%bf%ab%e9%80%9f%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/www.chenqing.work\/?p=1028","title":{"rendered":"Helm Chart \u5feb\u901f\u5165\u95e8"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"1280\" src=\"https:\/\/www.chenqing.work\/wp-content\/uploads\/2023\/02\/marina-maliutina-JbVcazzegdw-unsplash-1.jpg\" alt=\"\" class=\"wp-image-7875\"\/><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6982\u8ff0<\/h2>\n\n\n\n<p>helm chart \u662f\u4e00\u79cd\u63cf\u8ff0\u5982\u4f55\u90e8\u7f72\u5e94\u7528\u5230 kubernetes \u4e2d\u7684\u6587\u6863\u683c\u5f0f\u3002<\/p>\n\n\n\n<p>helm \u9879\u76ee\u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u5de5\u5177 helm \u6765\u8fdb\u884c\u90e8\u7f72\u5305\u7684\u7ba1\u7406\uff0c\u5e76\u4e14\u652f\u6301\u63a5\u5165 chart \u4ed3\u5e93\uff0c\u5982\u679c\u4f60\u7528\u8fc7 linux \u5404\u5927\u53d1\u884c\u7248\u7684\u6e90\uff0c\u6216\u8005 docker \u7684\u955c\u50cf\u4ed3\u5e93\uff0c\u76f8\u4fe1\u53ef\u4ee5\u8fc5\u901f Get \u5230\u8fd9\u79cd\u65b9\u6848\u7406\u5ff5\u3002\u76ee\u524d\u5b98\u65b9\u4e2d\u592e\u4ed3\u5e93\u4e3a <a href=\"https:\/\/artifacthub.io\/\" data-type=\"URL\" data-id=\"https:\/\/artifacthub.io\/\">artifacthub<\/a>\u3002<\/p>\n\n\n\n<p>\u4e0b\u8f7d\u4e00\u4e2a helm 3 \u6267\u884c\u7a0b\u5e8f\u5230\u672c\u5730\uff0c\u7136\u540e\u53ef\u4ee5\u901a\u8fc7\u6267\u884c <code>helm repo add &lt;repo-name&gt; &lt;repo-url&gt; <\/code>\u6765\u6dfb\u52a0 chart \u4ed3\u5e93\u3002<code>helm search repo &lt;repo-name&gt; <\/code>\u53ef\u4ee5\u6d4f\u89c8\u5f53\u524d\u4ed3\u5e93\u4e2d\u6709\u7684 chart\u3002<\/p>\n\n\n\n<p>\u4f7f\u7528 <code>helm create &lt;charts-name&gt;<\/code> \u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u521d\u59cb chart\uff0c\u6587\u4ef6\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># tree mychart\nmychart\n\u251c\u2500\u2500 charts\/ # \u5b50 chart\n\u251c\u2500\u2500 Chart.yaml # chart \u7684\u6982\u8981\u4fe1\u606f\n\u251c\u2500\u2500 templates # \u6a21\u677f\uff0c\u5bf9\u6807 k8s \u4e2d\u7684\u79cd\u79cd\u8d44\u6e90\u7c7b\u578b\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 deployment.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 _helpers.tpl\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 hpa.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 ingress.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 NOTES.txt\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 serviceaccount.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 service.yaml\n\u2502&nbsp;&nbsp; \u2514\u2500\u2500 tests\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u2514\u2500\u2500 test-connection.yaml\n\u2514\u2500\u2500 values.yaml # \u4e00\u4e9b\u9700\u8981\u4f20\u9012\u7ed9\u6a21\u677f\u7684\u503c\u88ab\u653e\u7f6e\u5728\u8fd9\u91cc<\/pre>\n\n\n\n<p>\u9664\u4e86 Chart.yaml\u3001values.yaml \u662f\u5fc5\u987b\u8981\u6709\u7684\uff0c\u5176\u4ed6\u90fd\u662f\u53ef\u9009\u7684\u3002\u5f53\u7136\u5728\u5b9e\u9645\u4f7f\u7528\u65f6\uff0c\u901a\u5e38\u9700\u8981 templates\/ \u91cc\u7684\u6a21\u677f\uff0c\u6bd4\u5982 deployment.yaml\u3001service.yaml\uff0c\u6a21\u677f\u4ece values.yaml \u4e2d\u83b7\u53d6\u503c\u6765\u6e32\u67d3\u5f97\u5230\u6700\u7ec8\u7684\u90e8\u7f72\u76f8\u5173\u8d44\u6e90\u63cf\u8ff0\u6587\u4ef6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Chart.yaml<\/h2>\n\n\n\n<p>Chart.yaml \u4e2d\u4e3b\u8981\u662f\u653e\u4e00\u4e9b\u6982\u8981\u4fe1\u606f\uff0c\u6bd4\u5982 chart \u7684\u540d\u79f0\u3001\u7248\u672c\u3001\u7ef4\u62a4\u8005\u3001\u4f9d\u8d56\uff08\u5373\u5b50 chart\uff09\u3002<\/p>\n\n\n\n<p><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">name: mychart<br>description: A Helm chart for Kubernetes<br>type: application # application or library<br>version: 0.1.0 # chart release version<br>appVersion: \"1.16.0\" # version of some application inside the chart, such as nginx. Just a message, not important<br>\u200b<br># optional<br>maintainers:<br>- email: &lt;&gt;<br>  name: &lt;&gt;<br>\u200b<br># optional<br>dependencies:<br>- name: &lt;&gt;<br>  version: &lt;&gt;<br>  repository: &lt;&gt; # optional<\/pre>\n\n\n\n<p>\u6ce8\u610f\u5728 Helm 3 \u4e2d\uff0c\u4e0d\u518d\u9700\u8981 requirements.yaml \u6765\u63cf\u8ff0 dependencies \u3002<\/p>\n\n\n\n<p>\u5728\u58f0\u660e\u4e86 dependencies \u7684 chart \u4e2d\u6267\u884c <code>helm dependency update<\/code> \u6216 <code>helm dependency build<\/code> \u5c06\u4f1a\u81ea\u52a8\u751f\u6210\u4e00\u4e2a Chart.lock \u6587\u4ef6\uff0c\u4e14\u5982\u679c\u8bbe\u7f6e\u4e86\u4f9d\u8d56\u9879\u7684 repository\uff0c\u4f1a\u5230\u4ed3\u5e93\u4e2d\u67e5\u627e\u5e76\u6253\u5305\u4e3a .tgz \u6587\u4ef6\u4e0b\u8f7d\u5230 charts\/ \u8def\u5f84\u4e0b\u3002<\/p>\n\n\n\n<p>\u5f53\u7136\uff0c\u4f60\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528 <code>helm pull &lt;chart-name&gt;<\/code>\u76f4\u63a5\u4ece\u4ed3\u5e93\u4e2d\u6293\u53d6\u5bf9\u5e94\u7684 chart \u5230 charts\/ \u4e0b\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">values.yaml<\/h2>\n\n\n\n<p>values.yaml \u4e2d\u653e\u7f6e\u4e00\u4e9b\u9700\u8981\u4f20\u9012\u7ed9\u6a21\u677f\u7684\u503c\uff0c\u5728\u6a21\u677f\u6587\u4ef6\u4e2d\u4f60\u5c06\u53ef\u4ee5\u901a\u8fc7 {{.Values.xxx.xxx}} \u6765\u8fdb\u884c\u5f15\u7528\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Default values for mychart.\n# This is a YAML-formatted file.\n# Declare variables to be passed into your templates.\nreplicaCount: 1\n\u200b\nimage:\n  repository: nginx\n  pullPolicy: IfNotPresent\n &nbsp;# Overrides the image tag whose default is the chart appVersion.\n  tag: \"\"\n\u200b\nimagePullSecrets: []\nnameOverride: \"\"\nfullnameOverride: \"\"\n\u200b\nserviceAccount:\n &nbsp;# Specifies whether a service account should be created\n  create: true\n &nbsp;# Annotations to add to the service account\n  annotations: {}\n &nbsp;# The name of the service account to use.\n &nbsp;# If not set and create is true, a name is generated using the fullname template\n  name: \"\"\npodAnnotations: {}\npodSecurityContext: {}\n &nbsp;# fsGroup: 2000\nsecurityContext: {}\n &nbsp;# capabilities:\n &nbsp;# &nbsp; drop:\n &nbsp;# &nbsp; - ALL\n &nbsp;# readOnlyRootFilesystem: true\n &nbsp;# runAsNonRoot: true\n &nbsp;# runAsUser: 1000\n\u200b\nservice:\n  type: ClusterIP\n  port: 80\n\u200b\ningress:\n  enabled: false\n  className: \"\"\n  annotations: {}\n &nbsp; &nbsp;# kubernetes.io\/ingress.class: nginx\n &nbsp; &nbsp;# kubernetes.io\/tls-acme: \"true\"\n  hosts:\n &nbsp;  - host: chart-example.local\n &nbsp; &nbsp;  paths:\n &nbsp; &nbsp; &nbsp;  - path: \/\n &nbsp; &nbsp; &nbsp; &nbsp;  pathType: ImplementationSpecific\n  tls: []\n &nbsp;#  - secretName: chart-example-tls\n &nbsp;# &nbsp;  hosts:\n &nbsp;# &nbsp; &nbsp;  - chart-example.local\n\u200b\nresources: {}\n &nbsp;# We usually recommend not to specify default resources and to leave this as a conscious\n &nbsp;# choice for the user. This also increases chances charts run on environments with little\n &nbsp;# resources, such as Minikube. If you do want to specify resources, uncomment the following\n &nbsp;# lines, adjust them as necessary, and remove the curly braces after 'resources:'.\n &nbsp;# limits:\n &nbsp;# &nbsp; cpu: 100m\n &nbsp;# &nbsp; memory: 128Mi\n &nbsp;# requests:\n &nbsp;# &nbsp; cpu: 100m\n &nbsp;# &nbsp; memory: 128Mi\n\u200b\nautoscaling:\n  enabled: false\n  minReplicas: 1\n  maxReplicas: 100\n  targetCPUUtilizationPercentage: 80\n &nbsp;# targetMemoryUtilizationPercentage: 80\n\u200b\nnodeSelector: {}\n\u200b\ntolerations: []\n\u200b\naffinity: {} \n\u200b\nroute:\n  host: xxx.cn<\/pre>\n\n\n\n<p>\u5982\u679c\u60f3\u8981\u7ea6\u675f values.yaml \u4e2d\u7684\u914d\u7f6e\u7ed3\u6784\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a values.schema.json\uff0c\u5982\u4e0b\u622a\u53d6\u4e86\u5bf9 values.yaml \u4e2d route \u8bbe\u7f6e\u7ed3\u6784\u7684\u7ea6\u675f\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{<br> &nbsp;\"$schema\": \"http:\/\/json-schema.org\/schema\",<br> &nbsp;\"properties\": {<br> &nbsp; &nbsp;...<br> &nbsp; &nbsp;\"route\": {<br> &nbsp; &nbsp; &nbsp;\"properties\": {<br> &nbsp; &nbsp; &nbsp; &nbsp;\"host\": {<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"type\": \"string\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"description\": \"ingress full hostname for icc\"<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp; &nbsp;  }<br> &nbsp;  }<br>  }<br>}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u8986\u76d6\u5b50 chart \u914d\u7f6e<\/h2>\n\n\n\n<p>\u4e00\u4e2a\u53ef\u7528\u670d\u52a1\u901a\u5e38\u6d89\u53ca\u5230\u591a\u4e2a\u5e94\u7528\uff0c\u6bd4\u5982\u4e1a\u52a1\u5e94\u7528\u4f1a\u4f9d\u8d56 redis \u4e4b\u7c7b\u4e2d\u95f4\u4ef6\uff0c\u8fd9\u5c31\u662f Chart.yaml \u4e2d\u8bbe\u7f6e dependencies \u7684\u7528\u610f\u3002\u5f53\u6211\u4eec\u4f9d\u8d56\u4e8e\u522b\u4eba\u63d0\u4f9b\u7684 chart\uff0c\u4f46\u5728\u90e8\u7f72\u65f6\u53c8\u9700\u8981\u5bf9\u5176\u4e2d\u7684\u4e00\u4e9b\u914d\u7f6e\u8fdb\u884c\u8c03\u6574\uff0c\u8fd9\u65f6\u5019\u5c31\u53ef\u4ee5\u901a\u8fc7\u5728\u7236 Chart.yaml \u4e2d\u8bbe\u7f6e\u80fd\u5bf9\u5e94\u5230\u5b50 chart \u4e2d values.yaml \u4e2d\u7684\u914d\u7f6e\u7684\u914d\u7f6e\u9879\uff0c\u6765\u8fbe\u5230\u8986\u76d6\u5b50 chart \u4e2d\u914d\u7f6e\u503c\u7684\u76ee\u7684\u3002<\/p>\n\n\n\n<p>\u5047\u8bbe\u73b0\u5728 mychart \u6709\u4e00\u4e2a mysubchart \u7684\u4f9d\u8d56\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># tree\n.\n\u251c\u2500\u2500 charts\n\u2502&nbsp;&nbsp; \u2514\u2500\u2500 mysubchart\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u251c\u2500\u2500 charts\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u251c\u2500\u2500 Chart.yaml\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u251c\u2500\u2500 templates\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u2514\u2500\u2500 values.yaml\n\u251c\u2500\u2500 Chart.yaml\n\u251c\u2500\u2500 templates\n\u2514\u2500\u2500 values.yaml<\/pre>\n\n\n\n<p>\u5728 mychart\/charts\/mysubchart\/values.yaml \u4e2d\u5b58\u5728\u4e00\u4e2a\u914d\u7f6e\u9879 dessert\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">dessert: cake<\/pre>\n\n\n\n<p>\u53ef\u4ee5\u901a\u8fc7\u5728 mychart\/values.yaml \u4e2d\u8bbe\u7f6e\u53e6\u4e00\u4e2a\u503c\u6765\u8986\u76d6\u3002\u6307\u660e\u5b50 chart \u540d\u79f0\uff0c\u7136\u540e\u662f values.yaml \u4e2d\u7684\u8def\u5f84\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysubchart:<br>  dessert: ice-cream<\/pre>\n\n\n\n<p>\u6700\u7ec8\uff0c\u6211\u4eec\u5f97\u5230\u7684 chart \u7684\u7ed3\u6784\u53ef\u80fd\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># tree\n.\n\u251c\u2500\u2500 Chart.lock\n\u251c\u2500\u2500 charts\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 mysubchart\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 charts\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 Chart.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 templates\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 deployment.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 _helpers.tpl\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 hpa.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 ingress.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 NOTES.txt\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 serviceaccount.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u251c\u2500\u2500 service.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2514\u2500\u2500 tests\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; &nbsp; &nbsp; \u2514\u2500\u2500 test-connection.yaml\n\u2502&nbsp;&nbsp; \u2502&nbsp;&nbsp; \u2514\u2500\u2500 values.yaml\n\u2502&nbsp;&nbsp; \u2514\u2500\u2500 redis.tgz\n\u251c\u2500\u2500 Chart.yaml\n\u251c\u2500\u2500 templates\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 deployment.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 _helpers.tpl\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 hpa.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 ingress.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 NOTES.txt\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 serviceaccount.yaml\n\u2502&nbsp;&nbsp; \u251c\u2500\u2500 service.yaml\n\u2502&nbsp;&nbsp; \u2514\u2500\u2500 tests\n\u2502&nbsp;&nbsp; &nbsp; &nbsp; \u2514\u2500\u2500 test-connection.yaml\n\u251c\u2500\u2500 values.schema.json\n\u2514\u2500\u2500 values.yaml<\/pre>\n\n\n\n<p><em>reference<\/em><\/p>\n\n\n\n<p><a href=\"https:\/\/helm.sh\/zh\/docs\/chart_template_guide\/getting_started\/\">https:\/\/helm.sh\/zh\/docs\/<\/a><\/p>\n\n\n\n<p>ps\uff1a\u5b98\u65b9\u7684\u6587\u6863\u7ec4\u7ec7\u5f97\u8fd8\u884c\uff0c\u4e2d\u6587\u7684\u8bdd\u5e94\u8be5\u662f\u673a\u7ffb\u7684\uff0c\u51e0\u4e2a\u5730\u65b9\u7ffb\u8bd1\u5f97\u5f88\u5947\u602a<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8ff0 helm chart \u662f\u4e00\u79cd\u63cf\u8ff0\u5982\u4f55\u90e8\u7f72\u5e94\u7528\u5230 kubernetes \u4e2d\u7684\u6587\u6863\u683c\u5f0f\u3002 helm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[38,37],"class_list":["post-1028","post","type-post","status-publish","format-standard","hentry","category-code","tag-helm","tag-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/posts\/1028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1028"}],"version-history":[{"count":7,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions"}],"predecessor-version":[{"id":7876,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=\/wp\/v2\/posts\/1028\/revisions\/7876"}],"wp:attachment":[{"href":"https:\/\/www.chenqing.work\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chenqing.work\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}