{"id":1977,"date":"2025-03-14T11:18:27","date_gmt":"2025-03-14T03:18:27","guid":{"rendered":"https:\/\/www.fanyamin.com\/wordpress\/?p=1977"},"modified":"2025-03-16T10:21:25","modified_gmt":"2025-03-16T02:21:25","slug":"helm","status":"publish","type":"post","link":"https:\/\/www.fanyamin.com\/wordpress\/?p=1977","title":{"rendered":"Helm tutorial 1"},"content":{"rendered":"<p>Helm \u662f Kubernetes \u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u65e8\u5728\u7b80\u5316\u5e94\u7528\u7a0b\u5e8f\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u3002 \ue200cite\ue202turn0search3\ue201 \u5b83\u901a\u8fc7\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684 Kubernetes \u8d44\u6e90\u5b9a\u4e49\u6253\u5305\u6210\u79f0\u4e3a Chart \u7684\u683c\u5f0f\uff0c\u63d0\u4f9b\u4e86\u81ea\u52a8\u5316\u7684\u5e94\u7528\u5206\u53d1\u65b9\u5f0f\u3002<\/p>\n<p><strong>\u6838\u5fc3\u6982\u5ff5\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p><strong>Chart<\/strong>\uff1aHelm \u5305\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u5305\u542b\u4e86\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u8d44\u6e90\u5b9a\u4e49\u3002<\/p>\n<\/li>\n<li>\n<p><strong>Repository\uff08\u4ed3\u5e93\uff09<\/strong>\uff1a\u5b58\u653e\u548c\u5171\u4eab Charts \u7684\u5730\u65b9\uff0c\u7c7b\u4f3c\u4e8e Perl \u7684 CPAN \u6216 Fedora \u7684\u8f6f\u4ef6\u5305\u4ed3\u5e93\u3002<\/p>\n<\/li>\n<li>\n<p><strong>Release<\/strong>\uff1a\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684 Chart \u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u4e00\u4e2a Chart \u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u96c6\u7fa4\u4e2d\u5b89\u88c5\u591a\u6b21\uff0c\u6bcf\u6b21\u5b89\u88c5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Release\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528 Helm \u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5 Helm<\/strong>\uff1a\u9996\u5148\uff0c\u9700\u8981\u5728\u672c\u5730\u73af\u5883\u4e2d\u5b89\u88c5 Helm \u5ba2\u6237\u7aef\u3002\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b89\u88c5\uff0c\u4f8b\u5982\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u6216\u4ece GitHub \u53d1\u5e03\u9875\u9762\u4e0b\u8f7d\u3002<\/p>\n<\/li>\n<li>\n<p><strong>\u6dfb\u52a0 Chart \u4ed3\u5e93<\/strong>\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u6dfb\u52a0 Chart \u4ed3\u5e93\u3002\u4f8b\u5982\uff0c\u6dfb\u52a0 Bitnami \u4ed3\u5e93\uff1a<\/p>\n<pre><code class=\"language-bash\">helm repo add bitnami https:\/\/charts.bitnami.com\/bitnami<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u641c\u7d22 Charts<\/strong>\uff1a\u4f7f\u7528 <code>helm search<\/code> \u547d\u4ee4\u67e5\u627e\u53ef\u7528\u7684 Charts\u3002\u4f8b\u5982\uff0c\u641c\u7d22 WordPress\uff1a<\/p>\n<pre><code class=\"language-bash\">helm search repo wordpress<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5 Chart<\/strong>\uff1a\u4f7f\u7528 <code>helm install<\/code> \u547d\u4ee4\u5b89\u88c5\u6240\u9700\u7684 Chart\u3002\u4f8b\u5982\uff0c\u5b89\u88c5\u540d\u4e3a <code>my-release<\/code> \u7684 WordPress\uff1a<\/p>\n<pre><code class=\"language-bash\">helm install my-release bitnami\/wordpress<\/code><\/pre>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406 Release<\/strong>\uff1a\u5b89\u88c5\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>helm list<\/code> \u67e5\u770b\u6240\u6709\u7684 Releases\uff0c\u4f7f\u7528 <code>helm upgrade<\/code> \u5347\u7ea7 Release\uff0c\u4f7f\u7528 <code>helm rollback<\/code> \u56de\u6eda\u5230\u4e4b\u524d\u7684\u7248\u672c\uff0c\u4f7f\u7528 <code>helm uninstall<\/code> \u5378\u8f7d Release\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u901a\u8fc7 Helm\uff0c\u5f00\u53d1\u8005\u548c\u8fd0\u7ef4\u4eba\u5458\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u7ba1\u7406 Kubernetes \u5e94\u7528\u7a0b\u5e8f\u7684\u751f\u547d\u5468\u671f\uff0c\u7b80\u5316\u90e8\u7f72\u8fc7\u7a0b\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002 <\/p>\n<h2>Example 1<\/h2>\n<p>To install MySQL using Helm in the current namespace of your Kubernetes (k8s) cluster, follow these steps:<\/p>\n<h3><strong>Step 1: Add the Bitnami Helm Repository<\/strong><\/h3>\n<p>Bitnami provides a well-maintained MySQL Helm chart.<\/p>\n<pre><code class=\"language-sh\">helm repo add bitnami https:\/\/charts.bitnami.com\/bitnami\nhelm repo update<\/code><\/pre>\n<h3><strong>Step 2: Install MySQL in the Current Namespace<\/strong><\/h3>\n<p>To install MySQL in the current namespace, run:<\/p>\n<pre><code class=\"language-sh\">helm install my-mysql bitnami\/mysql<\/code><\/pre>\n<blockquote>\n<p><strong>Note:<\/strong> If you are using a custom namespace, ensure that your <code>kubectl<\/code> context is set to the desired namespace:<\/p>\n<pre><code class=\"language-sh\">kubectl config set-context --current --namespace=<your-namespace><\/code><\/pre>\n<\/blockquote>\n<h3><strong>Step 3: Verify Installation<\/strong><\/h3>\n<p>Check the status of the MySQL deployment:<\/p>\n<pre><code class=\"language-sh\">kubectl get pods<\/code><\/pre>\n<p>To see the Helm release:<\/p>\n<pre><code class=\"language-sh\">helm list<\/code><\/pre>\n<h3><strong>Step 4: Retrieve the MySQL Root Password<\/strong><\/h3>\n<p>MySQL generates a random root password by default. You can retrieve it using:<\/p>\n<pre><code class=\"language-sh\">kubectl get secret my-mysql -o jsonpath=&quot;{.data.mysql-root-password}&quot; | base64 --decode<\/code><\/pre>\n<h3><strong>Step 5: Connect to MySQL<\/strong><\/h3>\n<p>To connect to MySQL from a pod inside the cluster:<\/p>\n<pre><code class=\"language-sh\">kubectl run my-mysql-client --rm --tty -i --restart=&#039;Never&#039; --image docker.io\/bitnami\/mysql:latest --namespace default -- \\\n    mysql -h my-mysql -uroot -p<\/code><\/pre>\n<p>For external access, you may need to configure a <code>LoadBalancer<\/code> or <code>NodePort<\/code> service.<\/p>\n<hr \/>\n<p>Would you like to customize MySQL with specific configurations (e.g., storage size, replication, custom user\/passwords)? \ud83d\ude80<\/p>\n<h2>Example 2<\/h2>\n<p>To install Redis using Helm in the <strong>current namespace<\/strong> of your Kubernetes cluster, follow these steps:<\/p>\n<h3><strong>Step 1: Add the Bitnami Helm Repository<\/strong><\/h3>\n<p>Bitnami provides an official Helm chart for Redis.<\/p>\n<pre><code class=\"language-sh\">helm repo add bitnami https:\/\/charts.bitnami.com\/bitnami\nhelm repo update<\/code><\/pre>\n<h3><strong>Step 2: Install Redis in the Current Namespace<\/strong><\/h3>\n<p>To install Redis in the current namespace, simply run:<\/p>\n<pre><code class=\"language-sh\">helm install my-redis bitnami\/redis<\/code><\/pre>\n<blockquote>\n<p><strong>Note:<\/strong> If you are using a specific namespace, ensure your <code>kubectl<\/code> context is set to it:<\/p>\n<pre><code class=\"language-sh\">kubectl config set-context --current --namespace=<your-namespace><\/code><\/pre>\n<\/blockquote>\n<h3><strong>Step 3: Verify the Installation<\/strong><\/h3>\n<p>Check if the Redis pods are running:<\/p>\n<pre><code class=\"language-sh\">kubectl get pods<\/code><\/pre>\n<p>To see the Helm release:<\/p>\n<pre><code class=\"language-sh\">helm list<\/code><\/pre>\n<h3><strong>Step 4: Retrieve the Redis Password<\/strong><\/h3>\n<p>The default Redis installation requires authentication. Retrieve the Redis password:<\/p>\n<pre><code class=\"language-sh\">kubectl get secret my-redis -o jsonpath=&quot;{.data.redis-password}&quot; | base64 --decode<\/code><\/pre>\n<h3><strong>Step 5: Connect to Redis<\/strong><\/h3>\n<p>To access Redis from within the cluster, you can use:<\/p>\n<pre><code class=\"language-sh\">kubectl run my-redis-client --rm --tty -i --restart=&#039;Never&#039; --image docker.io\/bitnami\/redis:latest -- \\\n    redis-cli -h my-redis-master -a &lt;your-redis-password&gt;<\/code><\/pre>\n<p>For external access, consider setting the service type to <code>LoadBalancer<\/code> or <code>NodePort<\/code> by modifying the <code>values.yaml<\/code> or using:<\/p>\n<pre><code class=\"language-sh\">helm install my-redis bitnami\/redis --set service.type=LoadBalancer<\/code><\/pre>\n<hr \/>\n<h3><strong>Optional: Customizing Redis Installation<\/strong><\/h3>\n<p>You can customize Redis with parameters like persistence, cluster mode, and custom passwords. Example:<\/p>\n<pre><code class=\"language-sh\">helm install my-redis bitnami\/redis --set auth.password=mysecurepassword<\/code><\/pre>\n<h3>install mysql<\/h3>\n<h2>Best practice<\/h2>\n<p>Helm \u662f Kubernetes \u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u65e8\u5728\u7b80\u5316\u5e94\u7528\u7a0b\u5e8f\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u3002\u4e3a\u4e86\u6709\u6548\u5730\u4f7f\u7528 Helm\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5b9e\u8df5\u5efa\u8bae\uff1a<\/p>\n<ol>\n<li>\n<p><strong>\u7ed3\u6784\u5316 Chart \u6587\u4ef6<\/strong>\uff1a\u786e\u4fdd\u60a8\u7684 Chart \u76ee\u5f55\u7ed3\u6784\u6e05\u6670\uff0c\u5305\u62ec <code>templates<\/code>\u3001<code>values.yaml<\/code>\u3001<code>Chart.yaml<\/code> \u7b49\u5fc5\u8981\u6587\u4ef6\u3002\u8fd9\u6709\u52a9\u4e8e\u7ef4\u62a4\u548c\u7406\u89e3 Chart \u7684\u5185\u5bb9\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>values.yaml<\/code> \u7ba1\u7406\u914d\u7f6e<\/strong>\uff1a\u5c06\u53ef\u914d\u7f6e\u53c2\u6570\u653e\u5165 <code>values.yaml<\/code> \u6587\u4ef6\u4e2d\uff0c\u4f7f Chart \u66f4\u52a0\u7075\u6d3b\uff0c\u65b9\u4fbf\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u590d\u7528\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u6a21\u677f\u5316\u8d44\u6e90\u5b9a\u4e49<\/strong>\uff1a\u5229\u7528 Helm \u7684\u6a21\u677f\u529f\u80fd\uff0c\u5c06 Kubernetes \u8d44\u6e90\u7684\u5b9a\u4e49\u6a21\u677f\u5316\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u90e8\u7f72\u9700\u6c42\u3002 \ue200<\/p>\n<\/li>\n<li>\n<p><strong>\u9075\u5faa YAML \u8bed\u6cd5<\/strong>\uff1a\u6a21\u677f\u5e94\u9075\u5faa YAML \u8bed\u6cd5\uff0c\u9664\u975e\u4f7f\u7528 JSON \u8bed\u6cd5\u80fd\u663e\u8457\u964d\u4f4e\u683c\u5f0f\u95ee\u9898\u7684\u98ce\u9669\u3002 \ue200<\/p>\n<\/li>\n<li>\n<p><strong>\u8c28\u614e\u751f\u6210\u968f\u673a\u503c<\/strong>\uff1a\u5728\u6a21\u677f\u4e2d\u751f\u6210\u968f\u673a\u6570\u636e\uff08\u5982\u52a0\u5bc6\u5bc6\u94a5\uff09\u65f6\uff0c\u8981\u6ce8\u610f\u5728\u5347\u7ea7\u6216\u91cd\u65b0\u6267\u884c\u6a21\u677f\u65f6\u53ef\u80fd\u5bfc\u81f4\u8d44\u6e90\u4e0d\u4e00\u81f4\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528 <code>helm upgrade --install<\/code> \u547d\u4ee4<\/strong>\uff1a\u8be5\u547d\u4ee4\u53ef\u4ee5\u5728\u4e0d\u5b58\u5728 Release \u65f6\u5b89\u88c5\uff0c\u5b58\u5728\u65f6\u5347\u7ea7\uff0c\u7b80\u5316\u90e8\u7f72\u6d41\u7a0b\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u4f9d\u8d56\u5173\u7cfb<\/strong>\uff1a\u5728 <code>Chart.yaml<\/code> \u4e2d\u660e\u786e\u5217\u51fa\u4f9d\u8d56\u7684 Charts\uff0c\u5e76\u4f7f\u7528 <code>helm dependency<\/code> \u547d\u4ee4\u7ba1\u7406\u8fd9\u4e9b\u4f9d\u8d56\u5173\u7cfb\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u94a9\u5b50\uff08Hooks\uff09<\/strong>\uff1a\u5229\u7528 Helm \u63d0\u4f9b\u7684\u94a9\u5b50\u673a\u5236\uff0c\u5728\u90e8\u7f72\u8fc7\u7a0b\u4e2d\u6267\u884c\u7279\u5b9a\u64cd\u4f5c\uff0c\u5982\u8fc1\u79fb\u6570\u636e\u5e93\u6216\u6e05\u7406\u8d44\u6e90\u3002 \ue200<\/p>\n<\/li>\n<li>\n<p><strong>\u7248\u672c\u63a7\u5236<\/strong>\uff1a\u4e3a\u60a8\u7684 Charts \u5236\u5b9a\u660e\u786e\u7684\u7248\u672c\u7b56\u7565\uff0c\u786e\u4fdd\u5728\u4e0d\u540c\u73af\u5883\u4e2d\u4f7f\u7528\u6b63\u786e\u7684\u7248\u672c\u3002 <\/p>\n<\/li>\n<li>\n<p><strong>\u5b9a\u671f\u66f4\u65b0 Charts<\/strong>\uff1a\u53ca\u65f6\u66f4\u65b0\u60a8\u7684 Charts\uff0c\u4ee5\u5305\u542b\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u4fee\u590d\u3002 \ue200<\/p>\n<\/li>\n<\/ol>\n<p>\u9075\u5faa\u8fd9\u4e9b\u6700\u4f73\u5b9e\u8df5\uff0c\u53ef\u4ee5\u63d0\u9ad8 Helm Charts \u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u590d\u7528\u6027\uff0c\u786e\u4fdd\u5728 Kubernetes \u73af\u5883\u4e2d\u7684\u7a33\u5b9a\u90e8\u7f72\u3002 <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Helm \u662f Kubernetes \u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u65e8\u5728\u7b80\u5316\u5e94\u7528\u7a0b\u5e8f\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u7684\u90e8\u7f72\u548c\u7ba1\u7406\u3002 \ue200cite\ue202turn0search3\ue201 \u5b83\u901a\u8fc7\u5c06\u5e94\u7528\u7a0b\u5e8f\u7684 Kubernetes \u8d44\u6e90\u5b9a\u4e49\u6253\u5305\u6210\u79f0\u4e3a Chart \u7684\u683c\u5f0f\uff0c\u63d0\u4f9b\u4e86\u81ea\u52a8\u5316\u7684\u5e94\u7528\u5206\u53d1\u65b9\u5f0f\u3002 \u6838\u5fc3\u6982\u5ff5\uff1a Chart\uff1aHelm \u5305\u7684\u57fa\u672c\u5355\u4f4d\uff0c\u5305\u542b\u4e86\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u6240\u9700\u7684\u6240\u6709\u8d44\u6e90\u5b9a\u4e49\u3002 Repository\uff08\u4ed3\u5e93\uff09\uff1a\u5b58\u653e\u548c\u5171\u4eab Charts \u7684\u5730\u65b9\uff0c\u7c7b\u4f3c\u4e8e Perl \u7684 CPAN \u6216 Fedora \u7684\u8f6f\u4ef6\u5305\u4ed3\u5e93\u3002 Release\uff1a\u5728 Kubernetes \u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684 Chart \u7684\u4e00\u4e2a\u5b9e\u4f8b\u3002\u4e00\u4e2a Chart \u53ef\u4ee5\u5728\u540c\u4e00\u4e2a\u96c6\u7fa4\u4e2d\u5b89\u88c5\u591a\u6b21\uff0c\u6bcf\u6b21\u5b89\u88c5\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Release\u3002 \u4f7f\u7528 Helm \u7684\u57fa\u672c\u6b65\u9aa4\uff1a \u5b89\u88c5 Helm\uff1a\u9996\u5148\uff0c\u9700\u8981\u5728\u672c\u5730\u73af\u5883\u4e2d\u5b89\u88c5 Helm \u5ba2\u6237\u7aef\u3002\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b89\u88c5\uff0c\u4f8b\u5982\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177\u6216\u4ece GitHub \u53d1\u5e03\u9875\u9762\u4e0b\u8f7d\u3002 \u6dfb\u52a0 Chart \u4ed3\u5e93\uff1a\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u6dfb\u52a0 Chart \u4ed3\u5e93\u3002\u4f8b\u5982\uff0c\u6dfb\u52a0 Bitnami \u4ed3\u5e93\uff1a helm repo add bitnami https:\/\/charts.bitnami.com\/bitnami [&hellip;] <a class=\"read-more\" href=\"https:\/\/www.fanyamin.com\/wordpress\/?p=1977\" title=\"Permanent Link to: Helm tutorial 1\">&rarr;Read&nbsp;more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1977","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1977"}],"collection":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1977"}],"version-history":[{"count":5,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1977\/revisions"}],"predecessor-version":[{"id":1997,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/1977\/revisions\/1997"}],"wp:attachment":[{"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fanyamin.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}