{"id":4952,"date":"2021-10-02T13:34:19","date_gmt":"2021-10-02T05:34:19","guid":{"rendered":"http:\/\/blog.ywdevops.cn\/?p=4952"},"modified":"2023-02-23T15:50:41","modified_gmt":"2023-02-23T07:50:41","slug":"k8s-4","status":"publish","type":"post","link":"https:\/\/blog.ywdevops.cn\/index.php\/2021\/10\/02\/k8s-4\/","title":{"rendered":"k8s\u4e4bpod\u8c03\u5ea6"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5728Kubernetes\u5e73\u53f0\u4e0a\uff0c\u6211\u4eec\u5f88\u5c11\u4f1a\u76f4\u63a5\u521b\u5efa\u4e00\u4e2aPod\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4f1a\u901a\u8fc7RC\u3001Deployment\u3001DaemonSet\u3001Job\u7b49\u63a7\u5236\u5668\u5b8c\u6210\u5bf9\u4e00\u7ec4Pod\u526f\u672c\u7684\u521b\u5efa\u3001\u8c03\u5ea6\u53ca\u5168\u751f\u547d\u5468\u671f\u7684\u81ea\u52a8\u63a7\u5236\u4efb\u52a1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> \u771f\u5b9e\u751f\u4ea7\u73af\u5883\u53ef\u80fd\u5b58\u5728\u5982\u4e0b\u9700\u6c42\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>(1) \uff1a<\/strong>\u4e0d\u540cPod\u4e4b\u95f4\u7684\u4eb2\u548c\u6027\uff08Affinity\uff09\u3002\u6bd4\u5982MySQL\u6570\u636e\u5e93\u4e0eRedis\u4e2d\u95f4\u4ef6\u4e0d\u80fd\u88ab\u8c03\u5ea6\u5230\u540c\u4e00\u4e2a\u76ee\u6807\u8282\u70b9\u4e0a\uff0c\u6216\u8005\u4e24\u79cd\u4e0d\u540c\u7684Pod\u5fc5\u987b\u88ab\u8c03\u5ea6\u5230\u540c\u4e00\u4e2aNode\u4e0a\uff0c\u4ee5\u5b9e\u73b0\u672c\u5730\u6587\u4ef6\u5171\u4eab\u6216\u672c\u5730\u7f51\u7edc\u901a\u4fe1\u7b49\u7279\u6b8a\u9700\u6c42\uff0c\u8fd9\u5c31\u662fPodAffinity\u8981\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(2)\uff1a\u6709 \u72b6 \u6001 \u96c6 \u7fa4 \u7684 \u8c03 \u5ea6 \u3002 \u5bf9 \u4e8e ZooKeeper \u3001 Elasticsearch \u3001MongoDB\u3001Kafka\u7b49\u6709\u72b6\u6001\u96c6\u7fa4\uff0c\u867d\u7136\u96c6\u7fa4\u4e2d\u7684\u6bcf\u4e2aWorker\u8282\u70b9\u770b\u8d77\u6765\u90fd\u662f\u76f8\u540c\u7684\uff0c\u4f46\u6bcf\u4e2aWorker\u8282\u70b9\u90fd\u5fc5\u987b\u6709\u660e\u786e\u7684\u3001\u4e0d\u53d8\u7684\u552f\u4e00ID\uff08\u4e3b\u673a\u540d\u6216IP\u5730\u5740\uff09\uff0c\u8fd9\u4e9b\u8282\u70b9\u7684\u542f\u52a8\u548c\u505c\u6b62\u6b21\u5e8f\u901a\u5e38\u6709\u4e25\u683c\u7684\u987a\u5e8f\u3002\u6b64\u5916\uff0c\u7531\u4e8e\u96c6\u7fa4\u9700\u6301\u4e45\u5316\u4fdd\u5b58\u72b6\u6001\u6570\u636e\uff0c\u6240\u4ee5\u96c6\u7fa4\u4e2d\u7684Worker\u8282\u70b9\u5bf9\u5e94\u7684Pod\u4e0d\u7ba1\u5728\u54ea\u4e2aNode\u4e0a\u6062\u590d\uff0c\u90fd\u9700\u8981\u6302\u8f7d\u539f\u6765\u7684Volume\uff0c\u56e0\u6b64\u8fd9\u4e9bPod\u8fd8\u9700\u8981\u6346\u7ed1\u5177\u4f53\u7684PV\u3002\u9488\u5bf9\u8fd9\u79cd\u590d\u6742\u7684\u9700\u6c42\uff0cKubernetes\u63d0\u4f9b\u4e86StatefulSet\u8fd9\u79cd\u7279\u6b8a\u7684\u526f\u672c\u63a7\u5236\u5668\u6765\u89e3\u51b3\u95ee\u9898\uff0c\u5728Kubernetes 1.9\u7248\u672c\u53d1\u5e03\u540e\uff0cStatefulSet\u624d\u53ef\u7528\u4e8e\u6b63\u5f0f\u751f\u4ea7\u73af\u5883\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(3)\uff1a\u5728\u6bcf\u4e2aNode\u4e0a\u8c03\u5ea6\u5e76\u4e14\u4ec5\u4ec5\u521b\u5efa\u4e00\u4e2aPod\u526f\u672c\u3002\u8fd9\u79cd\u8c03\u5ea6\u901a\u5e38\u7528\u4e8e\u7cfb\u7edf\u76d1\u63a7\u76f8\u5173\u7684Pod\uff0c\u6bd4\u5982\u4e3b\u673a\u4e0a\u7684\u65e5\u5fd7\u91c7\u96c6\u3001\u4e3b\u673a\u6027\u80fd\u91c7\u96c6\u7b49\u8fdb\u7a0b\u9700\u8981\u88ab\u90e8\u7f72\u5230\u96c6\u7fa4\u4e2d\u7684\u6bcf\u4e2a\u8282\u70b9\uff0c\u5e76\u4e14\u53ea\u80fd\u90e8\u7f72\u4e00\u4e2a\u526f\u672c\uff0c\u8fd9\u5c31\u662fDaemonSet\u8fd9\u79cd\u7279\u6b8aPod\u526f\u672c\u63a7\u5236\u5668\u6240\u89e3\u51b3\u7684\u95ee\u9898<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(4)\uff1a\u5bf9\u4e8e\u6279\u5904\u7406\u4f5c\u4e1a\uff0c\u9700\u8981\u521b\u5efa\u591a\u4e2aPod\u526f\u672c\u6765\u534f\u540c\u5de5\u4f5c\uff0c\u5f53\u8fd9\u4e9bPod\u526f\u672c\u90fd\u5b8c\u6210\u81ea\u5df1\u7684\u4efb\u52a1\u65f6\uff0c\u6574\u4e2a\u6279\u5904\u7406\u4f5c\u4e1a\u5c31\u7ed3\u675f\u4e86\u3002\u8fd9\u79cdPod\u8fd0\u884c\u4e14\u4ec5\u8fd0\u884c\u4e00\u6b21\u7684\u7279\u6b8a\u8c03\u5ea6\uff0c\u7528\u5e38\u89c4\u7684RC\u6216\u8005Deployment\u90fd\u65e0\u6cd5\u89e3\u51b3\uff0c\u6240\u4ee5Kubernetes\u5f15\u5165\u4e86\u65b0\u7684Pod\u8c03\u5ea6\u63a7\u5236\u5668Job\u6765\u89e3\u51b3\u95ee\u9898\uff0c\u5e76\u7ee7\u7eed\u5ef6\u4f38\u4e86\u5b9a\u65f6\u4f5c\u4e1a\u7684\u8c03\u5ea6\u63a7\u5236\u5668CronJob\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e \u5355 \u72ec \u7684 Pod \u5b9e \u4f8b \u4e0d \u540c \uff0c \u7531 RC \u3001 ReplicaSet \u3001 Deployment \u3001DaemonSet\u7b49\u63a7\u5236\u5668\u521b\u5efa\u7684Pod\u526f\u672c\u5b9e\u4f8b\u90fd\u662f\u5f52\u5c5e\u4e8e\u8fd9\u4e9b\u63a7\u5236\u5668\u7684\uff0c\u8fd9\u5c31\u4ea7\u751f\u4e86\u4e00\u4e2a\u95ee\u9898\uff1a\u63a7\u5236\u5668\u88ab\u5220\u9664\u540e\uff0c\u5f52\u5c5e\u4e8e\u63a7\u5236\u5668\u7684Pod\u526f\u672c\u8be5\u4f55\u53bb\u4f55\u4ece\uff1f\u5728Kubernetes 1.9\u4e4b\u524d\uff0c\u5728RC\u7b49\u5bf9\u8c61\u88ab\u5220\u9664\u540e\uff0c\u5b83\u4eec\u6240\u521b\u5efa\u7684Pod\u526f\u672c\u90fd\u4e0d\u4f1a\u88ab\u5220\u9664\uff1b\u5728Kubernetes 1.9\u4ee5\u540e\uff0c\u8fd9\u4e9bPod\u526f\u672c\u4f1a\u88ab\u4e00\u5e76\u5220\u9664\u3002\u5982\u679c\u4e0d\u5e0c\u671b\u8fd9\u6837\u505a\uff0c\u5219\u53ef\u4ee5\u901a\u8fc7kubectl\u547d\u4ee4\u7684 \u2013cascade=orphan \u53c2\u6570\u6765\u53d6\u6d88\u8fd9\u4e00\u9ed8\u8ba4\u7279\u6027\uff1akubectl delete deploy deploy\u540d\u79f0 \u2013cascade=orphan<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7deployment\u5b9a\u4e49pod\u540e\uff0c\u7cfb\u7edf\u4f1a\u6839\u636e\u81ea\u52a8\u8c03\u5ea6\u7b97\u6cd5\u5c06pod\u968f\u673a\u8c03\u5ea6\u5230\u67d0\u4e2a\u8282\u70b9\u4e0a\uff0c\u9664\u4e86\u81ea\u52a8\u8c03\u5ea6\u5916\uff0c Kubernetes\u4e5f\u63d0\u4f9b\u4e86\u591a\u79cd\u4e30\u5bcc\u7684\u8c03\u5ea6\u7b56\u7565\uff0c\u7528\u6237\u53ea\u9700\u5728Pod\u7684\u5b9a\u4e49\u4e2d\u4f7f\u7528NodeSelector\u3001 NodeAffinity\u3001PodAffinity\u3001Pod\u9a71\u9010\u7b49\u66f4\u52a0\u7ec6\u7c92\u5ea6\u7684\u8c03\u5ea6\u7b56\u7565\u8bbe\u7f6e\uff0c\u5c31\u80fd\u5b8c\u6210\u5bf9Pod\u7684\u7cbe\u51c6\u8c03\u5ea6\u3002\u4e0b\u9762\u5bf9\u8fd9\u4e9b\u7b56\u7565\u8fdb\u884c\u8bf4\u660e\u3002 <\/p>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color has-normal-font-size wp-block-paragraph\"><strong>\u4e00\u3001 NodeSelector\uff1a\u5b9a\u5411\u8c03\u5ea6\uff1a<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes Master\u4e0a\u7684Scheduler\u670d\u52a1\uff08kube-scheduler\u8fdb\u7a0b\uff09\u8d1f\u8d23\u5b9e\u73b0Pod\u7684\u8c03\u5ea6\uff0c\u6574\u4e2a\u8c03\u5ea6\u8fc7\u7a0b\u901a\u8fc7\u6267\u884c\u4e00\u7cfb\u5217\u590d\u6742\u7684\u7b97\u6cd5\uff0c\u6700\u7ec8\u4e3a\u6bcf\u4e2aPod\u90fd\u8ba1\u7b97\u51fa\u4e00\u4e2a\u6700\u4f73\u7684\u76ee\u6807\u8282\u70b9\uff0c\u8fd9\u4e00\u8fc7\u7a0b\u662f\u81ea\u52a8\u5b8c\u6210\u7684\uff0c\u901a\u5e38\u6211\u4eec\u65e0\u6cd5\u77e5\u9053Pod\u6700\u7ec8\u4f1a\u88ab\u8c03\u5ea6\u5230\u54ea\u4e2a\u8282\u70b9\u4e0a\u3002\u5728\u5b9e\u9645\u60c5\u51b5\u4e0b\uff0c\u4e5f\u53ef\u80fd\u9700\u8981\u5c06Pod\u8c03\u5ea6\u5230\u6307\u5b9a\u7684\u4e00\u4e9bNode\u4e0a\uff0c\u53ef\u4ee5\u901a\u8fc7<strong>Node\u7684\u6807\u7b7e<\/strong>\uff08Label\uff09\u548cPod \u7684<strong>nodeSelector<\/strong>\u5c5e\u6027\u76f8\u5339\u914d\uff0c\u6765\u8fbe\u5230\u4e0a\u8ff0\u76ee\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001 \u9996\u5148\u901a\u8fc7kubectl label\u547d\u4ee4\u7ed9\u76ee\u6807Node\u6253\u4e0a\u4e00\u4e9b\u6807\u7b7e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a\u7ed9k8s-node2\u8282\u70b9\u6253\u4e0a\u6807\u7b7ehello=world \uff0c\u6267\u884c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl label nodes k8s-node2 hello=world<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"930\" height=\"140\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/10.png\" alt=\"\" class=\"wp-image-4953\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/10.png 930w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/10-300x45.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/10-768x116.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/10-600x90.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\"> \u4e0a\u8ff0\u547d\u4ee4\u884c\u64cd\u4f5c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539\u8d44\u6e90\u5b9a\u4e49\u6587\u4ef6\u7684\u65b9\u5f0f\uff0c\u5e76\u6267\u884c kubectl replace -f xxx.yaml\u547d\u4ee4\u6765\u5b8c\u6210<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5220\u9664\u6807\u7b7e\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4&#8221; <strong>kubectl label node k8s-node2 hello-<\/strong>  &#8220;\u6765\u5b8c\u6210\uff0c\u6ce8\u610f,hello\u8868\u793a\u6807\u7b7e\u7684\u952e\uff0c\u6ce8\u610fhello\u540e\u9762\u8fd8\u6709\u4e00\u4e2a\u51cf\u53f7\uff0c\u8868\u793a\u5220\u9664\u8fd9\u4e2a \u6807\u7b7e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u5728pod\u5b9a\u4e49\u6587\u4ef6\u4e2d\uff0c\u6dfb\u52a0\u8282\u70b9\u9009\u62e9\u6761\u4ef6\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"385\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/0.png\" alt=\"\" class=\"wp-image-7877\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/0.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/0-300x163.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/0-600x325.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u547d\u4ee4kubectl create -f nginx.yaml\u521b\u5efapod\u540e\uff0c\u67e5\u770bpod\u6240\u5728\u8282\u70b9\uff0c\u5df2\u7ecf\u6210\u529f\u8c03\u5ea6\u5230k8s-node2\u8282\u70b9\u4e0a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"115\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-7.png\" alt=\"\" class=\"wp-image-7878\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-7.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-7-300x49.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-7-600x97.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u4e0a\u56fe\u4e2d\u7684Pod\u521b\u5efa\u5230\u547d\u4ee4\u7a7a\u95f4gongguan\u4e2d\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u7ed9\u591a\u4e2aNode\u90fd\u5b9a\u4e49\u4e86\u76f8\u540c\u7684\u6807\u7b7e\uff08\u4f8b\u5982hello=world\uff09\uff0c\u5219 scheduler\u4f1a\u6839\u636e\u8c03\u5ea6\u7b97\u6cd5\u4ece\u8fd9\u7ec4Node\u4e2d\u6311\u9009\u4e00\u4e2a\u53ef\u7528\u7684Node\u8fdb\u884cPod\u8c03\u5ea6\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6211\u4eec\u6307\u5b9a\u4e86Pod\u7684nodeSelector\u6761\u4ef6\uff0c\u4e14\u5728\u96c6\u7fa4\u4e2d\u4e0d\u5b58\u5728\u5305\u542b\u76f8\u5e94\u6807\u7b7e\u7684Node\uff0c\u5219\u5373\u4f7f\u5728\u96c6\u7fa4\u4e2d\u8fd8\u6709\u5176\u4ed6\u53ef\u4f9b\u4f7f\u7528\u7684 Node\uff0c\u8fd9\u4e2aPod\u4e5f\u65e0\u6cd5\u88ab\u6210\u529f\u8c03\u5ea6,\u4f1a\u4e00\u76f4\u663e\u793apending\u72b6\u6001\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u7528\u6237\u53ef\u4ee5\u81ea\u884c\u7ed9Node\u6dfb\u52a0\u6807\u7b7e\uff0cKubernetes\u4e5f\u4f1a\u7ed9Node\u9884\u5b9a\u4e49 \u4e00\u4e9b\u6807\u7b7e\uff0c\u6267\u884c\u547d\u4ee4kubectl get node show-labels=true \u53ef\u4ee5\u67e5\u770b\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"940\" height=\"317\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/13.png\" alt=\"\" class=\"wp-image-4962\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/13.png 940w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/13-300x101.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/13-768x259.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/13-600x202.png 600w\" sizes=\"auto, (max-width: 940px) 100vw, 940px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u6237\u4e5f\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u7cfb\u7edf\u6807\u7b7e\u8fdb\u884cPod\u7684\u5b9a\u5411\u8c03\u5ea6<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NodeSelector\u901a\u8fc7\u6807\u7b7e\u7684\u65b9\u5f0f\uff0c\u7b80\u5355\u5b9e\u73b0\u4e86\u9650\u5236Pod\u6240\u5728\u8282\u70b9\u7684\u65b9 \u6cd5\u3002\u4eb2\u548c\u6027\u8c03\u5ea6\u673a\u5236\u5219\u6781\u5927\u6269\u5c55\u4e86Pod\u7684\u8c03\u5ea6\u80fd\u529b\uff0c\u4e3b\u8981\u7684\u589e\u5f3a\u529f\u80fd\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u66f4\u5177\u8868\u8fbe\u529b\uff08\u4e0d\u4ec5\u4ec5\u662f\u201c\u7b26\u5408\u5168\u90e8\u201d\u7684\u7b80\u5355\u60c5\u51b5\uff09 <\/li><li> \u53ef\u4ee5\u4f7f\u7528\u8f6f\u9650\u5236\u3001\u4f18\u5148\u91c7\u7528\u7b49\u9650\u5236\u65b9\u5f0f\uff0c\u4ee3\u66ff\u4e4b\u524d\u7684\u786c\u9650\u5236\uff0c \u8fd9\u6837\u8c03\u5ea6\u5668\u5728\u65e0\u6cd5\u6ee1\u8db3\u4f18\u5148\u9700\u6c42\u7684\u60c5\u51b5\u4e0b\uff0c\u4f1a\u9000\u800c\u6c42\u5176\u6b21\uff0c\u7ee7\u7eed\u8fd0\u884c\u8be5 Pod\u3002 <\/li><li> \u53ef\u4ee5\u4f9d\u636e\u8282\u70b9\u4e0a\u6b63\u5728\u8fd0\u884c\u7684\u5176\u4ed6Pod\u7684\u6807\u7b7e\u6765\u8fdb\u884c\u9650\u5236\uff0c\u800c\u975e\u8282\u70b9\u672c\u8eab\u7684\u6807\u7b7e\u3002\u8fd9\u6837\u5c31\u53ef\u4ee5\u5b9a\u4e49\u4e00\u79cd\u89c4\u5219\u6765\u63cf\u8ff0Pod\u4e4b\u95f4\u7684\u4eb2\u548c\u6216\u4e92\u65a5\u5173\u7cfb\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4eb2\u548c\u6027\u8c03\u5ea6\u529f\u80fd\u5305\u62ec\u8282\u70b9\u4eb2\u548c\u6027\uff08NodeAffinity\uff09\u548cPod\u4eb2\u548c\u6027 \uff08PodAffinity\uff09\u4e24\u4e2a\u7ef4\u5ea6\u7684\u8bbe\u7f6e\u3002\u8282\u70b9\u4eb2\u548c\u6027\u4e0eNodeSelector\u7c7b\u4f3c\uff0c\u589e\u5f3a\u4e86\u4e0a\u8ff0\u524d\u4e24\u70b9\u4f18\u52bf\uff1bPod\u7684\u4eb2\u548c\u4e0e\u4e92\u65a5\u9650\u5236\u5219\u901a\u8fc7Pod\u6807\u7b7e\u800c\u4e0d\u662f\u8282\u70b9\u6807\u7b7e\u6765\u5b9e\u73b0<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u5c0f\u8282\u4ee3\u7801\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nginx                     #deployment\u540d\u5b57\n  namespace: gongguan             #\u547d\u540d\u7a7a\u95f4\n  labels:\n    name: deployment-nginx\nspec:\n  selector:\n    matchLabels:\n      app: nginx-pod             #\u7ba1\u7406\u6807\u7b7e\u4e3anginx-pod\u7684pod\n  replicas: 2                    #\u526f\u672c\u4e2a\u6570\u4e3a2\n  template:                      #\u521b\u5efapod\u7684\u6a21\u677f\n    metadata:\n      labels:\n        app: nginx-pod           #pod\u6807\u7b7e\uff0c\u6807\u7b7e\u9009\u62e9\u5668\u5c31\u662f\u9009\u62e9\u8fd9\u4e2a\u6807\u7b7e\n    spec:\n      containers:\n      - name: nginx\n        image: nginx\n        ports:\n        - containerPort: 80\n      nodeSelector:              #\u8282\u70b9\u9009\u62e9\u6807\u7b7e\n        hello: world\n<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color has-normal-font-size wp-block-paragraph\"><strong>\u4e8c\u3001 NodeAffinity\uff1a\u8282\u70b9\u4eb2\u548c\u6027\u8c03\u5ea6<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">NodeAffinity\u610f\u4e3aNode\u4eb2\u548c\u6027\u7684\u8c03\u5ea6\u7b56\u7565\uff0c\u662f\u7528\u4e8e\u66ff\u6362NodeSelector \u7684\u5168\u65b0\u8c03\u5ea6\u7b56\u7565\u3002\u76ee\u524d\u6709\u4e24\u79cd\u8282\u70b9\u4eb2\u548c\u6027\u8868\u8fbe\u3002 <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> RequiredDuringSchedulingIgnoredDuringExecution\uff1a\u5fc5\u987b\u6ee1\u8db3\u6307\u5b9a\u7684\u89c4\u5219\u624d\u53ef\u4ee5\u8c03\u5ea6Pod\u5230Node\u4e0a\uff08\u529f\u80fd\u4e0enodeSelector\u5f88\u50cf\uff0c\u4f46\u662f\u4f7f\u7528\u7684\u662f\u4e0d\u540c\u7684\u8bed\u6cd5\uff09\uff0c\u76f8\u5f53\u4e8e<strong>\u786c\u9650\u5236<\/strong>\u3002 <\/li><li> PreferredDuringSchedulingIgnoredDuringExecution\uff1a\u5f3a\u8c03\u4f18\u5148\u6ee1\u8db3\u6307\u5b9a\u89c4\u5219\uff0c\u8c03\u5ea6\u5668\u4f1a\u5c1d\u8bd5\u8c03\u5ea6Pod\u5230Node\u4e0a\uff0c\u4f46\u5e76\u4e0d\u5f3a\u6c42\uff0c\u76f8\u5f53\u4e8e<strong>\u8f6f\u9650\u5236<\/strong>\u3002\u591a\u4e2a\u4f18\u5148\u7ea7\u89c4\u5219\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u6743\u91cd\uff08weight\uff09\u503c\uff0c\u4ee5\u5b9a\u4e49\u6267\u884c\u7684\u5148\u540e\u987a\u5e8f\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">IgnoredDuringExecution\u7684\u610f\u601d\u662f\uff1a\u5982\u679c\u4e00\u4e2aPod\u6240\u5728\u7684\u8282\u70b9\u5728Pod\u8fd0\u884c\u671f\u95f4\u6807\u7b7e\u53d1\u751f\u4e86\u53d8\u66f4\uff0c\u4e0d\u518d\u7b26\u5408\u8be5Pod\u7684\u8282\u70b9\u4eb2\u548c\u6027\u9700\u6c42\uff0c\u5219\u7cfb\u7edf\u5c06\u5ffd\u7565Node\u4e0aLabel\u7684\u53d8\u5316\uff0c\u8be5Pod\u80fd\u7ee7\u7eed\u5728\u8be5\u8282\u70b9\u8fd0\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001\u9996\u5148\u5728k8s-node1\u521b\u5efa\u6807\u7b7eni=hao\uff0c\u5728k8s-node2\u521b\u5efa\u6807\u7b7ehello=world<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">kubectl  label node k8s-node1  ni=hao\/kubectl label node k8s-node2 hello=world<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a \u4e0b\u9762\u4f8b\u5b50\u8bbe\u7f6e\u4e86NodeAffinity\u8c03\u5ea6\u7684\u5982\u4e0b\u89c4\u5219\uff0c requiredDuringSchedulingIgnoredDuringExecution\u8981\u6c42\u5fc5\u987b\u8fd0\u884c\u5728\u6807\u7b7e\u4e3ani=hao\u7684\u8282\u70b9\u4e0a\uff0c preferredDuringSchedulingIgnoredDuringExecution\u7684\u8981\u6c42\u662f\u5c3d\u91cf\u8fd0\u884c\u5728\u6807\u7b7e\u4e3ahello=world\u8282\u70b9\u4e0a\uff0c\u8d44\u6e90\u5b9a\u4e49\u6587\u4ef6\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"706\" height=\"611\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-8.png\" alt=\"\" class=\"wp-image-7887\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-8.png 706w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-8-300x260.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/1-8-600x519.png 600w\" sizes=\"auto, (max-width: 706px) 100vw, 706px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u53ef\u4ee5\u5c06\u952e\u503c\u5199\u6210<strong>json\u683c\u5f0f<\/strong>\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"534\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-5.png\" alt=\"\" class=\"wp-image-7889\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-5.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-5-300x226.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/4-5-600x452.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u8282\u70b9\u4eb2\u548c\u6027\u8868\u793a\u5f3a\u5236\u8fd9\u4e2apod\u5fc5\u987b\u8fd0\u884c\u5728\u5177\u6709\u6807\u7b7eni=hao\u7684\u8282\u70b9\u4e0a\uff0c\u540c\u65f6\u5c3d\u53ef\u80fd\u8c03\u5ea6\u5230\u5177\u6709\u6807\u7b7ehello=world\u7684\u8282\u70b9\u4e0a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u521b\u5efapod\uff0c\u521b\u5efa\u540e\u67e5\u770bpod\u6240\u5728\u8282\u70b9\u4fe1\u606f\uff0c\u53d1\u73b0\u88ab\u8c03\u5ea6\u5230k8s-node1\u4e0a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"703\" height=\"100\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-5.png\" alt=\"\" class=\"wp-image-7883\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-5.png 703w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-5-300x43.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-5-600x85.png 600w\" sizes=\"auto, (max-width: 703px) 100vw, 703px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\u5728k8s-node2\u8282\u70b9\u4e5f\u6253\u4e0a\u6807\u7b7eni=hao\uff0c\u91cd\u65b0\u521b\u5efa\u6b64pod\u770b\u662f\u5426\u53ef\u4ee5\u8c03\u5ea6\u5230k8s-node2\u4e0a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"100\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-6.png\" alt=\"\" class=\"wp-image-7885\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-6.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-6-300x42.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/2-6-600x85.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u8bf4\u660e\uff1a\u5728k8s-node2\u4e0a\u6253\u4e0a\u4e86\u6807\u7b7eni=hao\u540e\uff0c\u5c31\u53ef\u4ee5\u6ee1\u8db3\u8282\u70b9\u4eb2\u548c\u6027\u4e2d\u8bbe\u7f6e\u7684\u5fc5\u987b\u8c03\u5ea6\u5230\u6807\u7b7e\u4e3ani=hao\u7684\u8282\u70b9\u4e0a\uff0c\u53c8\u5c3d\u53ef\u80fd\u8c03\u5ea6\u5230\u6807\u7b7e\u4e3ahello=world\u7684\u8282\u70b9\u4e0a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u9762\u7684\u914d\u7f6e\u4e2d\u53ef\u4ee5\u770b\u5230In\u64cd\u4f5c\u7b26\uff0cNodeAffinity\u8bed\u6cd5\u652f\u6301\u7684\u64cd\u4f5c\u7b26\u5305\u62ecIn\u3001NotIn\u3001Exists\u3001DoesNotExist\u3001Gt\u3001Lt\u3002\u867d\u7136\u6ca1\u6709\u8282\u70b9\u6392\u65a5\u529f\u80fd\uff0c\u4f46\u662f\u7528NotIn\u548cDoesNotExist\u5c31\u53ef\u4ee5\u5b9e\u73b0\u6392\u65a5\u7684\u529f\u80fd\u4e86\u3002 <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> In\uff1a<code>label<\/code>\u7684\u503c\u5728\u67d0\u4e2a\u5217\u8868\u4e2d <\/li><li> NotIn\uff1a<code>label<\/code>\u7684\u503c\u4e0d\u5728\u67d0\u4e2a\u5217\u8868\u4e2d <\/li><li> Gt\uff1a<code>label<\/code>\u7684\u503c\u5927\u4e8e\u67d0\u4e2a\u503c <\/li><li> Lt\uff1a<code>label<\/code>\u7684\u503c\u5c0f\u4e8e\u67d0\u4e2a\u503c <\/li><li> Exists\uff1a\u67d0\u4e2a<code>label<\/code>\u5b58\u5728 <\/li><li> DoesNotExist\uff1a\u67d0\u4e2a<code>label<\/code>\u4e0d\u5b58\u5728 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"> NodeAffinity\u89c4\u5219\u8bbe\u7f6e\u7684\u6ce8\u610f\u4e8b\u9879\u5982\u4e0b\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u5982\u679c\u540c\u65f6\u5b9a\u4e49\u4e86nodeSelector\u548cnodeAffinity\uff0c\u90a3\u4e48\u5fc5\u987b\u4e24\u4e2a\u6761\u4ef6\u90fd\u5f97\u5230\u6ee1\u8db3\uff0cPod\u624d\u80fd\u6700\u7ec8\u8fd0\u884c\u5728\u6307\u5b9a\u7684Node\u4e0a\u3002 <\/li><li> \u5982\u679cnodeAffinity\u6307\u5b9a\u4e86\u591a\u4e2anodeSelectorTerms\uff0c\u90a3\u4e48\u5176\u4e2d\u4e00\u4e2a\u80fd\u591f\u5339\u914d\u6210\u529f\u5373\u53ef\u3002 <\/li><li> \u5982\u679c\u5728nodeSelectorTerms\u4e2d\u6709\u591a\u4e2amatchExpressions\uff0c\u5219\u4e00\u4e2a\u8282\u70b9\u5fc5\u987b\u6ee1\u8db3\u6240\u6709matchExpressions\u624d\u80fd\u8fd0\u884c\u8be5Pod\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u8282\u4ee3\u7801\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nginx                     #deployment\u540d\u5b57\n  namespace: gongguan             #\u547d\u540d\u7a7a\u95f4\n  labels:\n    name: deployment-nginx\nspec:\n  selector:\n    matchLabels:\n      app: nginx-pod             #\u7ba1\u7406\u6807\u7b7e\u4e3anginx-pod\u7684pod\n  replicas: 2                    #\u526f\u672c\u4e2a\u6570\u4e3a2\n  template:                      #\u521b\u5efapod\u7684\u6a21\u677f\n    metadata:\n      labels:\n        app: nginx-pod           #pod\u6807\u7b7e\uff0c\u6807\u7b7e\u9009\u62e9\u5668\u5c31\u662f\u9009\u62e9\u8fd9\u4e2a\u6807\u7b7e\n    spec:\n      containers:\n      - name: nginx\n        image: nginx\n        ports:\n        - containerPort: 80\n        imagePullPolicy: IfNotPresent\n      affinity:\n        nodeAffinity:\n          requiredDuringSchedulingIgnoredDuringExecution:\n            nodeSelectorTerms:\n            - matchExpressions:\n              - {key: ni,operator: In,values: &#91;\"hao\"]}\n          preferredDuringSchedulingIgnoredDuringExecution:\n          - weight: 1\n            preference:\n              matchExpressions:\n              - {key: hello,operator: In, values: &#91;\"world\"]}<\/code><\/pre>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color has-normal-font-size wp-block-paragraph\"><strong>\u4e09\u3001 PodAffinity\uff1aPod\u4eb2\u548c\u4e0e\u4e92\u65a5\u8c03\u5ea6\u7b56\u7565<\/strong> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pod\u95f4\u7684\u4eb2\u548c\u4e0e\u4e92\u65a5\u4eceKubernetes 1.4\u7248\u672c\u5f00\u59cb\u5f15\u5165\u3002\u8fd9\u4e00\u529f\u80fd\u8ba9\u7528\u6237\u4ece\u53e6\u4e00\u4e2a\u89d2\u5ea6\u6765\u9650\u5236Pod\u6240\u80fd\u8fd0\u884c\u7684\u8282\u70b9\uff1a\u6839\u636e\u5728\u8282\u70b9\u4e0a\u6b63\u5728\u8fd0\u884c\u7684<strong>Pod\u7684\u6807\u7b7e<\/strong>\u800c\u4e0d\u662f\u8282\u70b9\u7684\u6807\u7b7e\u8fdb\u884c\u5224\u65ad\u548c\u8c03\u5ea6\uff0c\u8981\u6c42\u5bf9\u8282\u70b9\u548cPod\u4e24\u4e2a\u6761\u4ef6\u8fdb\u884c\u5339\u914d\u3002  \u8fd9\u79cd\u89c4\u5219\u53ef\u4ee5\u63cf\u8ff0\u4e3a\uff1a\u5982\u679c\u5728\u5177\u6709\u6807\u7b7eX\u7684Node\u4e0a\u8fd0\u884c\u4e86\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u7b26\u5408\u4eb2\u548c\u6027\u6761\u4ef6Y\u7684Pod\uff0c\u90a3\u4e48\u65b0\u521b\u5efa\u7684Pod\u5e94\u8be5\uff08\u5982\u679c\u662f\u4e92\u65a5\u7684\u60c5\u51b5\uff0c\u90a3 \u4e48\u5c31\u53d8\u6210\u62d2\u7edd\uff09\u8fd0\u884c\u5728\u8fd9\u4e2aNode\u4e0a(\u4eb2\u548c\u6027\u9760\u62e2)\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u91ccX\u6307\u7684\u662f\u4e00\u4e2a\u96c6\u7fa4\u4e2d\u7684\u8282\u70b9\u3001\u673a\u67b6\u3001\u533a\u57df\u7b49\u6982\u5ff5\uff0c\u901a\u8fc7 Kubernetes\u5185\u7f6e\u8282\u70b9\u6807\u7b7e\u4e2d\u7684key\u6765\u8fdb\u884c\u58f0\u660e\u3002\u8fd9\u4e2akey\u7684\u540d\u5b57\u4e3a<strong> topologyKey<\/strong>(\u62d3\u6251\u57df)\uff0c\u610f\u4e3a\u8868\u8fbe\u8282\u70b9\u6240\u5c5e\u7684topology\u8303\u56f4\u3002  <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> kubernetes.io\/hostname <\/li><li> failure-domain.beta.kubernetes.io\/zone <\/li><li> failure-domain.beta.kubernetes.io\/region <\/li><\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a<strong>topologyKey<\/strong>\u4e3b\u8981\u7528\u6765\u7b5b\u9009node\uff0c\u53ef\u4ee5\u7ed9\u4e00\u7ec4node\u6253\u4e0a\u6807\u7b7e\uff0c\u90a3\u4e48<strong>topologyKey<\/strong>\u7684\u503c\u4e5f\u53ef\u4ee5\u8bbe\u7f6e\u4e3a\u6b64\u6807\u7b7e\uff0c\u8868\u793a\u4e00\u4e2a\u62d3\u6251\u57df<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e\u8282\u70b9\u4e0d\u540c\u7684\u662f\uff0cPod\u662f\u5c5e\u4e8e\u67d0\u4e2a\u547d\u540d\u7a7a\u95f4\u7684\uff0c\u6240\u4ee5\u6761\u4ef6Y\u8868\u8fbe\u7684 \u662f\u4e00\u4e2a\u6216\u8005\u5168\u90e8\u547d\u540d\u7a7a\u95f4\u4e2d\u7684\u4e00\u4e2aLabel Selector\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c\u8282\u70b9\u4eb2\u548c\u6027\u76f8\u540c\uff0cPod\u4eb2\u548c\u4e0e\u4e92\u65a5\u7684\u6761\u4ef6\u8bbe\u7f6e\u4e5f\u662f requiredDuringSchedulingIgnoredDuringExecution(\u786c\u7b56\u7565)\u548c preferredDuringSchedulingIgnoredDuringExecution(\u8f6f\u7b56\u7565)\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Pod\u7684\u4eb2\u548c\u6027\u88ab\u5b9a\u4e49\u4e8ePodSpec\u7684affinity\u5b57\u6bb5\u4e0b\u7684<strong>podAffinity<\/strong>\u5b50\u5b57\u6bb5\u4e2d\u3002Pod\u95f4\u7684\u4e92\u65a5\u6027\u5219\u88ab\u5b9a\u4e49\u4e8e\u540c\u4e00\u5c42\u6b21\u7684<strong>podAntiAffinity<\/strong>\u5b50\u5b57\u6bb5\u4e2d\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u901a\u8fc7\u5b9e\u4f8b\u6765\u8bf4\u660ePod\u95f4\u7684\u4eb2\u548c\u6027\u548c\u4e92\u65a5\u6027\u7b56\u7565\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1\u3001\u53c2\u7167\u7684\u76ee\u6807pod<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u5728\u547d\u4ee4\u7a7a\u95f4gongguan\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u5b57\u4e3anginx\u7684nginx\u5e94\u7528\u7684pod\uff0cpod\u6807\u7b7e\u4e3aapp: nginx-pod\uff0c \u540e\u9762\u7684\u4f8b\u5b50\u5c06\u4f7f\u7528nginx\u4f5c\u4e3aPod\u4eb2\u548c\u4e0e\u4e92\u65a5\u7684\u76ee\u6807Pod\uff1a \u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"384\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-5.png\" alt=\"\" class=\"wp-image-7894\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-5.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-5-300x163.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/6-5-600x325.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa\u5b8c\u6210\u540e\uff0c\u5728\u547d\u540d\u7a7a\u95f4gongguan\u4e2d\u53ef\u4ee5\u67e5\u770b\u5230Pod\u5728\u8282\u70b9k8s-node1\u4e0a\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"104\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-6.png\" alt=\"\" class=\"wp-image-7898\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-6.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-6-300x44.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/9-6-600x88.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u63a5\u4e0b\u6765\u5728\u547d\u540d\u7a7a\u95f4gongguan\u521b\u5efa\u4e00\u4e2aredis\u5e94\u7528\u7684pod\u6765\u8bf4\u660epod\u4eb2\u548c\u5ea6\uff0c\u5b9a\u4e49\u7684\u4eb2\u548c\u5ea6\u6807\u7b7e\u4e3aapp:=nginx-pod\uff0c\u5bf9\u5e94\u7b2c\u4e00\u6b65\u4e2d\u7684pod\uff0c topologyKey\u7684\u503c\u88ab\u8bbe\u7f6e\u4e3a&#8221; kubernetes.io\/hostname &#8220;,\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"529\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-7.png\" alt=\"\" class=\"wp-image-7902\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-7.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-7-300x224.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/10-7-600x449.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u4eb2\u548c\u6027\u662f\u5173\u8054\u7684pod\u6807\u7b7e\uff01\uff01\uff01\uff01\uff01\uff0c\u4e0d\u662fdeployment\u4e2d\u7684\u6807\u7b7e<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u6b64Pod\u5728\u4eb2\u548c\u6027\u4f4d\u7f6e\u8bbe\u7f6e\u7684\u6807\u7b7e\u4e3a\u7b2c\u4e00\u6b65\u5b9a\u4e49\u7684app=nginx-pod\u6807\u7b7e\uff0c\u8868\u793a\u6b64pod\u4e0e\u7b2c\u4e00\u6b65\u5b9a\u4e49\u7684pod\u4eb2\u548c\u5ea6\u9ad8\uff0c\u521b\u5efa\u5b8c\u540e\uff0c\u5728\u547d\u540d\u7a7a\u95f4\u67e5\u770bpod\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"118\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-6.png\" alt=\"\" class=\"wp-image-7905\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-6.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-6-300x50.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/11-6-600x100.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece\u4e0a\u56fe\u53ef\u4ee5\u770b\u51fa\uff0c\u65b0\u8fd0\u884c\u7684\u540d\u79f0\u4e3aredis\u7684pod\u548c\u65e7\u7684nginx\u7684pod \u90fd\u5728\u540c\u4e00\u4e2a\u8282\u70b9\u4e0a\uff0c\u7b2c\u4e8c\u4e2a\u4f9d\u636e\u4eb2\u548c\u6027\u627e\u5230\u7b2c\u4e00\u4e2apod<\/p>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a\u5f53\u7b2c\u4e00\u6b65\u4e2d\u7684pod\u5982\u679c\u91cd\u65b0\u8c03\u5ea6\u5230\u5176\u4ed6\u8282\u70b9\u540e\uff0c\u7b2c\u4e8c\u6b65\u7684pod\u5728\u91cd\u65b0\u521b\u5efa\u540e\u4e5f\u4f1a\u8c03\u5ea6\u8fc7\u53bb<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">redis.yaml\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: redis                     #deployment\u540d\u5b57\n  namespace: gongguan             #\u547d\u540d\u7a7a\u95f4\n  labels:\n    app: redis\nspec:\n  selector:\n    matchLabels:\n      app: redis-pod             #\u7ba1\u7406\u6807\u7b7e\u4e3anginx-pod\u7684pod\n  replicas: 2                    #\u526f\u672c\u4e2a\u6570\u4e3a2\n  template:                      #\u521b\u5efapod\u7684\u6a21\u677f\n    metadata:\n      labels:\n        app: redis-pod           #pod\u6807\u7b7e\uff0c\u6807\u7b7e\u9009\u62e9\u5668\u5c31\u662f\u9009\u62e9\u8fd9\u4e2a\u6807\u7b7e\n    spec:\n      containers:\n      - name: redis\n        image: redis\n        ports:\n        - containerPort: 6379\n        imagePullPolicy: IfNotPresent\n      affinity:\n        podAffinity:\n          requiredDuringSchedulingIgnoredDuringExecution:\n          - labelSelector:\n              matchExpressions:\n              - key: app        #\u5173\u8054\u7684pod\u6807\u7b7e\u7684\u952e\n                operator: In\n                values:\n                - nginx-pod     #\u5173\u8054\u7684pod\u6807\u7b7e\u7684\u503c\n            topologyKey: kubernetes.io\/hostname<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u63a5\u4e0b\u6765\u5728\u547d\u540d\u7a7a\u95f4gongguan\u4e2d\u521b\u5efa\u540d\u79f0\u4e3aredis-app\u7684Pod\uff0c\u7528\u6765\u8bf4\u660ePod\u4e4b\u95f4\u7684\u4e92\u65a5\u6027(\u53cd\u4eb2\u548c\u6027)\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"437\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/12-4.png\" alt=\"\" class=\"wp-image-7910\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/12-4.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/12-4-300x185.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2022\/03\/12-4-600x369.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u901a\u8fc7\u786c\u7b56\u7565\u7684\u5f62\u5f0f\uff0c\u8bbe\u5b9a\u6b64Pod\u4e0d\u4f1a\u8c03\u5ea6\u5230\u548c\u5177\u6709\u6807\u7b7eapp=nginx-pod\u7684pod\u5728\u540c\u4e00\u4e2aNode\u4e0a\uff0c\u53cd\u4eb2\u548c\u6027\u5c31\u662f\u5c06\u4eb2\u548c\u6027\u4e2d\u7684<strong>podAffinity<\/strong>\u6539\u4e3a<strong>podAntiAffinity<\/strong>\u5373\u53ef\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e\u8282\u70b9\u4eb2\u548c\u6027\u7c7b\u4f3c\uff0cPod\u4eb2\u548c\u6027\u7684\u64cd\u4f5c\u7b26\u4e5f\u5305\u62ecIn\u3001NotIn\u3001Exists\u3001 DoesNotExist\u3001Gt\u3001Lt <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1a \u539f\u5219\u4e0a\uff0ctopologyKey\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u5408\u6cd5\u7684\u6807\u7b7eKey\u8d4b\u503c\uff0c\u4f46\u662f\u51fa\u4e8e\u6027\u80fd\u548c\u5b89\u5168\u65b9\u9762\u7684\u8003\u8651\uff0c\u5bf9topologyKey\u6709\u5982\u4e0b\u9650\u5236\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u5728Pod\u4eb2\u548c\u6027\u548cRequiredDuringScheduling\u7684Pod\u4e92\u65a5\u6027\u7684\u5b9a\u4e49\u4e2d\uff0c\u4e0d\u5141\u8bb8\u4f7f\u7528\u7a7a\u7684topologyKey<\/li><li>  \u5982\u679cAdmission controller\u5305\u542b\u4e86 LimitPodHardAntiAffinityTopology\uff0c\u90a3\u4e48\u9488\u5bf9Required DuringScheduling \u7684Pod\u4e92\u65a5\u6027\u5b9a\u4e49\u5c31\u88ab\u9650\u5236\u4e3akubernetes.io\/hostname\uff0c\u8981\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684 topologyKey\uff0c\u5c31\u8981\u6539\u5199\u6216\u7981\u7528\u8be5\u63a7\u5236\u5668 <\/li><li> \u5728PreferredDuringScheduling\u7c7b\u578b\u7684Pod\u4e92\u65a5\u6027\u5b9a\u4e49\u4e2d\uff0c\u7a7a\u7684topologyKey\u4f1a\u88ab\u89e3\u91ca\u4e3akubernetes.io\/hostname\u3001failuredomain.beta.kubernetes.io\/zone\u53cafailuredomain.beta.kubernetes.io\/region\u7684 \u7ec4\u5408\u3002 <\/li><li> \u5982\u679c\u4e0d\u662f\u4e0a\u8ff0\u60c5\u51b5\uff0c\u5c31\u53ef\u4ee5\u91c7\u7528\u4efb\u610f\u5408\u6cd5\u7684topologyKey\u4e86\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"> PodAffinity\u89c4\u5219\u8bbe\u7f6e\u7684\u6ce8\u610f\u4e8b\u9879\u5982\u4e0b \uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u9664\u4e86\u8bbe\u7f6eLabel Selector\u548ctopologyKey\uff0c\u7528\u6237\u8fd8\u53ef\u4ee5\u6307\u5b9a Namespace\u5217\u8868\u6765\u8fdb\u884c\u9650\u5236\uff0c\u540c\u6837\uff0c\u4f7f\u7528Label Selector\u5bf9Namespace\u8fdb\u884c\u9009\u62e9\u3002Namespace\u7684\u5b9a\u4e49\u548cLabel Selector\u53catopologyKey\u540c\u7ea7\u3002\u7701\u7565 Namespace\u7684\u8bbe\u7f6e\uff0c\u8868\u793a\u4f7f\u7528\u5b9a\u4e49\u4e86affinity\/anti-affinity\u7684Pod\u6240\u5728\u7684 Namespace\u3002\u5982\u679cNamespace\u88ab\u8bbe\u7f6e\u4e3a\u7a7a\u503c\uff08&#8221;&#8221;\uff09\uff0c\u5219\u8868\u793a\u6240\u6709 Namespace\u3002 <\/li><li> \u5728\u6240\u6709\u5173\u8054requiredDuringSchedulingIgnoredDuringExecution\u7684 matchExpressions\u5168\u90fd\u6ee1\u8db3\u4e4b\u540e\uff0c\u7cfb\u7edf\u624d\u80fd\u5c06Pod\u8c03\u5ea6\u5230\u67d0\u4e2aNode\u4e0a <\/li><\/ul>\n\n\n\n<p class=\"has-vivid-purple-color has-text-color has-normal-font-size wp-block-paragraph\"><strong>\u56db\u3001 Taints\u548cTolerations\uff08\u6c61\u70b9\u548c\u5bb9\u5fcd)<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u524d\u9762\u4ecb\u7ecd\u7684NodeAffinity\u8282\u70b9\u4eb2\u548c\u6027\uff0c\u662f\u5728Pod\u4e0a\u5b9a\u4e49\u7684\u4e00\u79cd\u5c5e\u6027\uff0c \u4f7f\u5f97Pod\u80fd\u591f\u88ab\u8c03\u5ea6\u5230\u67d0\u4e9bNode\u4e0a\u8fd0\u884c\uff08\u4f18\u5148\u9009\u62e9\u6216\u5f3a\u5236\u8981\u6c42\uff09\u3002Taint \u5219\u6b63\u597d\u76f8\u53cd\uff0c\u5b83\u8ba9Node<strong>\u62d2\u7eddPod\u7684\u8fd0\u884c<\/strong>\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Taint\u9700\u8981\u548cToleration\u914d\u5408\u4f7f\u7528\uff0c\u8ba9Pod\u907f\u5f00\u90a3\u4e9b\u4e0d\u5408\u9002\u7684Node\u3002\u5728 Node\u4e0a\u8bbe\u7f6e\u4e00\u4e2a\u6216\u591a\u4e2aTaint\u4e4b\u540e\uff0c\u9664\u975ePod\u660e\u786e\u58f0\u660e\u80fd\u591f\u5bb9\u5fcd\u8fd9\u4e9b\u6c61\u70b9\uff0c\u5426\u5219\u65e0\u6cd5\u5728\u8fd9\u4e9bNode\u4e0a\u8fd0\u884c\u3002Toleration\u662fPod\u7684\u5c5e\u6027\uff0c\u8ba9Pod\u80fd\u591f \uff08<strong>\u6ce8\u610f\uff0c\u53ea\u662f\u80fd\u591f\uff0c\u800c\u975e\u5fc5\u987b<\/strong>\uff09\u8fd0\u884c\u5728\u6807\u6ce8\u4e86Taint\u7684Node\u4e0a\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>1\u3001<\/strong>\u4e0b\u9762\u547d\u4ee4\u8868\u793a\u5728\u8282\u70b9k8s-node1\u6dfb\u52a0\u6c61\u70b9\uff0c \u8be5Taint\u7684\u952e\u4e3akey\uff0c\u503c\u4e3a value\uff0cTaint\u7684\u6548\u679c(effect)\u662fNoSchedule \uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"142\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25-1024x142.png\" alt=\"\" class=\"wp-image-4990\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25-1024x142.png 1024w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25-300x42.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25-768x106.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25-600x83.png 600w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/25.png 1026w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u4e0a\u56fe\u4e2d\u7684\u8bbe\u7f6e\u9664\u975ePod\u660e\u786e\u58f0\u660e\u53ef\u4ee5\u5bb9\u5fcd\u8fd9\u4e2aTaint\uff0c\u5426\u5219\u5c31\u4e0d\u4f1a\u88ab\u8c03\u5ea6\u5230k8s-node1\u4e0a\u3002 <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u547d\u4ee4\u7a7a\u95f4\u4e2dtain\u4e2d\u521b\u5efapod\uff0c\u5e76\u901a\u8fc7\u8282\u70b9\u5b9a\u5411\u8c03\u5ea6nodeSelector\u5c06\u6b64pod\u8c03\u5ea6\u5230k8s-node1\uff0c\u4f1a\u63d0\u793aPending\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"937\" height=\"192\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/26.png\" alt=\"\" class=\"wp-image-4992\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/26.png 937w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/26-300x61.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/26-768x157.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/26-600x123.png 600w\" sizes=\"auto, (max-width: 937px) 100vw, 937px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6839\u636e\u4e8b\u4ef6\u67e5\u8be2\u663e\u793a\u6b64Node\u5df2\u7ecf\u8bbe\u7f6e\u4e86\u6c61\u70b9\uff0c\u5e76\u4e14\u6b64pod\u6ca1\u6709\u8bbe\u7f6e\u5bb9\u5fcd\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"900\" height=\"302\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/27.png\" alt=\"\" class=\"wp-image-4993\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/27.png 900w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/27-300x101.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/27-768x258.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/27-600x201.png 600w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>2\u3001<\/strong>\u4e0b\u9762\u5728\u6b64Pod\u4e2d\u6dfb\u52a0\u5bb9\u5fcd\u8bbe\u7f6e\uff0c\u8ba9\u6b64pod\u53ef\u4ee5\u5bb9\u5fcd\u5177\u6709\u6b64\u6c61\u70b9\u7684node\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"968\" height=\"410\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/28.png\" alt=\"\" class=\"wp-image-4996\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/28.png 968w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/28-300x127.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/28-768x325.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/28-600x254.png 600w\" sizes=\"auto, (max-width: 968px) 100vw, 968px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd8\u6709\u7b2c\u4e8c\u79cd\u8bbe\u7f6e\u529e\u6cd5\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"968\" height=\"383\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/29.png\" alt=\"\" class=\"wp-image-4997\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/29.png 968w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/29-300x119.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/29-768x304.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/29-600x237.png 600w\" sizes=\"auto, (max-width: 968px) 100vw, 968px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Pod\u7684Toleration\u58f0\u660e\u4e2d\u7684key\u548ceffect\u9700\u8981\u4e0eTaint\u7684\u8bbe\u7f6e\u4fdd\u6301\u4e00\u81f4\uff0c \u5e76\u4e14\u6ee1\u8db3\u4ee5\u4e0b\u6761\u4ef6\u4e4b\u4e00\uff1a <\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> operator\u7684\u503c\u662fExists\uff08\u65e0\u987b\u6307\u5b9avalue)<\/li><li> operator\u7684\u503c\u662fEqual\u5e76\u4e14value\u76f8\u7b49<\/li><\/ul>\n\n\n\n<p class=\"has-luminous-vivid-amber-background-color has-background wp-block-paragraph\">\u6ce8\u610f\uff1a \u5982\u679c\u4e0d\u6307\u5b9aoperator\uff0c\u5219\u9ed8\u8ba4\u503c\u4e3aEqual<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> \u53e6\u5916\uff0c\u6709\u5982\u4e0b\u4e24\u4e2a\u7279\u4f8b:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u7a7a\u7684key\u914d\u5408Exists\u64cd\u4f5c\u7b26\u80fd\u591f\u5339\u914d\u6240\u6709\u7684\u952e\u548c\u503c <\/li><li> \u7a7a\u7684effect\u5339\u914d\u6240\u6709\u7684effect<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0ceffect\u7684\u53d6\u503c\u4e3aNoSchedule\uff0c\u8fd8\u53ef\u4ee5\u53d6\u503c\u4e3a PreferNoSchedule\uff0c\u8fd9\u4e2a\u503c\u7684\u610f\u601d\u662f\u4f18\u5148\uff0c\u4e5f\u53ef\u4ee5\u7b97\u4f5cNoSchedule\u7684\u8f6f\u9650\u5236\u7248\u672c\uff0c\u4e00\u4e2aPod\u5982\u679c\u6ca1\u6709\u58f0\u660e\u5bb9\u5fcd\u8fd9\u4e2aTaint\uff0c\u5219\u7cfb\u7edf\u4f1a\u5c3d\u91cf\u907f\u514d\u628a\u8fd9\u4e2aPod\u8c03\u5ea6\u5230\u8fd9\u4e00\u8282\u70b9\u4e0a\uff0c\u4f46\u4e0d\u662f\u5f3a\u5236\u7684\u3002\u540e\u9762\u8fd8\u4f1a\u4ecb\u7ecd\u53e6\u4e00\u4e2a effect &#8220;NoExecute&#8221;\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> \u7cfb\u7edf\u5141\u8bb8\u5728\u540c\u4e00\u4e2aNode\u4e0a\u8bbe\u7f6e\u591a\u4e2aTaint\uff0c\u4e5f\u53ef\u4ee5\u5728Pod\u4e0a\u8bbe\u7f6e\u591a\u4e2a Toleration\u3002Kubernetes\u8c03\u5ea6\u5668\u5904\u7406\u591a\u4e2aTaint\u548cToleration\u7684\u903b\u8f91\u987a\u5e8f\u4e3a\uff1a \u9996\u5148\u5217\u51fa\u8282\u70b9\u4e2d\u6240\u6709\u7684Taint\uff0c\u7136\u540e\u5ffd\u7565Pod\u7684Toleration\u80fd\u591f\u5339\u914d\u7684\u90e8\u5206\uff0c\u5269\u4e0b\u7684\u6ca1\u6709\u5ffd\u7565\u7684Taint\u5c31\u662f\u5bf9Pod\u7684\u6548\u679c\u4e86\u3002\u4e0b\u9762\u662f\u51e0\u79cd\u7279\u6b8a\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> \u5982\u679c\u5728\u5269\u4f59\u7684Taint\u4e2d\u5b58\u5728effect=NoSchedule\uff0c\u5219\u8c03\u5ea6\u5668\u4e0d\u4f1a\u628a\u8be5Pod\u8c03\u5ea6\u5230\u8fd9\u4e00\u8282\u70b9\u4e0a\u3002<\/li><li> \u5982\u679c\u5728\u5269\u4f59\u7684Taint\u4e2d\u6ca1\u6709NoSchedule\u6548\u679c\uff0c\u4f46\u662f\u6709 PreferNoSchedule\u6548\u679c\uff0c\u5219\u8c03\u5ea6\u5668\u4f1a\u5c1d\u8bd5\u4e0d\u628a\u8fd9\u4e2aPod\u6307\u6d3e\u7ed9\u8fd9\u4e2a\u8282\u70b9 <\/li><li> \u5982\u679c\u5728\u5269\u4f59\u7684Taint\u4e2d\u6709NoExecute\u6548\u679c\uff0c\u5e76\u4e14\u8fd9\u4e2aPod\u5df2\u7ecf\u5728\u8be5\u8282\u70b9\u4e0a\u8fd0\u884c\uff0c\u5219\u4f1a\u88ab\u9a71\u9010\uff1b\u5982\u679c\u6ca1\u6709\u5728\u8be5\u8282\u70b9\u4e0a\u8fd0\u884c\uff0c\u5219\u4e5f\u4e0d\u4f1a\u518d\u88ab\u8c03\u5ea6\u5230\u8be5\u8282\u70b9\u4e0a\u3002 <\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"> \u4e00\u822c\u6765\u8bf4\uff0c\u5982\u679c\u7ed9Node\u52a0\u4e0aeffect=NoExecute\u7684Taint\uff0c\u90a3\u4e48\u5728\u8be5 Node\u4e0a\u6b63\u5728\u8fd0\u884c\u7684\u6240\u6709\u65e0\u5bf9\u5e94Toleration\u7684Pod\u90fd\u4f1a\u88ab\u7acb\u523b\u9a71\u9010\uff0c\u800c\u5177\u6709\u76f8\u5e94Toleration\u7684Pod\u6c38\u8fdc\u4e0d\u4f1a\u88ab\u9a71\u9010\u3002   \u4e0d\u8fc7\uff0c\u7cfb\u7edf\u5141\u8bb8\u7ed9\u5177\u6709NoExecute \u6548\u679c\u7684Toleration\u52a0\u5165\u4e00\u4e2a\u53ef\u9009\u7684tolerationSeconds\u5b57\u6bb5\uff0c\u8fd9\u4e2a\u8bbe\u7f6e\u8868\u660e Pod\u53ef\u4ee5\u5728Taint\u6dfb\u52a0\u5230Node\u4e4b\u540e\u8fd8\u80fd\u5728\u8fd9\u4e2aNode\u4e0a\u8fd0\u884c\u591a\u4e45\uff08\u5355\u4f4d\u4e3a s)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff1a\u5728pod\u4e2d\u5b9a\u4e49Toleration\u5e76\u52a0\u5165tolerationSeconds\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"948\" height=\"384\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/30.png\" alt=\"\" class=\"wp-image-5007\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/30.png 948w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/30-300x122.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/30-768x311.png 768w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2021\/10\/30-600x243.png 600w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u8ff0\u5b9a\u4e49\u7684\u610f\u601d\u662f\uff0c\u5982\u679cPod\u6b63\u5728\u8fd0\u884c\uff0c\u6240\u5728\u8282\u70b9\u90fd\u88ab\u52a0\u5165\u4e00\u4e2a\u5339\u914d\u7684Taint\uff0c\u5219\u8fd9\u4e2aPod\u4f1a\u6301\u7eed\u5728\u8fd9\u4e2a\u8282\u70b9\u4e0a\u5b58\u6d3b120s\u540e\u88ab\u9010\u51fa\u3002\u5982\u679c\u5728\u8fd9\u4e2a\u5bbd\u9650\u671f\u5185Taint\u88ab\u79fb\u9664\uff0c\u5219\u4e0d\u4f1a\u89e6\u53d1\u9a71\u9010\u4e8b\u4ef6\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-purple-color\">\u4e94\u3001QoS<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5373\u4f7f\u5bf9Pod\u8fdb\u884c\u4e86\u8d44\u6e90\u9650\u5236\uff0c\u4f46\u662f\u5b9e\u9645\u4f7f\u7528\u65f6\u4f9d\u65e7\u4f1a\u9020\u6210\u8282\u70b9\u8d44\u6e90\u4e0d\u8db3\uff0c\u9488\u5bf9\u8d44\u6e90\u4e0d\u8db3Kubernetes\u4f1a\u901a\u8fc7\u91cd\u542f\u6216\u9a71\u9010Pod\u91ca\u653e\u8d44\u6e90\uff0c\u5982\u679c\u9a71\u9010\u4e86\u4e00\u4e9b\u91cd\u8981\u7684pod\u5c31\u4f1a\u5f88\u4e0d\u597d\uff0c\u9a71\u9010\u4ec0\u4e48\u6837\u7684pod\u662f\u901a\u8fc7QoS(\uff08Quality of Service\uff0c\u670d\u52a1\u8d28\u91cf)\u51b3\u5b9a\u7684<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Kubernetes\u4e3a\u6211\u4eec\u63d0\u4f9b\u4e863\u79cd\u7ea7\u522b\u7684\u670d\u52a1\u8d28\u91cf\uff0c\u5206\u522b\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Guaranteed\uff1a[\u02cc\u0261\u00e6r\u0259n\u02c8ti\u02d0d]\uff0c\u6700\u9ad8\u670d\u52a1\u8d28\u91cf\uff0c\u5f53\u5bbf\u4e3b\u673a\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u4f1a\u5148\u6740\u6b7bQoS\u4e3aBestEffort\u548cBurstable\u7684Pod\uff0c\u5982\u679c\u5185\u5b58\u8fd8\u662f\u4e0d\u591f\uff0c\u624d\u4f1a\u6740\u6b7bGuaranteed\u7684Pod\uff0c\u8be5\u7ea7\u522bPod\u7684\u8d44\u6e90\u5360\u7528\u91cf\u4e00\u822c\u6bd4\u8f83\u660e\u786e\uff0c\u5373requests\u5b57\u6bb5\u7684cpu\u548cmemory\u4e0elimits\u5b57\u6bb5\u7684cpu\u548cmemory\u914d\u7f6e\u7684\u4e00\u81f4<\/li><li>Burstable\uff1a\u670d\u52a1\u8d28\u91cf\u4f4e\u4e8eGuaranteed\uff0c\u5f53\u5bbf\u4e3b\u673a\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u4f1a\u5148\u6740\u6b7bQoS\u4e3aBestEffort\u7684Pod\uff0c\u5982\u679c\u5185\u5b58\u8fd8\u662f\u4e0d\u591f\uff0c\u5c31\u4f1a\u6740\u6b7bQoS\u7ea7\u522b\u4e3aBurstable\u7684Pod\uff0c\u7528\u6765\u4fdd\u8bc1QoS\u8d28\u91cf\u4e3aGuaranteed\u7684Pod\uff0c\u8be5\u7ea7\u522b\u7684Pod\u4e00\u822c\u77e5\u9053\u6700\u5c0f\u8d44\u6e90\u4f7f\u7528\u91cf\uff0c\u4f46\u662f\u5f53\u673a\u5668\u8d44\u6e90\u5145\u8db3\u65f6\uff0c\u8fd8\u662f\u60f3\u5c3d\u53ef\u80fd\u4f7f\u7528\u66f4\u591a\u7684\u8d44\u6e90\uff0c\u5373limits\u5b57\u6bb5\u7684cpu\u548cmemory\u5927\u4e8erequests\u5b57\u6bb5\u7684cpu\u548cmemory\u7684\u914d\u7f6e<\/li><li>BestEffort\uff1a\u5c3d\u529b\u800c\u4e3a\uff0c\u5f53\u5bbf\u4e3b\u673a\u5185\u5b58\u4e0d\u591f\u65f6\uff0c\u9996\u5148\u6740\u6b7b\u7684\u5c31\u662f\u8be5QoS\u7684Pod\uff0c\u7528\u4ee5\u4fdd\u8bc1Burstable\u548cGuaranteed\u7ea7\u522b\u7684Pod\u6b63\u5e38\u8fd0\u884c<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b9e\u73b0\u4e0d\u540c\u7ea7\u522b\u7684\u670d\u52a1\u8d28\u91cf\u662f\u6839\u636erequests\u548climits\u7684\u914d\u7f6e\u51b3\u5b9a\u7684<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Guaranteed\uff1arequests\u5b57\u6bb5\u7684cpu\u548cmemory\u4e0elimits\u5b57\u6bb5\u7684cpu\u548cmemory\u914d\u7f6e\u7684\u4e00\u81f4<\/li><li>Burstable\uff1arequests\u5b57\u6bb5\u7684cpu\u548cmemory\u503c\u5c0f\u4e8elimits\u5b57\u6bb5\u7684cpu\u548cmemory\u914d\u7f6e\u503c<\/li><li>BestEffort\uff1a\u4e0d\u914d\u7f6erequests\u548climits\u5b57\u6bb5<\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">1\u3001 \u4e0b\u9762\u4f8b\u5b50\u521b\u5efa\u4e00\u4e2apod\uff0c\u6ca1\u6709\u8bbe\u7f6elimits\u548crequests\u5b57\u6bb5\uff0c\u67e5\u770bOoS\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"707\" height=\"446\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/11-6.png\" alt=\"\" class=\"wp-image-11644\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/11-6.png 707w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/11-6-300x189.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/11-6-600x379.png 600w\" sizes=\"auto, (max-width: 707px) 100vw, 707px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770bQos\uff0c\u6b64\u65f6\u4e3aBestEffort\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"710\" height=\"86\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/12-6.png\" alt=\"\" class=\"wp-image-11645\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/12-6.png 710w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/12-6-300x36.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/12-6-600x73.png 600w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2\u3001\u4fee\u6539\u4e0a\u8ff0\u6e05\u5355\u6587\u4ef6\uff0c\u8bbe\u7f6elimits\u548crequests\u7684\u503c\u76f8\u7b49\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"586\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/13-6.png\" alt=\"\" class=\"wp-image-11647\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/13-6.png 712w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/13-6-300x247.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/13-6-600x494.png 600w\" sizes=\"auto, (max-width: 712px) 100vw, 712px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b\u5bb9\u5668\u7684Qos\uff0c\u503c\u4e3aGuaranteed\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"161\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/14-3.png\" alt=\"\" class=\"wp-image-11648\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/14-3.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/14-3-300x68.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/14-3-600x136.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3\u3001\u4fee\u6539\u4e0a\u8ff0\u6e05\u5355\u6587\u4ef6\uff0c\u8bbe\u7f6elimits\u5927\u4e8erequests\u7684\u503c\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"708\" height=\"578\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/15-3.png\" alt=\"\" class=\"wp-image-11649\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/15-3.png 708w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/15-3-300x245.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/15-3-600x490.png 600w\" sizes=\"auto, (max-width: 708px) 100vw, 708px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770b\u5bb9\u5668\u7684Qos\uff0c\u503c\u4e3aBurstable\uff0c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"709\" height=\"115\" src=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/16-2.png\" alt=\"\" class=\"wp-image-11651\" srcset=\"https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/16-2.png 709w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/16-2-300x49.png 300w, https:\/\/blog.ywdevops.cn\/wp-content\/uploads\/2023\/02\/16-2-600x97.png 600w\" sizes=\"auto, (max-width: 709px) 100vw, 709px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf4\u660e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>cpu\u4e3a0.1\u8868\u793a0.1\u9897cpu\uff0c1\u4e2acpu\u7b49\u4e8e1000m\uff0c\u56e0\u6b64\u8bbe\u7f6e0.1\u548c100m\u90fd\u884c<\/li><li>256mi\u8868\u793a\u5185\u5b58\u6b64\u65f6\u4f7f\u7528\u7684\u5c31\u662f256m\uff0c\u5982\u679c\u662fG\uff0c\u53ef\u8bbe\u7f6e\u4e3a1Gi\u30012Gi\u7b49<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5728Kubernetes\u5e73\u53f0\u4e0a\uff0c\u6211\u4eec\u5f88\u5c11\u4f1a\u76f4\u63a5\u521b\u5efa\u4e00\u4e2aPod\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\u4f1a\u901a\u8fc7RC\u3001Deployment\u3001D [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":4980,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[93],"tags":[],"class_list":["post-4952","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-kubernetes"],"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\/4952","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=4952"}],"version-history":[{"count":54,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/4952\/revisions"}],"predecessor-version":[{"id":11653,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/posts\/4952\/revisions\/11653"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media\/4980"}],"wp:attachment":[{"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/media?parent=4952"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/categories?post=4952"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ywdevops.cn\/index.php\/wp-json\/wp\/v2\/tags?post=4952"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}