{"id":1896,"date":"2023-03-31T06:33:52","date_gmt":"2023-03-30T22:33:52","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1896"},"modified":"2023-04-22T08:58:43","modified_gmt":"2023-04-22T00:58:43","slug":"kubernetes-perform-rolling-updates","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/31\/kubernetes-perform-rolling-updates\/","title":{"rendered":"Kubernetes\u6267\u884c\u6eda\u52a8\u66f4\u65b0"},"content":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81ea Kubernetes \u5b98\u7f51 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/kubernetes.io\/docs\/tutorials\/kubernetes-basics\/update\/update-intro\/\" title=\"Performing a Rolling Update\">Performing a Rolling Update<\/a>\uff0c\u5e76\u6709\u6240\u6539\u5199<\/p>\n<h2>\u76ee\u6807<\/h2>\n<ul>\n<li>\u4f7f\u7528 kubectl \u6267\u884c Rolling Update\uff08\u6eda\u52a8\u66f4\u65b0\uff09<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h2>\u66f4\u65b0\u5e94\u7528\u7a0b\u5e8f<\/h2>\n<p>\u7528\u6237\u671f\u671b\u5e94\u7528\u7a0b\u5e8f\u59cb\u7ec8\u53ef\u7528\uff0c\u4e3a\u6b64\u5f00\u53d1\u8005\/\u8fd0\u7ef4\u8005\u5728\u66f4\u65b0\u5e94\u7528\u7a0b\u5e8f\u65f6\u8981\u5206\u591a\u6b21\u5b8c\u6210\u3002\u5728 Kubernetes \u4e2d\uff0c\u8fd9\u662f\u901a\u8fc7 <strong>Rolling Update \u6eda\u52a8\u66f4\u65b0<\/strong>\u5b8c\u6210\u7684\u3002Rolling Update\u6eda\u52a8\u66f4\u65b0 \u901a\u8fc7\u4f7f\u7528\u65b0\u7248\u672c\u7684 Pod \u9010\u6b65\u66ff\u4ee3\u65e7\u7248\u672c\u7684 Pod \u6765\u5b9e\u73b0 Deployment \u7684\u66f4\u65b0\uff0c\u4ece\u800c\u5b9e\u73b0\u96f6\u505c\u673a\u3002\u65b0\u7684 Pod \u5c06\u5728\u5177\u6709\u53ef\u7528\u8d44\u6e90\u7684 Node\uff08\u8282\u70b9\uff09\u4e0a\u8fdb\u884c\u8c03\u5ea6\u3002<\/p>\n<blockquote>\n<p>Kubernetes \u66f4\u65b0\u591a\u526f\u672c\u7684 Deployment \u7684\u7248\u672c\u65f6\uff0c\u4f1a\u9010\u6b65\u7684\u521b\u5efa\u65b0\u7248\u672c\u7684 Pod\uff0c\u9010\u6b65\u7684\u505c\u6b62\u65e7\u7248\u672c\u7684 Pod\uff0c\u4ee5\u4fbf\u4f7f\u5e94\u7528\u4e00\u76f4\u5904\u4e8e\u53ef\u7528\u72b6\u6001\u3002\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0cService \u80fd\u591f\u76d1\u89c6 Pod \u7684\u72b6\u6001\uff0c\u5c06\u6d41\u91cf\u59cb\u7ec8\u8f6c\u53d1\u5230\u53ef\u7528\u7684 Pod \u4e0a\u3002<\/p>\n<\/blockquote>\n<p>\u5728\u4e0a\u4e00\u4e2a\u6a21\u5757\u4e2d\uff0c\u6211\u4eec\u5b66\u4e60\u4e86\u5c06\u5e94\u7528\u7a0b\u5e8f Scale Up\uff08\u6269\u5bb9\uff09\u4e3a\u591a\u4e2a\u5b9e\u4f8b\uff0c\u8fd9\u662f\u6267\u884c\u66f4\u65b0\u800c\u4e0d\u5f71\u54cd\u5e94\u7528\u7a0b\u5e8f\u53ef\u7528\u6027\u7684\u524d\u63d0\uff08\u5982\u679c\u53ea\u6709 1 \u4e2a\u5b9e\u4f8b\u90a3\u8fd8\u73a9\u5565\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cRolling Update \u6eda\u52a8\u66f4\u65b0 \u8fc7\u7a0b\u4e2d\uff0cKubernetes \u9010\u4e2a\u4f7f\u7528\u65b0\u7248\u672c Pod \u66ff\u6362\u65e7\u7248\u672c Pod\uff08\u6700\u5927\u4e0d\u53ef\u7528 Pod \u6570\u4e3a 1\u3001\u6700\u5927\u65b0\u5efa Pod \u6570\u4e5f\u4e3a 1\uff09\u3002\u8fd9\u4e24\u4e2a\u53c2\u6570\u53ef\u4ee5\u914d\u7f6e\u4e3a\u6570\u5b57\u6216\u767e\u5206\u6bd4\u3002\u5728Kubernetes \u4e2d\uff0c\u66f4\u65b0\u662f\u7248\u672c\u5316\u7684\uff0c\u4efb\u4f55\u90e8\u7f72\u66f4\u65b0\u90fd\u53ef\u4ee5\u6062\u590d\u4e3a\u4ee5\u524d\u7684\uff08\u7a33\u5b9a\uff09\u7248\u672c\u3002<\/p>\n<h2>\u6eda\u52a8\u66f4\u65b0\u6982\u8ff0<\/h2>\n<p>\uff081\uff09\u539f\u672c Service A \u5c06\u6d41\u91cf\u8d1f\u8f7d\u5747\u8861\u5230 4 \u4e2a\u65e7\u7248\u672c\u7684 Pod \uff08\u5f53\u4e2d\u7684\u5bb9\u5668\u4e3a \u7eff\u8272\uff09\u4e0a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_06_rollingupdates1.3f74dfba.svg\" alt=\"Kubernetes Pod\u7b49\u5f85\u66f4\u65b0\" \/><\/p>\n<p>\uff082\uff09\u66f4\u65b0\u5b8c Deployment \u90e8\u7f72\u6587\u4ef6\u4e2d\u7684\u955c\u50cf\u7248\u672c\u540e\uff0cmaster \u8282\u70b9\u9009\u62e9\u4e86\u4e00\u4e2a worker \u8282\u70b9\uff0c\u5e76\u6839\u636e\u65b0\u7684\u955c\u50cf\u7248\u672c\u521b\u5efa Pod\uff08\u7d2b\u8272\u5bb9\u5668\uff09\u3002\u65b0 Pod \u62e5\u6709\u552f\u4e00\u7684\u65b0\u7684 IP\u3002\u540c\u65f6\uff0cmaster \u8282\u70b9\u9009\u62e9\u4e00\u4e2a\u65e7\u7248\u672c\u7684 Pod \u5c06\u5176\u79fb\u9664\u3002<\/p>\n<p>\u6b64\u65f6\uff0cService A \u5c06\u65b0 Pod \u7eb3\u5165\u5230\u8d1f\u8f7d\u5747\u8861\u4e2d\uff0c\u5c06\u65e7Pod\u79fb\u9664<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_06_rollingupdates2.62afd5b1.svg\" alt=\"Kubernetes \u521b\u5efa\u65b0Pod\u79fb\u9664\u65e7Pod\" \/><\/p>\n<p>\uff083\uff09\u540c\u6b65\u9aa42\uff0c\u518d\u521b\u5efa\u4e00\u4e2a\u65b0\u7684 Pod \u66ff\u6362\u4e00\u4e2a\u539f\u6709\u7684 Pod<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_06_rollingupdates3.dc3754d9.svg\" alt=\"Kubernetes \u65b0Pod\u66ff\u4ee3\u65e7Pod\" \/><\/p>\n<p>\uff084\uff09\u5982\u6b64 Rolling Update \u6eda\u52a8\u66f4\u65b0\uff0c\u76f4\u5230\u6240\u6709\u65e7\u7248\u672c Pod \u5747\u79fb\u9664\uff0c\u65b0\u7248\u672c Pod \u4e5f\u8fbe\u5230 Deployment \u90e8\u7f72\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684\u526f\u672c\u6570\uff0c\u5219\u6eda\u52a8\u66f4\u65b0\u5b8c\u6210<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_06_rollingupdates4.05347706.svg\" alt=\"Kubernetes Pod\u66f4\u65b0\u5b8c\u6210\" \/><\/p>\n<p>\u6eda\u52a8\u66f4\u65b0\u5141\u8bb8\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li>\u5c06\u5e94\u7528\u7a0b\u5e8f\u4ece\u51c6\u4e0a\u7ebf\u73af\u5883\u5347\u7ea7\u5230\u751f\u4ea7\u73af\u5883\uff08\u901a\u8fc7\u66f4\u65b0\u5bb9\u5668\u955c\u50cf\uff09<\/li>\n<li>\u56de\u6eda\u5230\u4ee5\u524d\u7684\u7248\u672c<\/li>\n<li>\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u4ea4\u4ed8\u5e94\u7528\u7a0b\u5e8f\uff0c\u65e0\u9700\u505c\u673a<\/li>\n<\/ul>\n<h2>\u5b9e\u6218\uff1a\u66f4\u65b0 nginx Deployment<\/h2>\n<h3>\u4f7f\u7528kubectl<\/h3>\n<p>\uff081\uff09\u4fee\u6539 nginx-deployment.yaml \u6587\u4ef6<\/p>\n<p>\u4fee\u6539\u6587\u4ef6\u4e2d image \u955c\u50cf\u7684\u6807\u7b7e\uff0c\u5982\u4e0b\u6240\u793a<\/p>\n<pre><code class=\"language-yml\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nginx-deployment\n  labels:\n    app: nginx\nspec:\n  replicas: 4\n  selector:\n    matchLabels:\n      app: nginx\n  template:\n    metadata:\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: nginx:1.8   #\u4f7f\u7528\u955c\u50cfnginx:1.8\u66ff\u6362\u539f\u6765\u7684nginx:1.7.9\n        ports:\n        - containerPort: 80<\/code><\/pre>\n<p>\uff082\uff09\u6267\u884c\u547d\u4ee4<\/p>\n<pre><code class=\"language-bash\">kubectl apply -f nginx-deployment.yaml<\/code><\/pre>\n<p>\uff083\uff09\u67e5\u770b\u8fc7\u7a0b\u53ca\u7ed3\u679c<\/p>\n<p>\u6267\u884c\u547d\u4ee4\uff0c\u53ef\u89c2\u5bdf\u5230 pod \u9010\u4e2a\u88ab\u66ff\u6362\u7684\u8fc7\u7a0b\u3002<\/p>\n<pre><code class=\"language-bash\">watch kubectl get pods -l app=nginx<\/code><\/pre>\n<h3>\u4f7f\u7528Kuboard<\/h3>\n<ul>\n<li>\n<p>\u8fdb\u5165 default \u540d\u79f0\u7a7a\u95f4<\/p>\n<\/li>\n<li>\n<p>\u70b9\u51fb<strong>\u8c03\u6574\u955c\u50cf\u7248\u672c<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>\u52fe\u9009\u5c55\u73b0\u5c42\uff0c\u5e76\u5237\u65b0\uff0c\u53ef\u627e\u5230 Nginx\u90e8\u7f72<\/p>\n<ul>\n<li>\u9488\u5bf9<strong>Nginx\u90e8\u7f72<\/strong>\u70b9\u51fb\u4fee\u6539<\/li>\n<\/ul>\n<p>\u586b\u5199\u65b0\u7684 nginx \u7248\u672c\u53f7\uff1a1.8\uff0c \u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuboard.cn\/assets\/img\/image-20210403204908592.6a947b91.png\" alt=\"Kuboard \u4fee\u6539\u955c\u50cf\u7248\u672c\" \/><\/p>\n<ul>\n<li>\u70b9\u51fb<strong>\u53d8\u66f4<\/strong>\uff0c<strong>\u5e94\u7528<\/strong>\uff0c<strong>\u5b8c\u6210<\/strong><\/li>\n<\/ul>\n<p>\u53ef\u89c2\u5bdf\u5230 Kubernetes \u5bf9<strong>Nginx\u90e8\u7f72<\/strong>\u6267\u884c\u6eda\u52a8\u66f4\u65b0\u7684\u8fc7\u7a0b\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuboard.cn\/assets\/img\/image-20210403205053379.de2bc7b2.png\" alt=\"Kuboard \u6267\u884c\u6eda\u52a8\u66f4\u65b0\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81ea Kubernetes \u5b98\u7f51 Performing a Rolling Update\uff0c\u5e76\u6709\u6240\u6539\u5199 \u76ee [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[483],"class_list":["post-1896","post","type-post","status-publish","format-standard","hentry","category-k8s","tag-kuboard"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1896","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1896"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1896\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1896"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1896"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1896"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}