{"id":1895,"date":"2023-03-31T06:32:26","date_gmt":"2023-03-30T22:32:26","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1895"},"modified":"2023-04-22T08:58:21","modified_gmt":"2023-04-22T00:58:21","slug":"kubernetes-scaling-application","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/31\/kubernetes-scaling-application\/","title":{"rendered":"Kubernetes\u4f38\u7f29\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81ea Kubernetes \u5b98\u7f51 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/kubernetes.io\/docs\/tutorials\/kubernetes-basics\/scale\/scale-intro\/\" title=\"Running Multiple Instances of Your App\">Running Multiple Instances of Your App<\/a>\uff0c\u5e76\u6709\u6240\u6539\u5199<\/p>\n<h2>\u76ee\u6807<\/h2>\n<ul>\n<li>\u4f7f\u7528 kubectl \u4f38\u7f29\u5e94\u7528\u7a0b\u5e8f<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<h2>Scaling\uff08\u4f38\u7f29\uff09\u5e94\u7528\u7a0b\u5e8f<\/h2>\n<p>\u5728\u4e4b\u524d\u7684\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/workloads\/controllers\/deployment\/\" title=\"Deployment\">Deployment<\/a>\uff0c\u7136\u540e\u901a\u8fc7 <a target=\"_blank\" rel=\"noopener\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/services-networking\/service\/\" title=\"\u670d\u52a1\">\u670d\u52a1<\/a> \u63d0\u4f9b\u8bbf\u95ee Pod \u7684\u65b9\u5f0f\u3002\u6211\u4eec\u53d1\u5e03\u7684 Deployment \u53ea\u521b\u5efa\u4e86\u4e00\u4e2a Pod \u6765\u8fd0\u884c\u6211\u4eec\u7684\u5e94\u7528\u7a0b\u5e8f\u3002\u5f53\u6d41\u91cf\u589e\u52a0\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5bf9\u5e94\u7528\u7a0b\u5e8f\u8fdb\u884c\u4f38\u7f29\u64cd\u4f5c\u4ee5\u6ee1\u8db3\u7cfb\u7edf\u6027\u80fd\u9700\u6c42\u3002<\/p>\n<p><strong>\u4f38\u7f29<\/strong>\u7684\u5b9e\u73b0\u53ef\u4ee5\u901a\u8fc7\u66f4\u6539<code>nginx-deployment.yaml<\/code>\u6587\u4ef6\u4e2d\u90e8\u7f72\u7684<code>replicas<\/code>\uff08\u526f\u672c\u6570\uff09\u6765\u5b8c\u6210<\/p>\n<pre><code class=\"language-yml\">spec:\n  replicas: 2    #\u4f7f\u7528\u8be5Deployment\u521b\u5efa\u4e24\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5b9e\u4f8b<\/code><\/pre>\n<h2>Scaling\uff08\u4f38\u7f29\uff09\u6982\u8ff0<\/h2>\n<p>\u4e0b\u56fe\u4e2d\uff0cService A \u53ea\u5c06\u8bbf\u95ee\u6d41\u91cf\u8f6c\u53d1\u5230 IP \u4e3a 10.0.0.5 \u7684Pod\u4e0a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_05_scaling1.d9d22450.svg\" alt=\"Kubernetes Pod \u4f38\u7f29\u524d\" \/><\/p>\n<p>\u4fee\u6539\u4e86 Deployment \u7684 replicas \u4e3a 4 \u540e\uff0cKubernetes \u53c8\u4e3a\u8be5 Deployment \u521b\u5efa\u4e86 3 \u65b0\u7684 Pod\uff0c\u8fd9 4 \u4e2a Pod \u6709\u76f8\u540c\u7684\u6807\u7b7e\u3002\u56e0\u6b64Service A\u901a\u8fc7\u6807\u7b7e\u9009\u62e9\u5668\u4e0e\u65b0\u7684 Pod\u5efa\u7acb\u4e86\u5bf9\u5e94\u5173\u7cfb\uff0c\u5c06\u8bbf\u95ee\u6d41\u91cf\u901a\u8fc7\u8d1f\u8f7d\u5747\u8861\u5728 4 \u4e2a Pod \u4e4b\u95f4\u8fdb\u884c\u8f6c\u53d1\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_05_scaling2.3f74dfba.svg\" alt=\"Kubernetes Pod \u4f38\u7f29\u540e\" \/><\/p>\n<blockquote>\n<p>TIP\uff1a\u901a\u8fc7\u66f4\u6539\u90e8\u7f72\u4e2d\u7684 replicas\uff08\u526f\u672c\u6570\uff09\u6765\u5b8c\u6210\u6269\u5c55<\/p>\n<\/blockquote>\n<h2>\u5b9e\u6218\uff1a\u5c06 nginx Deployment \u6269\u5bb9\u5230 4 \u4e2a\u526f\u672c<\/h2>\n<h3>\u4f7f\u7528kubectl<\/h3>\n<p>\uff081\uff09\u4fee\u6539<code>nginx-deployment.yaml<\/code>\u6587\u4ef6<\/p>\n<p>\u5c06<code>replicas<\/code>\u4fee\u6539\u4e3a 4<\/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.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\u7ed3\u679c<\/p>\n<pre><code class=\"language-bash\">watch kubectl get pods -o wide<\/code><\/pre>\n<h3>\u4f7f\u7528Kuboard<\/h3>\n<ul>\n<li>\n<p>\u5728 default \u540d\u79f0\u7a7a\u95f4\uff0c\u70b9\u51fb<strong>\u5c55\u73b0\u5c42<\/strong> &#8211;&gt; <strong>Nginx\u90e8\u7f72<\/strong><\/p>\n<\/li>\n<li>\n<p>\u70b9\u51fb<strong>\u4f38\u7f29<\/strong>\u6309\u94ae<\/p>\n<\/li>\n<\/ul>\n<p>\u586b\u5199\u8868\u5355\uff0c\u526f\u672c\u6570\uff1a4<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.kuboard.cn\/assets\/img\/module_05_scaling2.3f74dfba.svg\" alt=\"Kuboard \u4f38\u7f29\u526f\u672c\u914d\u7f6e\" \/><\/p>\n<ul>\n<li>\u70b9\u51fb<strong>\u786e\u5b9a<\/strong>\u6309\u94ae<\/li>\n<\/ul>\n<p>\u7b49\u5f85\u65b0\u589e\u7684\u5bb9\u5668\u7ec4\u5b8c\u6210\u521d\u59cb\u5316\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/kuboard.cn\/assets\/img\/image-20210403203909667.66482c76.png\" alt=\"Kuboard \u4f38\u7f29\u7ed3\u679c\" \/><\/p>\n<p>\u4e00\u65e6\u8fd0\u884c\u4e86\u591a\u4e2a\u5e94\u7528\u7a0b\u5e8f\u5b9e\u4f8b\uff0c\u5c31\u53ef\u4ee5\u5728\u4e0d\u505c\u673a\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u6eda\u52a8\u66f4\u65b0\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u7ffb\u8bd1\u81ea Kubernetes \u5b98\u7f51 Running Multiple Instances of Your  [&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-1895","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\/1895","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=1895"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1895\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}