{"id":2786,"date":"2023-10-10T14:14:56","date_gmt":"2023-10-10T06:14:56","guid":{"rendered":"https:\/\/199604.com\/?p=2786"},"modified":"2023-10-10T14:14:56","modified_gmt":"2023-10-10T06:14:56","slug":"kubernetes-vpa%ef%bc%88pod%e7%ba%b5%e5%90%91%e8%87%aa%e5%8a%a8%e6%89%a9%e7%bc%a9%ef%bc%89","status":"publish","type":"post","link":"https:\/\/199604.com\/2786","title":{"rendered":"Kubernetes VPA\uff08Pod\u7eb5\u5411\u81ea\u52a8\u6269\u7f29\uff09"},"content":{"rendered":"<h1>Kubernetes VPA\uff08Pod\u7eb5\u5411\u81ea\u52a8\u6269\u7f29\uff09<\/h1>\n<h2>GPT\u4ecb\u7ecd<\/h2>\n<p>Kubernetes VPA\uff08Vertical Pod Autoscaler\uff09\u662fKubernetes\u7684\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u5177\u6709\u4ee5\u4e0b\u7279\u70b9\uff1a<\/p>\n<ol>\n<li>\u81ea\u52a8\u5782\u76f4\u6269\u7f29\u5bb9\uff1aVPA\u80fd\u591f\u6839\u636ePod\u7684\u5b9e\u9645\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\u81ea\u52a8\u8c03\u6574\u5176\u8d44\u6e90\u8bf7\u6c42\u548c\u9650\u5236\u3002\u5b83\u4f1a\u5206\u6790\u5386\u53f2\u7684\u4f7f\u7528\u6a21\u5f0f\uff0c\u5e76\u6839\u636e\u9700\u6c42\u52a8\u6001\u5730\u8c03\u6574Pod\u7684\u8d44\u6e90\u914d\u7f6e\uff0c\u4ece\u800c\u5b9e\u73b0\u8d44\u6e90\u7684\u81ea\u52a8\u5782\u76f4\u6269\u7f29\u5bb9\u3002<\/li>\n<li>\u8d44\u6e90\u4f18\u5316\uff1aVPA\u65e8\u5728\u4f18\u5316\u96c6\u7fa4\u5185\u7684\u8d44\u6e90\u5206\u914d\uff0c\u786e\u4fddPod\u80fd\u591f\u83b7\u5f97\u6240\u9700\u7684\u8d44\u6e90\u3002\u5b83\u901a\u8fc7\u6839\u636e\u5b9e\u9645\u9700\u6c42\u8c03\u6574\u8d44\u6e90\u8bf7\u6c42\u548c\u9650\u5236\uff0c\u53ef\u4ee5\u907f\u514d\u8d44\u6e90\u7684\u8fc7\u5ea6\u6216\u4e0d\u8db3\u5206\u914d\uff0c\u63d0\u9ad8\u96c6\u7fa4\u7684\u8d44\u6e90\u5229\u7528\u7387\u3002<\/li>\n<li>\u9002\u5e94\u5de5\u4f5c\u8d1f\u8f7d\u6ce2\u52a8\uff1a\u4f20\u7edf\u7684\u8d44\u6e90\u8bf7\u6c42\u548c\u9650\u5236\u662f\u9759\u6001\u914d\u7f6e\uff0c\u65e0\u6cd5\u9002\u5e94\u5de5\u4f5c\u8d1f\u8f7d\u7684\u6ce2\u52a8\u548c\u8d44\u6e90\u9700\u6c42\u7684\u53d8\u5316\u3002VPA\u901a\u8fc7\u52a8\u6001\u8c03\u6574\u8d44\u6e90\u914d\u7f6e\uff0c\u53ef\u4ee5\u6839\u636e\u8d1f\u8f7d\u7684\u53d8\u5316\u81ea\u52a8\u8c03\u6574Pod\u7684\u8d44\u6e90\u3002<\/li>\n<li>\u652f\u6301\u591a\u79cd\u8d44\u6e90\u7c7b\u578b\uff1aVPA\u4e0d\u4ec5\u652f\u6301CPU\u548c\u5185\u5b58\u8d44\u6e90\u7684\u8c03\u6574\uff0c\u8fd8\u53ef\u4ee5\u5e94\u7528\u4e8e\u5176\u4ed6\u81ea\u5b9a\u4e49\u7684\u8d44\u6e90\u7c7b\u578b\u3002\u8fd9\u4f7f\u5f97\u5b83\u5728\u4e0d\u540c\u7c7b\u578b\u7684\u5de5\u4f5c\u8d1f\u8f7d\u548c\u5e94\u7528\u573a\u666f\u4e2d\u90fd\u5177\u6709\u5e7f\u6cdb\u7684\u9002\u7528\u6027\u3002<\/li>\n<li>\u914d\u7f6e\u7075\u6d3b\u6027\uff1aVPA\u63d0\u4f9b\u4e86\u5404\u79cd\u914d\u7f6e\u9009\u9879\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u8fdb\u884c\u7075\u6d3b\u7684\u8c03\u6574\u3002\u53ef\u4ee5\u8bbe\u7f6e\u8c03\u6574\u7684\u9891\u7387\u3001\u8c03\u6574\u7b56\u7565\u3001\u76ee\u6807\u8d44\u6e90\u4f7f\u7528\u7387\u7b49\u53c2\u6570\uff0c\u4ee5\u6ee1\u8db3\u4e0d\u540c\u7684\u9700\u6c42\u548c\u4f18\u5316\u76ee\u6807\u3002<\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0cKubernetes VPA\u901a\u8fc7\u81ea\u52a8\u5206\u6790\u548c\u8c03\u6574Pod\u7684\u8d44\u6e90\u914d\u7f6e\uff0c\u5b9e\u73b0\u4e86\u8d44\u6e90\u7684\u81ea\u52a8\u4f18\u5316\u548c\u5782\u76f4\u6269\u7f29\u5bb9\uff0c\u63d0\u9ad8\u4e86\u96c6\u7fa4\u7684\u8d44\u6e90\u5229\u7528\u7387\u548c\u5e94\u7528\u7684\u6027\u80fd\u3002<\/p>\n<h2>\u7b80\u4ecb<\/h2>\n<p>HPA\u4e00\u822c\u88ab\u79f0\u4e3a\u6a2a\u5411\u6269\u5c55\uff0c\u4e0eHPA\u4e0d\u540c\u7684Vertical Pod Autoscaler ( VPA ) \u4f1a\u81ea\u52a8\u8c03\u6574 Pod \u7684 CPU \u548c\u5185\u5b58\u5c5e\u6027\uff0c\u88ab\u79f0\u4e3a\u7eb5\u5411\u6269\u5c55\u3002VPA\u53ef\u4ee5\u7ed9\u51fa\u670d\u52a1\u8fd0\u884c\u6240\u9002\u5408\u7684CPU\u548c\u5185\u5b58\u914d\u7f6e\uff0c\u7701\u53bb\u4f30\u8ba1\u670d\u52a1\u5360\u7528\u8d44\u6e90\u7684\u65f6\u95f4\uff0c\u66f4\u5408\u7406\u7684\u4f7f\u7528\u8d44\u6e90\u3002\u5f53\u7136\uff0cVPA\u4e5f\u53ef\u6839\u636e\u8d44\u6e90\u7684\u4f7f\u7528\u60c5\u51b5\u201c\u8c03\u6574\u201dpod\u7684\u8d44\u6e90\u3002\u8fd9\u91cc\u7684\u8c03\u6574\u6211\u4eec\u7528\u4e86\u53cc\u5f15\u53f7\uff0c\u56e0\u4e3a\u4ed6\u7684\u5b9e\u73b0\u673a\u5236\u662f\u91cd\u5efa\u800c\u4e0d\u662f\u52a8\u6001\u589e\u52a0\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u5b9e\u9645\u7684\u4f8b\u5b50\uff1a\u5047\u8bbe\u6211\u7684<code>memory limits<\/code>\u662f100Mi\uff0c\u4f46\u662f\u73b0\u5728\u5df2\u7ecf\u7528\u5230\u4e8698Mi\uff0c\u5982\u679c\u518d\u5927\u7684\u8bdd\u5c31oom\u4e86\uff0c\u6b64\u65f6vpa\u4f1a\u5728\u5782\u76f4\u65b9\u5411\u4e0a\u63d0\u5347\u4f60\u7684<code>memory limits<\/code>\u7684\u5927\u5c0f\u3002\u8fd9\u79cdvpa\u6bd4\u8f83\u9002\u5408\u4e00\u4e9b\u8d44\u6e90\u6d88\u8017\u6bd4\u8f83\u5927\u7684\u5e94\u7528\uff0c\u4f8b\u5982es\uff0c\u4f60\u7ed9\u5927\u4e86\u8d44\u6e90\u6d6a\u8d39\uff0c\u7ed9\u5c0f\u4e86\uff0c\u53c8\u4e0d\u591f\u3002\u6240\u4ee5vpa\u5c31\u6d3e\u4e0a\u7528\u573a\u4e86\u3002\u5f53\u7136\uff0cvpa\u4e0d\u50cfhpa\u9ed8\u8ba4\u96c6\u6210\u5728k8s\u91cc\u9762\u7684\uff0c\u9700\u8981\u4f60\u81ea\u5df1\u53bb\u914d\u7f6e\u7684\u3002<\/p>\n<h2>VPA \u4e0e HPA<\/h2>\n<p>\u4ece\u6839\u672c\u4e0a\u6765\u8bf4\uff0cVPA \u548c HPA \u4e4b\u95f4\u7684\u533a\u522b\u5728\u4e8e\u5b83\u4eec\u7684\u6269\u5c55\u65b9\u5f0f\u3002HPA \u901a\u8fc7\u6dfb\u52a0\u6216\u5220\u9664pod\u8fdb\u884c\u6269\u5c55\uff0c\u4ece\u800c\u6c34\u5e73\u6269\u5c55\u5bb9\u91cf\u3002\u7136\u800c\uff0cVPA \u901a\u8fc7\u589e\u52a0\u6216\u51cf\u5c11\u73b0\u6709 Pod \u5bb9\u5668\u5185\u7684 CPU \u548c\u5185\u5b58\u8d44\u6e90\u6765\u8fdb\u884c\u6269\u5c55\uff0c\u4ece\u800c\u5782\u76f4\u6269\u5c55\u5bb9\u91cf\u3002\u4e0b\u8868\u66f4\u8be6\u7ec6\u5730\u89e3\u91ca\u4e86 Kubernetes VPA \u548c HPA \u4e4b\u95f4\u7684\u5dee\u5f02\u3002<\/p>\n<table>\n<thead>\n<tr>\n<th>\u9700\u8981\u8c03\u6574\u5bb9\u91cf<\/th>\n<th>\u6c34\u5e73\u7f29\u653e (HPA)<\/th>\n<th>\u5782\u76f4\u7f29\u653e (VPA)<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u66f4\u591a\u8d44\u6e90<\/td>\n<td>\u6dfb\u52a0\u66f4\u591a Pod<\/td>\n<td>\u589e\u52a0\u73b0\u6709 pod \u5bb9\u5668\u7684 CPU \u6216\u5185\u5b58\u8d44\u6e90<\/td>\n<\/tr>\n<tr>\n<td>\u8d44\u6e90\u8f83\u5c11<\/td>\n<td>\u5220\u9664 Pod<\/td>\n<td>\u51cf\u5c11\u73b0\u6709 Pod \u5bb9\u5668\u7684 CPU \u6216\u5185\u5b58\u8d44\u6e90<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u5de5\u4f5c\u539f\u7406<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/qn.199604.com\/typoraImg\/b74b6433538fa3e882494623cc68a0e6a479e5.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/qn.199604.com\/typoraImg\/b74b6433538fa3e882494623cc68a0e6a479e5.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\u56fe\u7247\" \/><\/div><\/p>\n<h2>VPA \u7684\u7ec4\u6210\u90e8\u5206<\/h2>\n<p>VPA \u90e8\u7f72\u5177\u6709\u4e09\u4e2a\u4e3b\u8981\u7ec4\u4ef6\uff1a<code>VPA Recommender<\/code>\u3001<code>VPA Updater<\/code>\u548c<code>VPA Admission Controller<\/code>\u3002\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u4f5c\u7528\u3002<code>VPA Recommender<\/code>\uff1a<\/p>\n<ul>\n<li>\u76d1\u63a7\u8d44\u6e90\u5229\u7528\u7387\u5e76\u8ba1\u7b97\u76ee\u6807\u503c\u3002<\/li>\n<li>\u67e5\u770b\u6307\u6807\u5386\u53f2\u8bb0\u5f55\u3001OOM \u4e8b\u4ef6\u548c VPA \u90e8\u7f72\u89c4\u8303\u5e76\u5efa\u8bae\u516c\u5e73\u8bf7\u6c42\u3002\u6839\u636e\u5b9a\u4e49\u7684\u9650\u5236\u8bf7\u6c42\u6bd4\u4f8b\u63d0\u9ad8\/\u964d\u4f4e\u9650\u5236\u3002<\/li>\n<\/ul>\n<p><code>VPA \u66f4\u65b0\u7a0b\u5e8f<\/code>\uff1a<\/p>\n<ul>\n<li>\u9a71\u9010\u90a3\u4e9b\u9700\u8981\u65b0\u8d44\u6e90\u9650\u5236\u7684 Pod\u3002<\/li>\n<li>\u5982\u679c\u5b9a\u4e49\u4e86<code>\u201cupdateMode: Auto\u201d<\/code>\uff0c\u5219\u5b9e\u73b0\u63a8\u8350\u5668\u5efa\u8bae\u7684\u4efb\u4f55\u5185\u5bb9\u3002<\/li>\n<\/ul>\n<p><code>VPA \u51c6\u5165\u63a7\u5236\u5668<\/code>\uff1a<\/p>\n<ul>\n<li>\u6bcf\u5f53 VPA \u66f4\u65b0\u7a0b\u5e8f\u9010\u51fa\u5e76\u91cd\u65b0\u542f\u52a8 Pod \u65f6\uff0c\u90fd\u4f1a\u5728\u65b0 Pod \u542f\u52a8\u4e4b\u524d\u66f4\u6539 CPU \u548c\u5185\u5b58\u8bbe\u7f6e\uff08\u4f7f\u7528 Webhook\uff09\u3002<\/li>\n<li>\u5f53<code>Vertical Pod Autoscaler<\/code>\u8bbe\u7f6e\u4e3a\u201cAuto\u201d\u7684 <code>updateMode<\/code> \u65f6\uff0c\u5982\u679c\u9700\u8981\u66f4\u6539 Pod \u7684\u8d44\u6e90\u8bf7\u6c42\uff0c\u5219\u9a71\u9010 Pod\u3002\u7531\u4e8e Kubernetes \u7684\u8bbe\u8ba1\uff0c\u4fee\u6539\u6b63\u5728\u8fd0\u884c\u7684 pod \u7684\u8d44\u6e90\u8bf7\u6c42\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u91cd\u65b0\u521b\u5efa pod\u3002<\/li>\n<\/ul>\n<h2>Kubernetes VPA \u5de5\u4f5c\u6a21\u5f0f<\/h2>\n<p><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/qn.199604.com\/typoraImg\/f2f1b61002e6ec18ad1679404ec9f9d1931d6b.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/qn.199604.com\/typoraImg\/f2f1b61002e6ec18ad1679404ec9f9d1931d6b.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"img\" \/><\/div><\/p>\n<ol>\n<li>\u7528\u6237\u914d\u7f6eVPA\u3002<\/li>\n<li>VPA Recommender \u4ece\u6307\u6807\u670d\u52a1\u5668\u8bfb\u53d6 VPA \u914d\u7f6e\u548c\u8d44\u6e90\u5229\u7528\u7387\u6307\u6807\u3002<\/li>\n<li>VPA Recommender \u63d0\u4f9b Pod \u8d44\u6e90\u63a8\u8350\u3002<\/li>\n<li>VPA Updater \u8bfb\u53d6 Pod \u8d44\u6e90\u5efa\u8bae\u3002<\/li>\n<li>VPA Updater \u542f\u52a8 Pod \u7ec8\u6b62\u3002<\/li>\n<li>\u90e8\u7f72\u610f\u8bc6\u5230 Pod \u5df2\u7ec8\u6b62\uff0c\u5e76\u5c06\u91cd\u65b0\u521b\u5efa Pod \u4ee5\u5339\u914d\u5176\u526f\u672c\u914d\u7f6e\u3002<\/li>\n<li>\u5f53 Pod \u5904\u4e8e\u91cd\u65b0\u521b\u5efa\u8fc7\u7a0b\u4e2d\u65f6\uff0cVPA \u51c6\u5165\u63a7\u5236\u5668\u4f1a\u83b7\u53d6 Pod \u8d44\u6e90\u63a8\u8350\u3002\u7531\u4e8e Kubernetes \u4e0d\u652f\u6301\u52a8\u6001\u66f4\u6539\u6b63\u5728\u8fd0\u884c\u7684 pod \u7684\u8d44\u6e90\u9650\u5236\uff0c\u56e0\u6b64 VPA \u65e0\u6cd5\u4f7f\u7528\u65b0\u7684\u9650\u5236\u66f4\u65b0\u73b0\u6709 pod\u3002\u5b83\u4f1a\u7ec8\u6b62\u4f7f\u7528\u8fc7\u65f6\u9650\u5236\u7684 pod\u3002\u5f53 Pod \u7684\u63a7\u5236\u5668\u5411 Kubernetes API \u670d\u52a1\u8bf7\u6c42\u66ff\u6362\u65f6\uff0cVPA \u51c6\u5165\u63a7\u5236\u5668\u4f1a\u5c06\u66f4\u65b0\u7684\u8d44\u6e90\u8bf7\u6c42\u548c\u9650\u5236\u503c\u6ce8\u5165\u5230\u65b0 Pod \u7684\u89c4\u8303\u4e2d\u3002<\/li>\n<li>\u6700\u540e\uff0cVPA \u51c6\u5165\u63a7\u5236\u5668\u4f1a\u8986\u76d6\u5bf9 Pod \u7684\u5efa\u8bae\u3002<\/li>\n<\/ol>\n<h2>\u6700\u4f73\u5b9e\u8df5<\/h2>\n<p>\u65e2\u7136\u4f60\u77e5\u9053\u4e86\u5927\u81f4\u539f\u7406\uff0c\u8ba9\u6211\u4eec\u5f00\u59cb\u52a8\u624b\u64cd\u4f5c\u4f60\u5427<\/p>\n<pre><code class=\"language-shell \">\u514b\u9686\u4ee3\u7801\n# git clone https:\/\/github.com\/kubernetes\/autoscaler.git\n\n\u7531\u4e8e\u67d0\u4e9b\u539f\u56e0\u62c9\u4e0d\u5230\u955c\u50cf\uff0c\u6539yaml\u4fee\u6539\u4f18\u5148\u4f7f\u7528\u672c\u5730\u955c\u50cf\n# cd autoscaler\/vertical-pod-autoscaler\/deploy\n# sed -i 's\/Always\/IfNotPresent\/g'  recommender-deployment.yaml\n# sed -i 's\/Always\/IfNotPresent\/g'  admission-controller-deployment.yaml\n# sed -i 's\/Always\/IfNotPresent\/g'  updater-deployment.yaml\n\n# \u62c9\u53d6\u955c\u50cf\n# docker pull giantswarm\/vpa-admission-controller:0.14.0\n# docker pull giantswarm\/vpa-recommender:0.14.0\n# docker pull giantswarm\/vpa-updater:0.14.0\n\n\n# \u4fee\u6539tag\n# docker tag giantswarm\/vpa-updater:0.14.0 registry.k8s.io\/autoscaling\/vpa-updater:0.14.0\n# docker tag giantswarm\/vpa-recommender:0.14.0 registry.k8s.io\/autoscaling\/vpa-recommender:0.14.0\n# docker tag giantswarm\/vpa-admission-controller:0.14.0 registry.k8s.io\/autoscaling\/vpa-admission-controller:0.14.0\n\n# cd autoscaler\/vertical-pod-autoscaler\/hack\n\n# \u5b89\u88c5\u811a\u672c\u5b89\u88c5\u4e4b\u524d\u4fdd\u8bc1\u4f60\u7684K8S\u96c6\u7fa4\u7684metrics-server\u5df2\u5b89\u88c5\uff0c\u5e76\u4e14openssl\u5347\u7ea7\u52301.1.1\u6216\u66f4\u9ad8\u7248\u672c\n# .\/vpa-up.sh\n<\/code><\/pre>\n<h3>\u7b49\u5f85\u5b89\u88c5\u5b8c\u6210<\/h3>\n<pre><code class=\"language-shell \"># kubectl get pods -n kube-system | grep vpa\nkube-system     vpa-admission-controller-75bffbf8d8-6hxqq          1\/1     Running     0               5m9s\nkube-system     vpa-recommender-748c55b5bf-kqqjc                   1\/1     Running     0               4m34s\nkube-system     vpa-updater-679d5dcdd6-lslc7                       1\/1     Running     0               4m15s\n<\/code><\/pre>\n<p>\u4f7f\u7528VPA\uff0c\u60a8\u9700\u8981\u4e3a\u8981\u81ea\u52a8\u8ba1\u7b97\u8d44\u6e90\u9700\u6c42\u7684\u6bcf\u4e2a\u63a7\u5236\u5668\u63d2\u5165\u4e00\u4e2aVertical Pod Autoscaler\u8d44\u6e90\u3002\u8fd9\u5c06\u662f\u6700\u5e38\u89c1\u7684Deployment\u3002<\/p>\n<h3>VPA\u6709\u56db\u79cd\u8fd0\u884c\u6a21\u5f0f<\/h3>\n<ul>\n<li>&#8220;Auto&#8221;\uff1aVPA \u5728\u521b\u5efa pod \u65f6\u5206\u914d\u8d44\u6e90\u8bf7\u6c42\uff0c\u5e76\u4f7f\u7528\u9996\u9009\u66f4\u65b0\u673a\u5236\u5728\u73b0\u6709 pod \u4e0a\u66f4\u65b0\u5b83\u4eec\u3002\u76ee\u524d\u8fd9\u76f8\u5f53\u4e8e&#8221;Recreate&#8221;\uff08\u89c1\u4e0b\u6587\uff09\u3002\u4e00\u65e6 pod \u8bf7\u6c42\u7684\u514d\u91cd\u542f\uff08\u201c\u5c31\u5730\u201d\uff09\u66f4\u65b0\u53ef\u7528\uff0c\u5b83\u53ef\u80fd\u4f1a\u88ab\u8be5&#8221;Auto&#8221;\u6a21\u5f0f\u7528\u4f5c\u9996\u9009\u7684\u66f4\u65b0\u673a\u5236\u3002\u6ce8\u610f\uff1aVPA \u7684\u6b64\u529f\u80fd\u662f\u5b9e\u9a8c\u6027\u7684\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u505c\u673a\uff0c\u5f53\u76ee\u524d\u8fd0\u884c\u7684pod\u7684\u8d44\u6e90\u8fbe\u4e0d\u5230VPA\u7684\u63a8\u8350\u503c\uff0c\u5c31\u4f1a\u6267\u884cpod\u9a71\u9010\uff0c\u91cd\u65b0\u90e8\u7f72\u65b0\u7684\u8db3\u591f\u8d44\u6e90\u7684\u670d\u52a1<\/li>\n<li>&#8220;Recreate&#8221;\uff1aVPA \u5728\u521b\u5efa Pod \u65f6\u5206\u914d\u8d44\u6e90\u8bf7\u6c42\uff0c\u5e76\u5728\u73b0\u6709 Pod \u4e0a\u66f4\u65b0\u5b83\u4eec\uff0c\u5f53\u8bf7\u6c42\u7684\u8d44\u6e90\u4e0e\u65b0\u5efa\u8bae\u6709\u5f88\u5927\u5dee\u5f02\u65f6\uff08\u5c0a\u91cd Pod \u4e2d\u65ad\u9884\u7b97\uff0c\u5982\u679c\u5b9a\u4e49\uff09\u3002\u8fd9\u79cd\u6a21\u5f0f\u5e94\u8be5\u5f88\u5c11\u4f7f\u7528\uff0c\u53ea\u6709\u5f53\u60a8\u9700\u8981\u786e\u4fdd\u5728\u8d44\u6e90\u8bf7\u6c42\u53d1\u751f\u53d8\u5316\u65f6\u91cd\u65b0\u542f\u52a8 Pod \u65f6\u3002\u5426\u5219\uff0c\u66f4\u559c\u6b22\u8fd9\u79cd&#8221;Auto&#8221;\u6a21\u5f0f\uff0c\u4e00\u65e6\u5b83\u4eec\u53ef\u7528\uff0c\u5c31\u53ef\u4ee5\u5229\u7528\u91cd\u65b0\u542f\u52a8\u514d\u8d39\u66f4\u65b0\u3002\u6ce8\u610f\uff1aVPA \u7684\u6b64\u529f\u80fd\u662f\u5b9e\u9a8c\u6027\u7684\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u60a8\u7684\u5e94\u7528\u7a0b\u5e8f\u505c\u673a<\/li>\n<li>&#8220;Initial&#8221;\uff1aVPA \u4ec5\u5728\u521b\u5efa pod \u65f6\u5206\u914d\u8d44\u6e90\u8bf7\u6c42\uff0c\u4ee5\u540e\u4e0d\u4f1a\u66f4\u6539\u5b83\u4eec<\/li>\n<li>&#8220;Off&#8221;\uff1aVPA \u4e0d\u4f1a\u81ea\u52a8\u66f4\u6539 Pod \u7684\u8d44\u6e90\u9700\u6c42\u3002\u8fd9\u4e9b\u5efa\u8bae\u662f\u7ecf\u8fc7\u8ba1\u7b97\u7684\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728 VPA \u5bf9\u8c61\u4e2d\u8fdb\u884c\u68c0\u67e5\u3002\u8fd9\u79cd\u6a21\u5f0f\u4ec5\u83b7\u53d6\u8d44\u6e90\u63a8\u8350\u503c\uff0c\u4f46\u662f\u4e0d\u66f4\u65b0Pod<\/li>\n<\/ul>\n<h3>\u521b\u5efa\u4e00\u4e2aupdateMode: Auto \u7684VPA<\/h3>\n<pre><code class=\"language-shell \"># \u5c06updateMode\u4e2d\u7684requests \u6539\u4e3a CPU\uff1a50m\uff0cMemory: 50Mi\uff0c\u540c\u65f6\u5c06updateMode\u4fee\u6539\u4e3aAuto\n\n# \u521b\u5efa\u4e00\u4e2apod\u548csvc\n# kubectl get pods -n vpa\nNAME                     READY   STATUS    RESTARTS   AGE\nnginx-8454bb78d8-67pth   1\/1     Running   0          9s\nnginx-8454bb78d8-6efsh   1\/1     Running   0          9s\n# kubectl get svc -n vpa\nNAME    TYPE       CLUSTER-IP   EXTERNAL-IP   PORT(S)        AGE\nnginx   NodePort   10.0.200.5   &lt;none&gt;        80:45425\/TCP   15s\n\n# \u8fdb\u884c\u538b\u6d4b\uff0c\u538b\u6d4b\u5230\u4e00\u534a\u65f6\uff0c\u7a81\u7136\u8fde\u63a5\u65ad\u4e86\uff0c\u8bf4\u660ePOD\u88ab\u91cd\u65b0\u521b\u5efa\u4e86\n# ab -c 1000 -n 100000 http:\/\/192.168.0.191:45425\/\nThis is ApacheBench, Version 2.3 &lt;$Revision: 1430300 $&gt;\nCopyright 1996 Adam Twiss, Zeus Technology Ltd, http:\/\/www.zeustech.net\/\nLicensed to The Apache Software Foundation, http:\/\/www.apache.org\/\n\nBenchmarking 192.168.0.191 (be patient)\napr_socket_recv: Connection reset by peer (104)\nTotal of 187078 requests completed\n\n# \u67e5\u770bvpa\n# kubectl describe vpa nginx-vpa -n vpa | tail -n 20\n  Conditions:\n    Last Transition Time:  2023-09-07T15:41:32Z\n    Status:                True\n    Type:                  RecommendationProvided\n  Recommendation:\n    Container Recommendations:\n      Container Name:  nginx\n      Lower Bound:               #\u5bb9\u5668\u7684\u6700\u5c0f\u4f30\u8ba1\u503c\n        Cpu:     100m\n        Memory:  262144k\n      Target:                   #\u76ee\u6807\u4f30\u8ba1\u662f\u6211\u4eec\u7528\u4e8e\u8bbe\u7f6e\u8d44\u6e90\u8bf7\u6c42\u7684\u4f30\u8ba1\n        Cpu:     350m\n        Memory:  262144k\n      Uncapped Target:          #\u65e0\u4e0a\u9650\u76ee\u6807\u4f30\u8ba1\u662f\u5728\u6ca1\u6709minAllowed\u548cmaxAllowed\u9650\u5236\u7684\u60c5\u51b5\u4e0b\u4ea7\u751f\u7684\u76ee\u6807\u4f30\u8ba1\n        Cpu:     350m\n        Memory:  262144k\n      Upper Bound:              #\u4e0a\u9650\u662f\u5bb9\u5668\u7684\u6700\u5927\u5efa\u8bae\u8d44\u6e90\u4f30\u8ba1\n        Cpu:     2\n        Memory:  405160855\nEvents:          &lt;none&gt;\n\n# \u67e5\u770bpod\u88ab\u91cd\u65b0\u521b\u5efa\u4e86 \u7a0d\u9ad8\u7684\u914d\u7f6e\n# kubectl get pods -n vpa\nNAME                     READY   STATUS    RESTARTS   AGE\nnginx-daecsfv8d8-see8h   1\/1     Running   0          4m\nnginx-daecsfv8d8-fsise   1\/1     Running   0          3m\n<\/code><\/pre>\n<h2>\u5df2\u77e5\u7684\u9650\u5236<\/h2>\n<ul>\n<li>\u6bcf\u5f53 VPA \u66f4\u65b0 Pod \u8d44\u6e90\u65f6\uff0c\u90fd\u4f1a\u91cd\u65b0\u521b\u5efa Pod\uff0c\u8fd9\u4f1a\u5bfc\u81f4\u91cd\u65b0\u521b\u5efa\u6240\u6709\u6b63\u5728\u8fd0\u884c\u7684\u5bb9\u5668\u3002Pod \u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u8282\u70b9\u4e0a\u91cd\u65b0\u521b\u5efa\u3002<\/li>\n<li>VPA \u65e0\u6cd5\u4fdd\u8bc1\u5b83\u9a71\u9010\u6216\u5220\u9664\u4ee5\u5e94\u7528\u5efa\u8bae\uff08\u5728Auto\u548cRecreate\u6a21\u5f0f\u4e0b\u914d\u7f6e\u65f6\uff09\u7684 pod \u5c06\u6210\u529f\u91cd\u65b0\u521b\u5efa\u3002\u901a\u8fc7\u5c06 VPA \u4e0eCluster Autoscaler\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u90e8\u5206\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<li>VPA \u4e0d\u4f1a\u66f4\u65b0\u4e0d\u5728\u63a7\u5236\u5668\u4e0b\u8fd0\u884c\u7684 Pod \u7684\u8d44\u6e90\u3002<\/li>\n<li>\u76ee\u524d\uff0cVertical Pod Autoscaler\u4e0d\u5e94\u4e0eCPU \u6216\u5185\u5b58\u4e0a\u7684Horizontal Pod Autoscaler (HPA)\u4e00\u8d77\u4f7f\u7528\u3002\u4f46\u662f\uff0c\u60a8\u53ef\u4ee5\u5728\u81ea\u5b9a\u4e49\u548c\u5916\u90e8\u6307\u6807\u4e0a\u5c06 VPA \u4e0e HPA\u7ed3\u5408\u4f7f\u7528\u3002<\/li>\n<li>VPA \u51c6\u5165\u63a7\u5236\u5668\u662f\u4e00\u4e2a\u51c6\u5165 Webhook\u3002\u5982\u679c\u60a8\u5c06\u5176\u4ed6\u51c6\u5165 Webhook \u6dfb\u52a0\u5230\u96c6\u7fa4\u4e2d\uff0c\u5219\u5206\u6790\u5b83\u4eec\u5982\u4f55\u4ea4\u4e92\u4ee5\u53ca\u5b83\u4eec\u662f\u5426\u53ef\u80fd\u76f8\u4e92\u51b2\u7a81\u975e\u5e38\u91cd\u8981\u3002\u51c6\u5165\u63a7\u5236\u5668\u7684\u987a\u5e8f\u7531 API \u670d\u52a1\u5668\u4e0a\u7684\u6807\u5fd7\u5b9a\u4e49\u3002<\/li>\n<li>VPA \u4f1a\u5bf9\u5927\u591a\u6570\u5185\u5b58\u4e0d\u8db3\u4e8b\u4ef6\u505a\u51fa\u53cd\u5e94\uff0c\u4f46\u5e76\u975e\u5728\u6240\u6709\u60c5\u51b5\u4e0b\u90fd\u4f1a\u505a\u51fa\u53cd\u5e94\u3002<\/li>\n<li>VPA \u6027\u80fd\u5c1a\u672a\u5728\u5927\u578b\u96c6\u7fa4\u4e2d\u8fdb\u884c\u6d4b\u8bd5\u3002<\/li>\n<li>VPA \u5efa\u8bae\u53ef\u80fd\u4f1a\u8d85\u51fa\u53ef\u7528\u8d44\u6e90\uff08\u4f8b\u5982\u8282\u70b9\u5927\u5c0f\u3001\u53ef\u7528\u5927\u5c0f\u3001\u53ef\u7528\u914d\u989d\uff09\u5e76\u5bfc\u81f4Pod \u5904\u4e8e\u6302\u8d77\u72b6\u6001\u3002\u901a\u8fc7\u5c06 VPA \u4e0eCluster Autoscaler\u7ed3\u5408\u4f7f\u7528\u53ef\u4ee5\u90e8\u5206\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\u3002<\/li>\n<li>\u4e0e\u540c\u4e00 Pod \u5339\u914d\u7684\u591a\u4e2a VPA \u8d44\u6e90\u5177\u6709\u672a\u5b9a\u4e49\u7684\u884c\u4e3a\u3002<\/li>\n<\/ul>\n<h2>\u603b\u7ed3<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528VPA\u5b9e\u73b0\u4e86\u57fa\u4e8ePOD\u5bf9\u914d\u7f6e\u8fdb\u884c\u6a2a\u5411\u6269\u5c55\uff0c\u5408\u7406\u7684\u4f7f\u7528\u53ef\u4ee5\u63d0\u9ad8\u5bf9K8S\u7684\u5229\u7528\u7387\uff0c\u5b9e\u73b0\u964d\u672c\u589e\u6548\u3002\u4f46\u662f\u76ee\u524d\u7684VPA\u4e5f\u5b58\u5728\u4e00\u4e9b\u95ee\u9898\uff0c\u6211\u4e2a\u4eba\u89c9\u5f97VPA\u6700\u5927\u7684\u95ee\u9898\u662f\u4f1a\u5bf9\u670d\u52a1\u8fdb\u884c\u91cd\u5efa\uff0c\u91cd\u5efa\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u4f1a\u6709\u6d41\u91cf\u635f\u5931\uff0c\u4f46\u662f\u597d\u6d88\u606f\u662f\u4ece1.27 \u7248\u672c\u52a8\u6001\u8c03\u6574\u5bb9\u5668CPU\u548c\u5185\u5b58\u8d44\u6e90\u9650\u5236\uff0c\u65e0\u9700\u91cd\u542f\u5e94\u7528\u7a0b\u5e8f\uff0c\u5728\u53ef\u89c1\u7684\u5c06\u6765\uff0c\u4f1a\u5b9e\u73b0\u52a8\u6001\u6269\u5bb9\u66f4\u52a0\u987a\u6ed1\uff0c\u8ba9\u6211\u4eec\u4e00\u8d77\u671f\u5f85~<\/p>\n<h2>\u8f6c\u8f7d&amp;&amp;\u53c2\u8003<\/h2>\n<p>1.<code>https:\/\/www.51cto.com\/article\/766185.html<\/code><\/p>\n<p>2.<code>https:\/\/github.com\/kubernetes\/autoscaler\/tree\/vertical-pod-autoscaler-0.14.0\/vertical-pod-autoscaler\/deploy<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Kubernetes VPA\uff08Pod\u7eb5\u5411\u81ea\u52a8\u6269\u7f29\uff09 GPT\u4ecb\u7ecd Kubernetes VPA\uff08Vertical [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[353],"tags":[351,492],"class_list":["post-2786","post","type-post","status-publish","format-standard","hentry","category-kubernetes","tag-kubernetes","tag-vpa"],"_links":{"self":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2786","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/comments?post=2786"}],"version-history":[{"count":1,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2786\/revisions"}],"predecessor-version":[{"id":2787,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/posts\/2786\/revisions\/2787"}],"wp:attachment":[{"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/media?parent=2786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/categories?post=2786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/199604.com\/wp-json\/wp\/v2\/tags?post=2786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}