{"id":207185,"date":"2025-07-08T09:27:54","date_gmt":"2025-07-08T01:27:54","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207185\/"},"modified":"2025-07-08T09:27:54","modified_gmt":"2025-07-08T01:27:54","slug":"%e5%8e%bb%e5%ae%89%e8%a3%85%e5%9b%be%e8%a1%a8%e5%b9%b6%e6%a3%80%e6%9f%a5%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e6%98%af%e5%90%a6%e5%b7%b2%e5%90%af%e5%8a%a8%e5%b9%b6%e8%bf%90%e8%a1%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207185\/","title":{"rendered":"\u53bb\u5b89\u88c5\u56fe\u8868\u5e76\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u5df2\u542f\u52a8\u5e76\u8fd0\u884c"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u53bb\u5b89\u88c5\u56fe\u8868\u5e76\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u5df2\u542f\u52a8\u5e76\u8fd0\u884c<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-20 17:57:37<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u5927\u5bb6\u597d\uff0c\u6211\u4eec\u53c8\u89c1\u9762\u4e86\u554a~\u672c\u6587<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u53bb\u5b89\u88c5\u56fe\u8868\u5e76\u68c0\u67e5\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u5df2\u542f\u52a8\u5e76\u8fd0\u884c\u300b<\/span>\u7684\u5185\u5bb9\u4e2d\u5c06\u4f1a\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u3002\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u77e5\u8bc6\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\uff0c\u4ee5\u540e\u4f1a\u7ed9\u5927\u5bb6\u5e26\u6765\u66f4\u591a<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">Golang<\/span>\u76f8\u5173\u6587\u7ae0\uff0c\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u8fdb\u6b65\uff01\u4e0b\u9762\u5c31\u5f00\u59cb\u672c\u6587\u7684\u6b63\u5f0f\u5185\u5bb9~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u6709\u4ee5\u4e0b\u6709\u6548\u7684\u4ee3\u7801\uff0c\u6211\u80fd\u591f\u5728\u76ee\u6807\u96c6\u7fa4\u4e2d\u521b\u5efa\u4e00\u4e2a\u8235\u56fe\u3002 \u5f53\u60a8\u5b89\u88c5\u67d0\u4e9b\u56fe\u8868\u76f4\u5230\u5e94\u7528\u7a0b\u5e8f\uff08\u56fe\u8868\u5185\uff09\u53ef\u7528\u65f6\uff0c\u9700\u8981\u65f6\u95f4\uff0c \u5982\u4f55\u68c0\u67e5\u901a\u8fc7 helm chart \u5b89\u88c5\u7684\u5e94\u7528\u7a0b\u5e8f\u662f\u5426\u5df2\u542f\u52a8\u5e76\u6b63\u5728\u8fd0\u884c\uff1f \u6709\u6ca1\u6709\u529e\u6cd5\u7528 helm \u5ba2\u6237\u7aef\u6765\u505a\u5230\u8fd9\u4e00\u70b9\uff08\u6211\u4eec\u4f7f\u7528 helm 3.5.2\uff09<\/p>\n<pre>tmpfile, err := ioutil.TempFile(kp, kcp)\nif err != nil {\n    log.Error(err, \"error\")\n}\n\ndefer os.Remove(tmpfile.Name()) \n\nif _, err := tmpfile.Write(cfg); err != nil {\n    return err\n}\nif err := tmpfile.Close(); err != nil {\n    return err\n}\n\nkcfgFilePath := tmpfile.Name()\nsettings := cli.New()\nac := new(action.Configuration)\nclientGetter := genericclioptions.NewConfigFlags(false)\nclientGetter.KubeConfig = &amp;kcfgFilePath\n\n\n\nfor _, chartInstallation := range charts {\n    chart, err := loader.Load(chartInstallation.Path)\n    if err != nil {\n        return err\n    }\n\n    releaseName := releaseName + \"-\" + chartInstallation.Name\n    if err := ac.Init(clientGetter, settings.Namespace(), os.Getenv(\"HELM_DRIVER\"), func(format string, v ...interface{}) {\n        \n    }); err != nil {\n        return err\n    }\n    releasePresent := true\n    statusAction := action.NewStatus(ac)\n    status, err := statusAction.Run(releaseName)\n    if err != nil {\n        if strings.Contains(err.Error(), driver.ErrReleaseNotFound.Error()) {\n            releasePresent = false\n        } else {\n            return err\n        }\n    }\n\n    if !releasePresent {\n        \/\/ install chart\n        installAction := action.NewInstall(ac)\n        installAction.CreateNamespace = true\n        installAction.Namespace = chartInstallation.Namespace\n        installAction.ReleaseName = releaseName\n\n        _, err := installAction.Run(chart, nil)\n        if err != nil {\n            return err\n        }\n        log.Info(\u201cchart installed: \", \"releaseName\", releaseName)\n    }\n\n    if status != nil {\n        if releasePresent &amp;&amp; status.Info.Status.String() == release.StatusFailed.String() { \n            upgradeAction := action.NewUpgrade(ac)\n            upgradeAction.Wait = true\n            upgradeAction.ReuseValues = false\n            upgradeAction.Recreate = false\n            _, err := upgradeAction.Run(releaseName, chart, nil)\n            if err != nil {\n                return err\n            }\n        }\n    }<\/pre>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u60a8\u9700\u8981\u4f7f\u7528 <code>helm \u5b89\u88c5<\/code>\uff08\u6216 <code>upgrade<\/code>\uff09\uff1a<\/p>\n<p><code>--wait<\/code>\uff1a\u7b49\u5f85\u6240\u6709 Pod \u90fd\u5904\u4e8e\u5c31\u7eea\u72b6\u6001\u3001PVC \u5df2\u7ed1\u5b9a\u3001\u90e8\u7f72\u5177\u6709\u6700\u5c11\uff08\u6240\u9700\u51cf\u53bb <code>maxUnavailable<\/code>\uff09\u4e2a\u5c31\u7eea Pod \u72b6\u6001\u548c\u670d\u52a1\u6709\u4e00\u4e2a IP \u5730\u5740\uff08\u5982\u679c\u662f\u8d1f\u8f7d\u5747\u8861\u5668\uff0c\u8fd8\u6709 Ingress\uff09 \u5728\u5c06\u53d1\u5e03\u6807\u8bb0\u4e3a\u6210\u529f\u4e4b\u524d\u3002\u5b83\u4f1a\u7b49\u5f85\u53ea\u8981 <code>--\u8d85\u65f6<\/code> [&#8230;]<\/p>\n<p>\u786e\u4fdd\u60a8\u7684 pod \u6709 \u4e2a\u68c0\u67e5\u3002\u4f7f\u7528 <code>--wait<\/code> \u53ea\u6709\u5728\u8fd9\u4e9b\u68c0\u67e5\u901a\u8fc7\u540e\uff0c\u91ca\u653e\u624d\u4f1a\u6210\u529f\u8fd4\u56de\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u672c\u6587\u7684\u5168\u90e8\u5185\u5bb9\u4e86\uff0c\u662f\u5426\u6709\u987a\u5229\u5e2e\u52a9\u4f60\u89e3\u51b3\u95ee\u9898\uff1f\u82e5\u662f\u80fd\u7ed9\u4f60\u5e26\u6765\u5b66\u4e60\u4e0a\u7684\u5e2e\u52a9\uff0c\u8bf7\u5927\u5bb6\u591a\u591a\u652f\u6301\uff01\u66f4\u591a\u5173\u4e8eGolang\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u4e5f\u53ef\u5173\u6ce8\u516c\u4f17\u53f7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207185","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207185","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207185"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207185\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207185"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207185"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207185"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}