{"id":5040,"date":"2021-10-03T20:40:03","date_gmt":"2021-10-03T12:40:03","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=5040"},"modified":"2026-01-06T11:09:04","modified_gmt":"2026-01-06T03:09:04","slug":"pod-5","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2021\/10\/03\/pod-5\/","title":{"rendered":"Pod\u7684\u6269\u7f29\u5bb9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Kubernetes\u5bf9Pod\u7684\u6269\u7f29\u5bb9\u64cd\u4f5c\u63d0\u4f9b\u4e86\u624b\u52a8\u548c\u81ea\u52a8\u4e24\u79cd\u6a21\u5f0f\uff0c\u624b\u52a8\u6a21\u5f0f\u901a\u8fc7\u6267\u884ckubectl scale\u547d\u4ee4\u6216\u901a\u8fc7RESTful API\u5bf9\u4e00\u4e2aDeployment\/RC\u8fdb\u884cPod\u526f\u672c\u6570\u91cf\u7684\u8bbe\u7f6e\uff0c\u5373\u53ef\u4e00\u952e\u5b8c\u6210\u3002\u81ea\u52a8\u6a21\u5f0f\u5219\u9700\u8981\u7528\u6237\u6839\u636e\u67d0\u4e2a\u6027\u80fd\u6307\u6807\u6216\u8005\u81ea\u5b9a\u4e49\u4e1a\u52a1\u6307\u6807\uff0c\u5e76\u6307\u5b9aPod\u526f\u672c\u6570\u91cf\u7684\u8303\u56f4\uff0c\u7cfb\u7edf\u5c06\u81ea\u52a8\u5728\u8fd9\u4e2a\u8303\u56f4\u5185\u6839\u636e\u6027\u80fd\u6307\u6807\u7684\u53d8\u5316\u8fdb\u884c\u8c03\u6574\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e00\u3001\u624b\u52a8\u6269\u7f29\u5bb9\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u67e5\u770b\u547d\u540d\u7a7a\u95f4update\u4e0b\u7684deploy\u63a7\u5236\u5668nginx-app\u4e0b\u7684pod\u526f\u672c\u6570\u91cf\u4e3a2\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"812\" height=\"224\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49.png\" alt=\"\" class=\"wp-image-5041\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49.png 812w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-300x83.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-768x212.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-600x166.png 600w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6269\u5bb9\uff1a<\/strong>\u901a\u8fc7kubectl scale\u547d\u4ee4\u53ef\u4ee5\u5c06Pod\u526f\u672c\u6570\u91cf\u4ece\u521d\u59cb\u76842\u4e2a\u66f4\u65b0\u4e3a3\u4e2a\uff0c\u5982\u56fe\uff1a <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"962\" height=\"251\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50.png\" alt=\"\" class=\"wp-image-5042\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50.png 962w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-300x78.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-768x200.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-600x157.png 600w\" sizes=\"auto, (max-width: 962px) 100vw, 962px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7f29\u5bb9\uff1a<\/strong>\u901a\u8fc7 kubectl scale\u547d\u4ee4\u53ef\u4ee5\u5c06Pod\u526f\u672c\u6570\u91cf\u4ece\u521d\u59cb\u76843\u4e2a\u7f29\u51cf\u4e3a1\u4e2a\uff0c\u5982\u56fe\uff1a <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"950\" height=\"118\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51.png\" alt=\"\" class=\"wp-image-5043\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51.png 950w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-300x37.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-768x95.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-600x75.png 600w\" sizes=\"auto, (max-width: 950px) 100vw, 950px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6b21\u67e5\u770b\u5df2\u7ecf\u7f29\u5bb9\u6210\u529f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"147\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52.png\" alt=\"\" class=\"wp-image-5044\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52.png 788w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-300x56.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-768x143.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-600x112.png 600w\" sizes=\"auto, (max-width: 788px) 100vw, 788px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4e8c\u3001\u81ea\u52a8\u6269\u7f29\u5bb9(<\/strong>Horizontal Pod Autoscaler<strong>)\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Horizontal Pod Autoscaler \u53ef\u4ee5\u6839\u636e CPU \u5229\u7528\u7387\u81ea\u52a8\u6269\u7f29 ReplicationController\u3001 Deployment\u3001ReplicaSet \u6216 StatefulSet \u4e2d\u7684 Pod \u6570\u91cf \uff08 \u9664\u4e86 CPU \u5229\u7528\u7387\uff0c\u4e5f\u53ef\u4ee5\u57fa\u4e8e\u5176\u4ed6\u5e94\u7a0b\u5e8f\u63d0\u4f9b\u7684&nbsp;<a href=\"https:\/\/git.k8s.io\/community\/contributors\/design-proposals\/instrumentation\/custom-metrics-api.md\">\u81ea\u5b9a\u4e49\u5ea6\u91cf\u6307\u6807<\/a>&nbsp;\u6765\u6267\u884c\u81ea\u52a8\u6269\uff09 Pod \u81ea\u52a8\u6269\u7f29\u4e0d\u9002\u7528\u4e8e\u65e0\u6cd5\u6269\u7f29\u7684\u5bf9\u8c61\uff0c\u6bd4\u5982 DaemonSet <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u539f\u7406\uff1a<\/strong>Kubernetes\u4e2d\u7684\u67d0\u4e2aMetrics Server\u6301\u7eed\u91c7\u96c6\u6240\u6709Pod\u526f\u672c\u7684\u6307\u6807\u6570\u636e\u3002HPA\u63a7\u5236\u5668\u901a\u8fc7Metrics Server\u7684API\u83b7\u53d6\u8fd9\u4e9b\u6570\u636e\uff0c\u57fa\u4e8e\u7528\u6237\u5b9a\u4e49<br>\u7684\u6269\u7f29\u5bb9\u89c4\u5219\u8fdb\u884c\u8ba1\u7b97\uff0c\u5f97\u5230\u76ee\u6807Pod\u7684\u526f\u672c\u6570\u91cf\u3002\u5f53\u76ee\u6807Pod\u526f\u672c\u6570\u91cf \u4e0e \u5f53 \u524d \u526f \u672c \u6570 \u91cf \u4e0d \u540c \u65f6 \uff0c HPA \u63a7 \u5236 \u5668 \u5c31 \u5411 Pod \u7684 \u526f \u672c \u63a7 \u5236 \u5668<br>\uff08Deployment\u3001RC\u6216ReplicaSet\uff09\u53d1\u8d77scale\u64cd\u4f5c\uff0c\u8c03\u6574Pod\u7684\u526f\u672c\u6570\u91cf\uff0c\u5b8c\u6210\u6269\u7f29\u5bb9\u64cd\u4f5c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"705\" height=\"333\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-1.png\" alt=\"\" class=\"wp-image-6260\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-1.png 705w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-1-300x142.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/01\/1-1-600x283.png 600w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>HPA\u6269\u7f29\u5bb9\u7b97\u6cd5\uff1a<\/strong>Autoscaler\u63a7\u5236\u5668\u4ece\u805a\u5408API\u83b7\u53d6\u5230Pod\u6027\u80fd\u6307\u6807\u6570\u636e\u4e4b\u540e\uff0c\u57fa\u4e8e\u4e0b\u9762\u7684\u7b97\u6cd5\u8ba1\u7b97\u51fa\u76ee\u6807Pod\u526f\u672c\u6570\u91cf\uff0c\u4e0e\u5f53\u524d\u8fd0\u884c\u7684Pod\u526f\u672c\u6570\u91cf\u8fdb\u884c\u5bf9\u6bd4\uff0c\u51b3\u5b9a\u662f\u5426\u9700\u8981\u8fdb\u884c\u6269\u7f29\u5bb9\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>\u671f\u671b\u526f\u672c\u6570 = ceil&#91;\u5f53\u524d\u526f\u672c\u6570 * ( \u5f53\u524d\u6307\u6807 \/ \u671f\u671b\u6307\u6807 )]<\/strong>\n\n\u4f8b\u5b50\uff1a\u4ee5CPU\u8bf7\u6c42\u6570\u91cf\u4e3a\u4f8b\uff0c\u5982\u679c\u7528\u6237\u8bbe\u7f6e\u7684\u671f\u671b\u6307\u6807\u503c\u4e3a100m\uff0c\u5f53\u524d\u5b9e\u9645\u4f7f\u7528\u7684\u6307\u6807\u503c\u4e3a200m\uff0c\u5219\u8ba1\u7b97\u5f97\u5230\u671f\u671b\u7684Pod\u526f\u672c\u6570\u91cf\u5e94\u4e3a\u4e24\u4e2a\n\uff08200\/100=2\uff09\u3002\u5982\u679c\u5f53\u524d\u5b9e\u9645\u4f7f\u7528\u7684\u6307\u6807\u503c\u4e3a50m\uff0c\u8ba1\u7b97\u7ed3\u679c\u4e3a0.5\uff0c\u5219\u5411\u4e0a\u53d6\u6574\uff0c\u503c\u4e3a1\uff0c\u5f97\u5230\u76ee\u6807Pod\u526f\u672c\u6570\u91cf\u5e94\u4e3a1\u4e2a\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u8ba1\u7b97\u7ed3\u679c\u4e0e1\u975e\u5e38\u63a5\u8fd1\u65f6\uff0c\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u5bb9\u5fcd\u5ea6\u8ba9\u7cfb\u7edf\u4e0d\u505a\u6269\u7f29\u5bb9 \u64cd \u4f5c \u3002 \u5bb9 \u5fcd \u5ea6 \u901a \u8fc7 kube-controller-manager \u670d \u52a1 \u7684 \u542f \u52a8 \u53c2 \u6570 &#8212;<br>horizontal-pod-autoscaler-tolerance\u8fdb\u884c\u8bbe\u7f6e\uff0c\u9ed8\u8ba4\u503c\u4e3a0.1\uff08\u537310%\uff09\uff0c\u8868\u793a\u57fa\u4e8e\u4e0a\u8ff0\u7b97\u6cd5\u5f97\u5230\u7684\u7ed3\u679c\u5728[-10%\uff0c+10%]\u533a\u95f4\u5185\uff0c\u5373[0.9\uff0c1.1]\u533a<br>\u95f4\uff0c\u63a7\u5236\u5668\u90fd\u4e0d\u4f1a\u8fdb\u884c\u6269\u7f29\u5bb9\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b58\u5728\u51e0\u79cdPod\u5f02\u5e38\u7684\u60c5\u51b5\uff0c\u5982\u4e0b\u6240\u8ff0\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pod\u6b63\u5728\u88ab\u5220\u9664\uff08\u8bbe\u7f6e\u4e86\u5220\u9664\u65f6\u95f4\u6233\uff09\uff1a\u5c06\u4e0d\u4f1a\u8ba1\u5165\u76ee\u6807Pod\u526f\u672c\u6570\u91cf\u3002<\/li>\n\n\n\n<li>Pod\u7684\u5f53\u524d\u6307\u6807\u503c\u65e0\u6cd5\u83b7\u5f97\uff1a\u672c\u6b21\u63a2\u6d4b\u4e0d\u4f1a\u5c06\u8fd9\u4e2aPod\u7eb3\u5165\u76ee\u6807Pod\u526f\u672c\u6570\u91cf\uff0c\u540e\u7eed\u7684\u63a2\u6d4b\u4f1a\u88ab\u91cd\u65b0\u7eb3\u5165\u8ba1\u7b97\u8303\u56f4<\/li>\n\n\n\n<li>\u5982\u679c\u6307\u6807\u7c7b\u578b\u662fCPU\u4f7f\u7528\u7387\uff0c\u5219\u5bf9\u4e8e\u6b63\u5728\u542f\u52a8\u4f46\u662f\u8fd8\u672a\u8fbe\u5230Ready\u72b6\u6001\u7684Pod\uff0c\u4e5f\u6682\u65f6\u4e0d\u4f1a\u7eb3\u5165\u76ee\u6807\u526f\u672c\u6570\u91cf\u8303\u56f4\u3002\u53ef\u4ee5\u901a\u8fc7kubecontroller-manager \u670d \u52a1 \u7684 \u542f \u52a8 \u53c2 \u6570 &#8211;horizontal-pod-autoscaler-initialreadiness-delay\u8bbe\u7f6e\u9996\u6b21\u63a2\u6d4bPod\u662f\u5426Ready\u7684\u5ef6\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba4\u503c\u4e3a30s\u3002\u53e6\u4e00\u4e2a\u542f\u52a8\u53c2\u6570&#8211;horizontal-pod-autoscaler-cpu-initialization-period\u8bbe\u7f6e\u9996\u6b21\u91c7\u96c6Pod\u7684CPU\u4f7f\u7528\u7387\u7684\u5ef6\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba45\u5206\u949f<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u6f14\u793a Horizontal Pod Autoscaler\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u57fa\u4e8e php-apache \u955c\u50cf\u7684 \u5b9a\u5236 Docker \u955c\u50cf\u3002Dockerfile \u5185\u5bb9\u5982\u4e0b\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM php:5-apache\nCOPY index.php \/var\/www\/html\/index.php\nRUN chmod a+rx index.php<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> \u8be5\u6587\u4ef6\u5b9a\u4e49\u4e86\u4e00\u4e2a index.php \u9875\u9762\u6765\u6267\u884c\u4e00\u4e9b CPU \u5bc6\u96c6\u578b\u8ba1\u7b97\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n  $x = 0.0001;\n  for ($i = 0; $i &lt;= 1000000; $i++) {\n    $x += sqrt($x);\n  }\n  echo \"OK!\";\n?&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\uff0c\u4f7f\u7528\u4e0b\u9762\u7684\u914d\u7f6e\u542f\u52a8\u4e00\u4e2a Deployment \u6765\u8fd0\u884c\u8fd9\u4e2a\u955c\u50cf\u5e76\u66b4\u9732\u4e00\u4e2a\u670d\u52a1\uff0c\u6587\u4ef6\u540d\u4e3aphp-apache.yaml\uff0c\u5982\u4e0b\uff1a <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: php-apache\nspec:\n  selector:\n    matchLabels:\n      run: php-apache\n  replicas: 1\n  template:\n    metadata:\n      labels:\n        run: php-apache\n    spec:\n      containers:\n      - name: php-apache\n        image: hpa-example\n        imagePullPolicy: Never      #\u4f7f\u7528\u672c\u5730\u955c\u50cf\n        ports:\n        - containerPort: 80\n        resources:\n          limits:\n            cpu: 500m\n            memory: 50Mi\n          requests:\n            cpu: 200m                #pod\u7684\u8bf7\u6c42cpu\u4e3a200\u6beb\u6838\n            memory: 25Mi\n---\napiVersion: v1\nkind: Service\nmetadata:\n  name: php-apache\n  labels:\n    run: php-apache\nspec:\n  ports:\n  - port: 80\n  selector:\n    run: php-apache\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u547d\u4ee4\u521b\u5efadeployment\uff0ckubectl create -f php-apache.yaml\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"836\" height=\"186\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/41-1.png\" alt=\"\" class=\"wp-image-5134\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/41-1.png 836w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/41-1-300x67.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/41-1-768x171.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/41-1-600x133.png 600w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u521b\u5efa Horizontal Pod Autoscaler(<strong>\u6839\u636ecpu\u6765\u5b9e\u73b0\u81ea\u52a8\u6269\u7f29\u5bb9<\/strong>)\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">php-apache \u670d\u52a1\u5668\u5df2\u7ecf\u8fd0\u884c\uff0c\u63a5\u4e0b\u6765\u521b\u5efa Horizontal Pod Autoscaler\u3002 \u4ee5\u4e0b\u4e24\u79cd\u65b9\u5f0f\u5c06\u521b\u5efa\u4e00\u4e2a Horizontal Pod Autoscaler \u7528\u4e8e\u63a7\u5236\u6211\u4eec\u4e0a\u4e00\u6b65\u9aa4\u4e2d\u521b\u5efa\u7684 Deployment\uff0c\u6839\u636e<strong>cpu\u7684\u4f7f\u7528\u7387<\/strong>\u6765\u63a7\u5236 Pod \u7684\u526f\u672c\u6570\u91cf\u7ef4\u6301\u5728 1 \u5230 5\u4e4b\u95f4\u3002 \u5927\u81f4\u6765\u8bf4\uff0cHPA \u901a\u8fc7 Deployment \u589e\u52a0\u6216\u8005\u51cf\u5c11 Pod \u526f\u672c\u7684\u6570\u91cf\u4ee5\u4fdd\u6301\u6240\u6709 Pod \u7684\u5e73\u5747 CPU \u5229\u7528\u7387\u5728 10% \u5de6\u53f3\uff08\u4f8b\u5982\u6bcf\u4e2a Pod \u8bf7\u6c42 200 \u6beb\u6838\u7684 CPU\uff0c\u5982\u679c\u6269\u5bb9\u4e3a2\u4e2apod\u8fd9\u610f\u5473\u7740\u5e73\u5747 \u6bcf\u4e2apod\u7684CPU \u7528\u91cf\u4e3a 100 \u6beb\u6838\uff09 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e00\u79cd\u65b9\u5f0f\uff1a<\/strong>\u76f4\u63a5\u4f7f\u7528kubectl autoscale\u6765\u521b\u5efahpa\uff0c\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>kubectl autoscale deployment php-apache --cpu-percent=10 --min=1 --max=<\/code>5<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u8be2\u521b\u5efa\u540e\u7684hpa\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"809\" height=\"160\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/43-1.png\" alt=\"\" class=\"wp-image-5138\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/43-1.png 809w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/43-1-300x59.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/43-1-768x152.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/43-1-600x119.png 600w\" sizes=\"auto, (max-width: 809px) 100vw, 809px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"> \u8bf7\u6ce8\u610f\u5f53\u524d\u7684 CPU \u5229\u7528\u7387\u662f 0%\uff0c\u8fd9\u662f\u7531\u4e8e\u6211\u4eec\u5c1a\u672a\u53d1\u9001\u4efb\u4f55\u8bf7\u6c42\u5230\u670d\u52a1\u5668&nbsp; <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7b2c\u4e8c\u79cd\u65b9\u5f0f\uff1a<\/strong>\u901a\u8fc7yaml\u6587\u4ef6\u5f62\u5f0f\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"466\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/48-1.png\" alt=\"\" class=\"wp-image-5140\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/48-1.png 930w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/48-1-300x150.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/48-1-768x385.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/48-1-600x301.png 600w\" sizes=\"auto, (max-width: 930px) 100vw, 930px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\u770b\u6587\u4ef6\u5f00\u5934\u7684api\u7248\u672c\u4e3aautoscaling\/v2beta2\uff0c\u6b64\u7248\u672c\u53ef\u4ee5\u57fa\u4e8e\u591a\u9879\u5ea6\u91cf\u6307\u6807\u548c\u81ea\u5b9a\u4e49\u5ea6\u91cf\u6307\u6807\u81ea\u52a8\u6269\u7f29<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u6d4b\u8bd5HPA\uff0c \u542f\u52a8\u4e00\u4e2a\u5bb9\u5668\uff0c\u5e76\u901a\u8fc7\u4e00\u4e2a\u5faa\u73af\u5411 php-apache \u670d\u52a1\u5668\u53d1\u9001\u65e0\u9650\u7684\u67e5\u8be2\u8bf7\u6c42 \uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl run -i --tty load-generator --rm --image=busybox --restart=Never -- \/bin\/sh -c \"while sleep 0.01; do wget -q -O- http:\/\/php-apache; done\"<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"> \u4e00\u5206\u949f\u65f6\u95f4\u5de6\u53f3\u4e4b\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u5230 CPU \u8d1f\u8f7d\u5347\u9ad8\u4e86\uff0ccpu\u5229\u7528\u7387\u5347\u9ad8\u7684\u6bd4\u4f8b\u8d85\u8fc7\u4e86\u9884\u8bbe\u768410%\uff0c\u4f1a\u89e6\u53d1\u81ea\u52a8\u6269\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"763\" height=\"176\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/45-1.png\" alt=\"\" class=\"wp-image-5141\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/45-1.png 763w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/45-1-300x69.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/45-1-600x138.png 600w\" sizes=\"auto, (max-width: 763px) 100vw, 763px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u65f6\u67e5\u770b\u526f\u672c\u6570\u5df2\u5b9e\u73b0\u81ea\u52a8\u6269\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"894\" height=\"207\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/46-1.png\" alt=\"\" class=\"wp-image-5142\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/46-1.png 894w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/46-1-300x69.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/46-1-768x178.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/46-1-600x139.png 600w\" sizes=\"auto, (max-width: 894px) 100vw, 894px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6269\u5bb9\u4e3a2\u4e2a\u526f\u672c\u540e\uff0c\u6b64\u65f6\u67e5\u770bpod\u7684\u5e73\u5747\u4f7f\u7528\u7387\u4e3a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"845\" height=\"180\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-1.png\" alt=\"\" class=\"wp-image-5144\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-1.png 845w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-1-300x64.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-1-768x164.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/49-1-600x128.png 600w\" sizes=\"auto, (max-width: 845px) 100vw, 845px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u770b\u5230\u5f53\u524d\u7684Pod\u5e73\u5747cpu\u4f7f\u7528\u7387\u4e3a6%\uff0c\u4e5f\u5c31\u662f\u8bf7\u6c42\u7684cpu\u76846%\uff0c\u4e0a\u56fe\u4e2d\u8bbe\u7f6e\u7684\u8bf7\u6c42cpu\u4e3a200m\uff0c\u90a3\u4e48200\u76846%\u5de6\u53f3\u5373\u4e3a\u5982\u4e0b\u56fe\u6240\u793a\u7684\u7528\u91cf\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"834\" height=\"216\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/47.png\" alt=\"\" class=\"wp-image-5143\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/47.png 834w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/47-300x78.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/47-768x199.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/47-600x155.png 600w\" sizes=\"auto, (max-width: 834px) 100vw, 834px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u8bf7\u6c42\u505c\u6b62\u540e\uff0c\u89c2\u5bdfkubectl get hpa\u4e2d\u7684cpu\u4f7f\u7528\u7387\u5df2\u7ecf\u4e0b\u964d\uff0c\u5e76\u4e14pod\u526f\u672c\u5df2\u81ea\u52a8\u964d\u4f4e\u4e3a1\u4e2a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"752\" height=\"195\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-1.png\" alt=\"\" class=\"wp-image-5147\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-1.png 752w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-1-300x78.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/50-1-600x156.png 600w\" sizes=\"auto, (max-width: 752px) 100vw, 752px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001 \u521b\u5efa Horizontal Pod Autoscaler(<strong>\u6839\u636e\u5185\u5b58\u6765\u5b9e\u73b0\u81ea\u52a8\u6269\u7f29\u5bb9<\/strong>)\uff1a <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u8f91hpa-php.yaml\u6587\u4ef6\uff0c\u6dfb\u52a0\u5185\u5b58\u6307\u6807\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"609\" height=\"405\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-1.png\" alt=\"\" class=\"wp-image-5153\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-1.png 609w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-1-300x200.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/51-1-600x399.png 600w\" sizes=\"auto, (max-width: 609px) 100vw, 609px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u547d\u4ee4kubectl apply -f hpa-php.yaml\u521b\u5efa\u8d44\u6e90\u5e76\u67e5\u770b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"569\" height=\"115\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-1.png\" alt=\"\" class=\"wp-image-5154\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-1.png 569w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/52-1-300x61.png 300w\" sizes=\"auto, (max-width: 569px) 100vw, 569px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u4e2d\u53ef\u4ee5\u770b\u51fa\uff0c\u5185\u5b58\u4f7f\u7528\u7387\u5df2\u7ecf\u8fbe\u5230\u4e8679%\uff0c\u8d85\u8fc7\u4e86\u8bbe\u5b9a\u7684\u503c\uff0c\u6b64\u65f6\u4f1a\u89e6\u53d1\u6269\u5bb9\uff0c\u67e5\u770bpod\u6570\u91cf\uff0c\u53d1\u73b0\u5df2\u7ecf\u6269\u5bb9\u5230\u4e86\u4e0a\u96505\u4e2a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"613\" height=\"182\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/53-1.png\" alt=\"\" class=\"wp-image-5155\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/53-1.png 613w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/53-1-300x89.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/53-1-600x178.png 600w\" sizes=\"auto, (max-width: 613px) 100vw, 613px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770bPod\u7684\u5185\u5b58\u8d44\u6e90\u5229\u7528\u7387\u53ef\u4ee5\u53d1\u73b0\uff0c\u5e73\u5747\u5185\u5b58\u5229\u7528\u7387\u8fd8\u662f\u8d85\u8fc750%(\u8bf7\u6c42\u8d44\u6e90\u4e3a25Mi\uff0c\u4e0a\u9762\u7684\u8d44\u6e90\u5b9a\u4e49\u6587\u4ef6\u4e2d\u6709\u914d\u7f6e)\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"571\" height=\"167\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/54-1.png\" alt=\"\" class=\"wp-image-5157\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/54-1.png 571w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/54-1-300x88.png 300w\" sizes=\"auto, (max-width: 571px) 100vw, 571px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8ehpa-php.yaml\u4e2d\u8bbe\u5b9a\u7684Pod\u6700\u5927\u526f\u672c\u6570\u91cf\u4e3a5\uff0c\u56e0\u6b64\u5bfc\u81f4\u65e0\u6cd5\u57fa\u7840\u6269\u5bb9\uff0c\u6b64\u65f6\u53ef\u4ee5\u4fee\u6539\u6700\u5927\u6570\u91cf\u4e3a10 \uff0c\u7136\u540e\u89c2\u5bdf\u526f\u672c\u53d8\u5316\uff0c\u53d1\u73b0\u53c8\u7ee7\u7eed\u6269\u5bb9\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"624\" height=\"263\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/55-1.png\" alt=\"\" class=\"wp-image-5159\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/55-1.png 624w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/55-1-300x126.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/55-1-600x253.png 600w\" sizes=\"auto, (max-width: 624px) 100vw, 624px\" \/><\/figure>\n\n\n\n<p class=\"has-white-background-color has-background wp-block-paragraph\">\u9664\u4e86HPA\u5916\uff0c\u8fd8\u6709VPA(Vertical Pod Autoscaler)\uff0c\u5373\u5782\u76f4Pod\u81ea\u52a8\u6269\u7f29\u5bb9\uff0c\u5b83\u6839\u636e\u5bb9\u5668\u8d44\u6e90\u4f7f\u7528\u7387\u81ea\u52a8\u63a8\u6d4b\u5e76\u8bbe\u7f6ePod\u5408\u7406\u7684CPU\u548c\u5185\u5b58\u7684\u9700\u6c42\u6307\u6807\uff0c\u4ece\u800c\u66f4\u52a0\u7cbe\u786e\u5730\u8c03\u5ea6Pod\uff0c\u5b9e\u73b0\u6574\u4f53\u4e0a\u8282\u7701\u96c6\u7fa4\u8d44\u6e90\u7684\u76ee\u6807\uff0c\u56e0\u4e3a\u65e0\u987b\u4eba\u4e3a\u64cd\u4f5c\uff0c\u56e0\u6b64\u4e5f\u8fdb\u4e00\u6b65\u63d0\u5347\u4e86\u8fd0\u7ef4\u81ea\u52a8\u5316\u7684\u6c34\u5e73\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\uff1a\u5982\u679c\u5f00\u542f\u4e86\u81ea\u52a8\u6269\u7f29\u5bb9\uff0c\u90a3\u4e48\u5728\u521b\u5efapod\u7684\u65f6\u5019\uff0c\u5c31\u4e0d\u9700\u8981\u8bbe\u7f6ereplicas\u53c2\u6570\u4e86\uff0c\u6b64\u65f6\u9ed8\u8ba4\u7684pod\u6570\u91cf\u4e3a1<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes\u5bf9Pod\u7684\u6269\u7f29\u5bb9\u64cd\u4f5c\u63d0\u4f9b\u4e86\u624b\u52a8\u548c\u81ea\u52a8\u4e24\u79cd\u6a21\u5f0f\uff0c\u624b\u52a8\u6a21\u5f0f\u901a\u8fc7\u6267\u884ckubectl scale\u547d [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":5046,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93,23],"tags":[],"class_list":["post-5040","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes","category-rong"],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":8}},"_links":{"self":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/5040","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/comments?post=5040"}],"version-history":[{"count":22,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/5040\/revisions"}],"predecessor-version":[{"id":19434,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/5040\/revisions\/19434"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/5046"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=5040"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=5040"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=5040"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}