{"id":97,"date":"2026-08-24T00:05:42","date_gmt":"2026-08-23T16:05:42","guid":{"rendered":"https:\/\/www.xiaoxindong.cloud\/?p=97"},"modified":"2026-09-06T19:57:52","modified_gmt":"2026-09-06T11:57:52","slug":"4-%e8%b5%84%e6%ba%90%e8%b0%83%e5%ba%a6%e4%b9%8b%e6%a0%87%e7%ad%be%e4%b8%8e%e6%8e%a7%e5%88%b6%e5%99%a8-%e5%a4%8d%e4%b9%a0%e8%b5%84%e6%96%99","status":"publish","type":"post","link":"https:\/\/www.xiaoxindong.cloud\/?p=97","title":{"rendered":"4. \u8d44\u6e90\u8c03\u5ea6\u4e4b\u6807\u7b7e\u4e0e\u63a7\u5236\u5668"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u6807\u7b7e Label<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6982\u5ff5<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6807\u7b7e\u662f\u9644\u52a0\u5728 K8s \u8d44\u6e90\uff08Pod\u3001Deployment\u3001Service \u7b49\uff09\u4e0a<strong>\u952e\u503c\u5bf9\u5143\u6570\u636e<\/strong>\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f5c\u7528\uff1a\u8d44\u6e90\u5206\u7ec4\u7b5b\u9009\uff0c\u63a7\u5236\u5668\u4f9d\u9760\u6807\u7b7e\u9009\u62e9\u5668\u5173\u8054\u7ba1\u7406 Pod<\/li>\n\n\n\n<li>\u63a7\u5236\u5668\u5de5\u4f5c\u539f\u7406\uff1a\u63a7\u5236\u5668<code>selector<\/code>\u6807\u7b7e\u9009\u62e9\u5668 \u2192 \u5339\u914d Pod \u6807\u7b7e \u2192 \u7ba1\u7406\u5339\u914d\u5230\u7684 Pod<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u7c7b\u6bd4\uff1a\u6807\u7b7e = \u8eab\u4efd\u8bc1\uff0c\u9009\u62e9\u5668 = \u5bfb\u4eba\u542f\u4e8b\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6807\u7b7e\u8bed\u6cd5\u89c4\u8303<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b57\u7b26\uff1a\u5927\u5c0f\u5199\u5b57\u6bcd\u3001\u6570\u5b57\u3001<code>-_.<\/code><\/li>\n\n\n\n<li>key \u6700\u5927 253 \u5b57\u7b26\uff0cvalue \u6700\u5927 63 \u5b57\u7b26<\/li>\n\n\n\n<li>\u4e0d\u80fd\u4ee5\u7279\u6b8a\u7b26\u53f7\u5f00\u5934\uff0c\u4e0d\u80fd\u5e26\u7a7a\u683c<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u5b98\u65b9\u6807\u51c6\u6807\u7b7e\uff08<code>app.kubernetes.io\/*<\/code>\uff09<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>labels:\n  app.kubernetes.io\/name: \"nginx\"        #\u5e94\u7528\u540d\u79f0\n  app.kubernetes.io\/instance: \"nginx-01\" #\u5b9e\u4f8b\u540d\u79f0\n  app.kubernetes.io\/version: \"1.27\"      #\u7248\u672c\n  app.kubernetes.io\/component: \"web\"    #\u7ec4\u4ef6\u7c7b\u578b\n  app.kubernetes.io\/part-of: \"shop\"      #\u6240\u5c5e\u4e0a\u5c42\u5e94\u7528\n  app.kubernetes.io\/managed-by: \"helm\"   #\u7ba1\u7406\u5de5\u5177\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u6807\u7b7e\u5e38\u7528\u547d\u4ee4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u521b\u5efapod\u5e26\u6807\u7b7e\nkubectl run nginx --image=nginx --labels=\"app=nginx,env=test\"\n\n#\u7ed9\u5df2\u6709pod\u6253\u6807\u7b7e\nkubectl label pod nginx env=prod\n\n#\u8986\u76d6\u5df2\u6709\u6807\u7b7e\uff0c\u5fc5\u987b\u52a0--overwrite\nkubectl label pod nginx env=dev --overwrite\n\n#\u5220\u9664\u6807\u7b7e\uff0ckey\u540e\u9762\u52a0\"-\"\nkubectl label pod nginx env-\n\n#\u67e5\u770b\u5e76\u663e\u793a\u6807\u7b7e\nkubectl get pod --show-labels\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u6807\u7b7e\u9009\u62e9\u5668 Selector<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">\u2460\u7b49\u5f0f\u9009\u62e9\u5668\uff08<code>=<\/code>\u3001<code>!=<\/code>\uff09\uff0c\u903b\u8f91\u4e0e\uff08\u9017\u53f7\u5206\u9694\u540c\u65f6\u6ee1\u8db3\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get pod -l app=nginx,env=prod\nkubectl get pod -l env!=test\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u2461\u96c6\u5408\u9009\u62e9\u5668\uff08in \/notin\/exists\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>#in\uff1a\u503c\u5c5e\u4e8e\u96c6\u5408\u4e2d\u4efb\u610f\u4e00\u4e2a\nkubectl get pod -l \"env in (dev,test)\"\n#notin\uff1a\u4e0d\u5728\u96c6\u5408\nkubectl get pod -l \"env notin (prod)\"\n#exists\uff1a\u6807\u7b7ekey\u5b58\u5728\uff0c\u4e0d\u7ba1value\nkubectl get pod -l env\n#!key\uff1a\u6807\u7b7ekey\u4e0d\u5b58\u5728\nkubectl get pod -l '!env'\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u6ce8\u610f\uff1ayaml \u4e2d\u63a7\u5236\u5668<code>spec.selector.matchLabels<\/code>\u5fc5\u987b\u548c pod \u6a21\u677f labels \u5b8c\u5168\u5339\u914d\uff0c\u5426\u5219\u63a7\u5236\u5668\u65e0\u6cd5\u7ba1\u7406 Pod\u3002<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u65e0\u72b6\u6001\u670d\u52a1 vs \u6709\u72b6\u6001\u670d\u52a1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8868\u683c<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u7c7b\u578b<\/th><th>\u65e0\u72b6\u6001\u670d\u52a1 Stateless<\/th><th>\u6709\u72b6\u6001\u670d\u52a1 Stateful<\/th><\/tr><\/thead><tbody><tr><td>\u63a7\u5236\u5668<\/td><td><strong>Deployment<\/strong><\/td><td><strong>StatefulSet<\/strong><\/td><\/tr><tr><td>Pod \u8eab\u4efd<\/td><td>Pod \u540d\u79f0\u968f\u673a\uff0c\u91cd\u5efa\u8eab\u4efd\u6539\u53d8<\/td><td>Pod \u56fa\u5b9a\u540d\u79f0 web\u20110\/web\u20111\uff0c\u91cd\u5efa\u540d\u79f0\u4e0d\u53d8<\/td><\/tr><tr><td>\u7f51\u7edc\u6807\u8bc6<\/td><td>PodIP \u968f\u673a\u53d8\u5316<\/td><td>\u642d\u914d Headless Service \u83b7\u53d6\u7a33\u5b9a DNS \u57df\u540d<\/td><\/tr><tr><td>\u5b58\u50a8<\/td><td>\u91cd\u5efa\u6570\u636e\u4e22\u5931\uff0c\u5171\u4eab\u5b58\u50a8 \/emptyDir<\/td><td>\u6bcf\u4e2a Pod \u72ec\u7acb PVC\uff0c\u91cd\u5efa\u6302\u8f7d\u539f\u6709\u6570\u636e<\/td><\/tr><tr><td>\u542f\u505c\u987a\u5e8f<\/td><td>\u5e76\u884c\u542f\u505c\u65e0\u5e8f<\/td><td>\u6709\u5e8f\u521b\u5efa 0\u2192N\uff1b\u7f29\u5bb9\u9006\u5e8f N\u21920<\/td><\/tr><tr><td>\u9002\u7528\u573a\u666f<\/td><td>web\u3001nginx\u3001\u5fae\u670d\u52a1 API<\/td><td>MySQL\u3001Redis \u96c6\u7fa4\u3001Kafka\u3001Zookeeper<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u65e0\u72b6\u6001\uff1a\u6240\u6709 Pod \u5b8c\u5168\u7b49\u4ef7\uff0c\u53ef\u4ee5\u968f\u610f\u9500\u6bc1\u91cd\u5efa\uff1b \u6709\u72b6\u6001\uff1a\u6bcf\u4e2a Pod \u6709\u4e13\u5c5e\u8eab\u4efd\u3001\u4e13\u5c5e\u6570\u636e\uff0c\u4e0d\u80fd\u968f\u4fbf\u4e71\u5220\u4e71\u6362\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001K8s \u5404\u7c7b\u63a7\u5236\u5668\u603b\u89c8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8868\u683c<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u63a7\u5236\u5668<\/th><th>\u4f5c\u7528<\/th><th>\u5178\u578b\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td>ReplicaSet<\/td><td>\u4fdd\u8bc1\u6307\u5b9a Pod \u526f\u672c\u6570\uff1bDeployment \u5e95\u5c42\u4f9d\u8d56\uff0c\u4e00\u822c\u4e0d\u76f4\u63a5\u64cd\u4f5c<\/td><td>\u88ab Deployment \u8c03\u7528<\/td><\/tr><tr><td>Deployment<\/td><td><strong>\u65e0\u72b6\u6001\u5e94\u7528\uff0c\u6eda\u52a8\u66f4\u65b0\u3001\u7248\u672c\u56de\u9000\u3001\u91d1\u4e1d\u96c0\u53d1\u5e03<\/strong><\/td><td>web\u3001\u5fae\u670d\u52a1<\/td><\/tr><tr><td>StatefulSet<\/td><td>\u6709\u72b6\u6001\u5e94\u7528\uff0c\u7a33\u5b9a\u8eab\u4efd\u3001\u6709\u5e8f\u66f4\u65b0\u3001\u72ec\u7acb PVC<\/td><td>\u6570\u636e\u5e93\u3001\u5206\u5e03\u5f0f\u4e2d\u95f4\u4ef6<\/td><\/tr><tr><td>DaemonSet<\/td><td><strong>\u6bcf\u4e2a\uff08\u6307\u5b9a\uff09\u8282\u70b9\u8fd0\u884c\u4e14\u53ea\u8fd0\u884c 1 \u4e2a Pod<\/strong><\/td><td>\u65e5\u5fd7\u91c7\u96c6 filebeat\u3001\u76d1\u63a7 exporter\u3001\u7f51\u7edc\u63d2\u4ef6 calico<\/td><\/tr><tr><td>Job<\/td><td>\u4e00\u6b21\u6027\u4efb\u52a1\uff0c\u6267\u884c\u5b8c\u6210\u9000\u51fa<\/td><td>\u6570\u636e\u8fc1\u79fb\u3001\u811a\u672c\u6279\u5904\u7406<\/td><\/tr><tr><td>CronJob<\/td><td>\u5b9a\u65f6\u5468\u671f\u4efb\u52a1\uff0c\u57fa\u4e8e Job<\/td><td>\u5b9a\u65f6\u5907\u4efd\u3001\u5b9a\u65f6\u6e05\u7406\u65e5\u5fd7<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u81ea\u4e3b Pod\uff1a\u76f4\u63a5 kubectl run \/yaml \u521b\u5efa\uff0c\u5220\u9664\u4e0d\u4f1a\u81ea\u52a8\u91cd\u5efa\uff1b\u63a7\u5236\u5668\u7ba1\u7406 Pod\uff0c\u6545\u969c\u5220\u9664\u81ea\u52a8\u91cd\u5efa\uff0c\u7ef4\u6301\u671f\u671b\u526f\u672c\u3002<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">1.ReplicaSet\uff08\u526f\u672c\u96c6\uff09<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>apiVersion: <code>apps\/v1<\/code><\/li>\n\n\n\n<li>\u529f\u80fd\uff1a\u7ef4\u6301\u526f\u672c\u6570\u91cf\u3001\u6545\u969c\u81ea\u6108\u3001\u6269\u7f29\u5bb9\uff1b<strong>Deployment \u5e95\u5c42\u4f7f\u7528\uff0c\u751f\u4ea7\u4e0d\u76f4\u63a5\u5199 RS yaml<\/strong><\/li>\n\n\n\n<li>\u6838\u5fc3\u5b57\u6bb5\uff1a<code>replicas<\/code>\u671f\u671b\u526f\u672c\uff1b<code>selector<\/code>\u9009\u62e9\u5668\uff1b<code>template<\/code>Pod \u6a21\u677f<\/li>\n<\/ul>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f selector.matchLabels \u5fc5\u987b\u4e0e template.metadata.labels \u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n<\/blockquote>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get rs\nkubectl scale rs xxx --replicas=5\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001Deployment \u91cd\u70b9\uff08\u65e0\u72b6\u6001\u63a7\u5236\u5668\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5c42\u7ea7\u5173\u7cfb<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><code>Deployment \u2192 ReplicaSet \u2192 Pod<\/code> Deployment \u901a\u8fc7\u7ba1\u7406 ReplicaSet \u95f4\u63a5\u7ba1\u7406 Pod\uff1b\u6bcf\u4e00\u6b21\u7248\u672c\u66f4\u65b0\u751f\u6210\u65b0 ReplicaSet\uff0c\u65e7 RS \u4fdd\u7559\u7528\u4e8e\u56de\u9000\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6838\u5fc3 yaml \u5173\u952e\u5b57\u6bb5<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: nginx-deploy\nspec:\n  replicas: 3                     #\u671f\u671b\u526f\u672c\u6570\n  revisionHistoryLimit: 3        #\u4fdd\u7559\u5386\u53f2RS\u7248\u672c\u6570\u91cf\uff0c\u7528\u4e8e\u56de\u9000\n  strategy:                       #\u66f4\u65b0\u7b56\u7565\n    type: RollingUpdate           #\u9ed8\u8ba4\u6eda\u52a8\u66f4\u65b0\n    rollingUpdate:\n      maxSurge: 25%               #\u66f4\u65b0\u671f\u95f4\u5141\u8bb8\u8d85\u51fareplicas\u6700\u5927\u526f\u672c\u6570\n      maxUnavailable: 25%         #\u66f4\u65b0\u671f\u95f4\u5141\u8bb8\u6700\u5927\u4e0d\u53ef\u7528Pod\u6570\u91cf\n  selector:\n    matchLabels:\n      app: nginx\n  template:\n    metadata:\n      labels:\n        app: nginx\n    spec:\n      containers:\n      - name: nginx\n        image: nginx:1.27.1\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u4e24\u79cd\u66f4\u65b0\u7b56\u7565<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Recreate \u91cd\u5efa\u66f4\u65b0<\/strong>\uff1a\u5148\u5168\u90e8\u5220\u9664\u65e7 Pod\uff0c\u518d\u521b\u5efa\u5168\u90e8\u65b0 Pod\u3002<strong>\u4f1a\u4e1a\u52a1\u4e2d\u65ad\uff0c\u6d4b\u8bd5\u73af\u5883\u7528<\/strong><\/li>\n\n\n\n<li><strong>RollingUpdate \u6eda\u52a8\u66f4\u65b0\uff08\u9ed8\u8ba4\uff0c\u751f\u4ea7\uff09<\/strong>\uff1a\u9010\u6b65\u66ff\u6362 Pod\uff0c\u4e1a\u52a1\u4e0d\u4e2d\u65ad\n<ul class=\"wp-block-list\">\n<li><code>maxSurge<\/code>\uff1a\u6700\u591a\u53ef\u4ee5\u591a\u8dd1\u591a\u5c11 Pod\uff1b<\/li>\n\n\n\n<li><code>maxUnavailable<\/code>\uff1a\u6700\u591a\u5141\u8bb8\u591a\u5c11 Pod \u4e0d\u53ef\u7528\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5e38\u7528\u64cd\u4f5c\u547d\u4ee4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u547d\u4ee4\u521b\u5efa\nkubectl create deployment nginx --image=nginx --replicas=3\n\n#\u6269\u7f29\u5bb9\nkubectl scale deployment nginx --replicas=5\n\n#\u4fee\u6539\u955c\u50cf\u7248\u672c\nkubectl set image deployment nginx nginx=nginx:1.27.1\n\n#\u67e5\u770b\u5347\u7ea7\u5386\u53f2\nkubectl rollout history deployment nginx\n\n#\u6dfb\u52a0\u7248\u672c\u53d8\u66f4\u6ce8\u91ca\nkubectl annotate deployment nginx kubernetes.io\/change-cause=\"\u66f4\u65b0\u5230nginx1.27.1\"\n\n#\u56de\u9000\u4e0a\u4e00\u4e2a\u7248\u672c\nkubectl rollout undo deployment nginx\n#\u56de\u9000\u6307\u5b9arevision\u7248\u672c\nkubectl rollout undo deployment nginx --to-revision=1\n\n#\u67e5\u770b\u53d1\u5e03\u8fdb\u5ea6\nkubectl rollout status deployment nginx\n\n#\u91d1\u4e1d\u96c0\u53d1\u5e03\uff1a\u66f4\u65b0\u955c\u50cf\u5e76\u4e14\u6682\u505c\u66f4\u65b0\uff0c\u65b0\u65e7\u7248\u672c\u5171\u5b58\uff0c\u9a8c\u8bc1\u65b0\u7248\u672c\nkubectl set image deployment nginx nginx=nginx:1.28 &amp;&amp; kubectl rollout pause deployment nginx\n\n#\u7ee7\u7eed\u5b8c\u6210\u5168\u91cf\u66f4\u65b0\nkubectl rollout resume deployment nginx\n<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">\u2728\u91d1\u4e1d\u96c0\u53d1\u5e03\u539f\u7406\uff1apause \u6682\u505c\u6eda\u52a8\u66f4\u65b0\uff0c\u6b64\u65f6\u53ea\u521b\u5efa maxSurge \u6570\u91cf\u65b0\u7248\u672c Pod\uff0c\u65e7 Pod \u4fdd\u7559\uff1b\u5c0f\u6d41\u91cf\u9a8c\u8bc1\u65b0\u7248\u672c\uff0c\u6ca1\u95ee\u9898\u518d resume \u5168\u91cf\u5347\u7ea7\uff0c\u6709\u95ee\u9898\u76f4\u63a5 undo \u56de\u6eda\u3002<\/p>\n<\/blockquote>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e94\u3001StatefulSet \u6709\u72b6\u6001\u63a7\u5236\u5668\u2b50\u91cd\u70b9<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u6838\u5fc3\u7279\u6027<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Pod \u56fa\u5b9a\u547d\u540d\uff1a<code>web-0\u3001web-1\u3001web-2<\/code>\uff0c\u91cd\u5efa\u540d\u79f0\u4e0d\u53d8\uff1b<\/li>\n\n\n\n<li>\u9700\u8981\u642d\u914d<strong>Headless Service<\/strong>\uff0c\u7ed9 Pod \u63d0\u4f9b\u7a33\u5b9a DNS \u57df\u540d\uff1b<\/li>\n\n\n\n<li>\u6709\u5e8f\u7ba1\u7406\uff1a\n<ul class=\"wp-block-list\">\n<li>\u6269\u5bb9\uff1a\u5e8f\u53f7\u4ece\u5c0f\u5230\u5927 <code>0 \u21921\u21922<\/code>\uff0c\u524d\u4e00\u4e2a\u5c31\u7eea\u624d\u521b\u5efa\u4e0b\u4e00\u4e2a\uff1b<\/li>\n\n\n\n<li>\u7f29\u5bb9\uff1a\u5e8f\u53f7\u4ece\u5927\u5230\u5c0f <code>2\u21921\u21920<\/code>\uff0c\u5148\u5220\u6700\u5927\u5e8f\u53f7\uff1b<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>volumeClaimTemplates<\/code>\uff1a\u6a21\u677f\u81ea\u52a8\u521b\u5efa\u72ec\u7acb PVC\uff0c\u6bcf\u4e2a Pod \u4e13\u5c5e\u5b58\u50a8\uff0c\u91cd\u5efa\u6570\u636e\u4fdd\u7559\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u66f4\u65b0\u7b56\u7565<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>RollingUpdate<\/code>\uff08\u9ed8\u8ba4\uff09\n<ul class=\"wp-block-list\">\n<li><strong>\u9006\u5e8f\u66f4\u65b0\uff1a\u4ece\u6700\u5927\u5e8f\u53f7\u5f80\u5c0f\u5e8f\u53f7\u9010\u4e2a\u66f4\u65b0\uff1b\u4e32\u884c\uff0c\u4e00\u4e2a\u5c31\u7eea\u518d\u66f4\u65b0\u4e0b\u4e00\u4e2a<\/strong><\/li>\n\n\n\n<li>\u5173\u952e\u5b57\u6bb5<code>partition<\/code>\uff1a<strong>\u5206\u533a\u7070\u5ea6\u53d1\u5e03<\/strong>\n<ul class=\"wp-block-list\">\n<li><code>partition=N<\/code>\uff1a\u53ea\u66f4\u65b0\u5e8f\u53f7 \u2265 N \u7684 Pod\uff1b\u5c0f\u4e8e N \u4fdd\u6301\u65e7\u7248\u672c\u3002<\/li>\n\n\n\n<li>\u793a\u4f8b<code>partition=2<\/code>\uff1a\u53ea\u66f4\u65b0 web\u20112\u3001web\u20113\uff1bweb\u20110\u3001web\u20111 \u4fdd\u7559\u65e7\u7248\u672c\uff0c\u5b9e\u73b0\u91d1\u4e1d\u96c0\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>OnDelete<\/code>\uff1a\u4fee\u6539 sts \u6a21\u677f\u4e0d\u4f1a\u81ea\u52a8\u66f4\u65b0 Pod\uff1b<strong>\u5fc5\u987b\u624b\u52a8\u5220\u9664 Pod\uff0c\u5220\u9664\u540e\u624d\u7528\u65b0\u7248\u672c\u91cd\u5efa<\/strong>\uff1b\u9002\u5408\u6570\u636e\u5e93\u7b49\u6781\u9ad8\u7a33\u5b9a\u6027\u573a\u666f\u3002<\/li>\n<\/ol>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">StatefulSet<strong>\u6ca1\u6709 maxSurge\/maxUnavailable \u53c2\u6570<\/strong>\uff01<\/p>\n<\/blockquote>\n\n\n\n<h3 class=\"wp-block-heading\">StatefulSet \u91d1\u4e1d\u96c0\u53d1\u5e03\u6b65\u9aa4<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u8bbe\u7f6e partition\uff0c\u5212\u5b9a\u66f4\u65b0\u8fb9\u754c<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl patch statefulset mysql -p '{\"spec\":{\"updateStrategy\":{\"rollingUpdate\":{\"partition\":2}}}}'\n<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u66f4\u65b0\u955c\u50cf\uff0c\u89e6\u53d1\u66f4\u65b0\uff1b\u53ea\u6709\u5e8f\u53f7\u22652 \u7684 Pod \u5347\u7ea7\u65b0\u7248\u672c<\/li>\n\n\n\n<li>\u9a8c\u8bc1\u65b0\u7248\u672c\u4e1a\u52a1\u6b63\u5e38\uff0c\u9010\u6b65\u8c03\u5c0f partition \u76f4\u5230 0 \u5b8c\u6210\u5168\u90e8\u66f4\u65b0<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u5e38\u7528\u547d\u4ee4<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>kubectl get sts\n#\u6269\u5bb9\u7f29\u5bb9\nkubectl scale statefulset mysql --replicas=4\n#\u66f4\u65b0\u955c\u50cf\nkubectl set image statefulset mysql mysql=mysql:8.0\n#patch\u5c40\u90e8\u4fee\u6539\u8d44\u6e90\uff0c\u4e0d\u9700\u8981\u5b8c\u6574yaml\nkubectl patch\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u516d\u3001DaemonSet<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4e0d\u9700\u8981\u5199<code>replicas<\/code>\u526f\u672c\u6570\uff1b<\/li>\n\n\n\n<li>\u96c6\u7fa4\u6bcf\u4e2a\u7b26\u5408\u6761\u4ef6 Node \u8fd0\u884c<strong>\u6070\u597d\u4e00\u4e2a Pod<\/strong>\uff1b\u65b0\u589e\u8282\u70b9\u81ea\u52a8\u521b\u5efa Pod\uff0c\u8282\u70b9\u4e0b\u7ebf\u81ea\u52a8\u9500\u6bc1 Pod\uff1b<\/li>\n\n\n\n<li>\u53ef\u4ee5\u914d\u5408<code>nodeSelector\/nodeAffinity<\/code>\uff0c\u53ea\u5728\u90e8\u5206\u8282\u70b9\u90e8\u7f72\uff08\u5982 GPU \u8282\u70b9\uff09\u3002<\/li>\n\n\n\n<li>\u5178\u578b\u7528\u9014\uff1acalico \u7f51\u7edc\u63d2\u4ef6\u3001filebeat \u65e5\u5fd7\u91c7\u96c6\u3001node\u2011exporter \u76d1\u63a7\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">yaml \u7b80\u8981\u793a\u4f8b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apiVersion: apps\/v1\nkind: DaemonSet\nmetadata:\n  name: filebeat\nspec:\n  selector:\n    matchLabels:\n      app: filebeat\n  template:\n    metadata:\n      labels:\n        app: filebeat\n    spec:\n      containers:\n      - name: filebeat\n        image: filebeat:7.17\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e03\u3001Job &amp; CronJob\uff08\u4e00\u6b21\u6027 \/ \u5b9a\u65f6\u4efb\u52a1\uff09<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Job\uff1a\u4e00\u6b21\u6027\u4efb\u52a1<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7528\u9014\uff1a\u6279\u5904\u7406\u3001\u6570\u636e\u8fc1\u79fb\uff0c\u4efb\u52a1\u5b8c\u6210 Pod \u9000\u51fa\uff08exit0\uff09\uff0c\u72b6\u6001 Succeeded<\/li>\n\n\n\n<li>Job \u4e0b Pod<strong>\u91cd\u542f\u7b56\u7565\u53ea\u80fd\u7528\uff1a<code>OnFailure<\/code> \/ <code>Never<\/code>\uff0c\u7981\u6b62 Always<\/strong>\u3002<\/li>\n\n\n\n<li>\u53c2\u6570\uff1a<code>parallelism<\/code>\u5e76\u884c Pod \u6570\u91cf\uff1b<code>completions<\/code>\u9700\u8981\u6210\u529f\u5b8c\u6210\u6b21\u6570\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">CronJob\uff1a\u5b9a\u65f6\u4efb\u52a1<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u57fa\u4e8e crontab \u65f6\u95f4\u8868\u8fbe\u5f0f\uff0c\u5b9a\u65f6\u81ea\u52a8\u521b\u5efa Job \u5bf9\u8c61\u6267\u884c\u4efb\u52a1\uff1b<\/li>\n\n\n\n<li>\u5b57\u6bb5\uff1a<code>schedule: \"0 2 * * *\"<\/code>\uff08\u6bcf\u5929\u51cc\u6668\u4e24\u70b9\uff09\uff1b<\/li>\n\n\n\n<li>\u53ef\u914d\u7f6e\u4fdd\u5b58\u6210\u529f\u3001\u5931\u8d25 Job \u5386\u53f2\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u516b\u3001\u6c47\u603b<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Deployment \u548c StatefulSet \u533a\u522b<\/strong><\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Deployment\uff1a\u65e0\u72b6\u6001\uff1bPod \u540d\u79f0\u968f\u673a\uff1b\u5e76\u884c\u65e0\u5e8f\u542f\u505c\uff1b\u6eda\u52a8\u66f4\u65b0 maxSurge\/maxUnavailable\uff1b\u65e0\u4e13\u5c5e\u5b58\u50a8\uff1b\u9002\u5408 web \u5fae\u670d\u52a1\u3002<\/li>\n\n\n\n<li>StatefulSet\uff1a\u6709\u72b6\u6001\uff1bPod \u56fa\u5b9a\u5e8f\u53f7\u540d\u79f0\uff1b\u6709\u5e8f\u521b\u5efa\u9006\u5e8f\u5220\u9664\uff1b\u9006\u5e8f\u4e32\u884c\u66f4\u65b0\uff0c\u4f7f\u7528 partition \u505a\u7070\u5ea6\uff1b\u72ec\u7acb PVC \u6301\u4e45\u5b58\u50a8\uff1b\u9700\u8981 HeadlessService\uff1b\u9002\u5408\u6570\u636e\u5e93\u3001\u5206\u5e03\u5f0f\u4e2d\u95f4\u4ef6\u3002<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>StatefulSet partition \u4f5c\u7528\uff1f\u5982\u4f55\u5b9e\u73b0\u91d1\u4e1d\u96c0\uff1f<\/strong> partition \u662f\u66f4\u65b0\u5206\u533a\u9608\u503c\uff1b<strong>\u53ea\u66f4\u65b0\u5e8f\u53f7\u5927\u4e8e\u7b49\u4e8e partition \u7684 Pod<\/strong>\uff1b \u6d41\u7a0b\uff1a\u8bbe\u7f6e partition \u2192 \u66f4\u65b0\u955c\u50cf \u2192 \u9a8c\u8bc1\u9ad8\u5e8f\u53f7\u65b0\u7248\u672c Pod \u2192 \u9010\u6b65\u964d\u4f4e partition \u76f4\u81f3 0\uff0c\u5b8c\u6210\u5168\u91cf\u66f4\u65b0\u3002<\/li>\n\n\n\n<li><strong>Deployment \u91d1\u4e1d\u96c0\uff08pause\/resume\uff09\u539f\u7406<\/strong> \u66f4\u65b0\u955c\u50cf\u540e\u6267\u884c<code>rollout pause<\/code>\u6682\u505c\u6eda\u52a8\uff1b\u53ea\u751f\u6210 maxSurge \u6570\u91cf\u65b0\u7248\u672c Pod\uff0c\u65e7 Pod \u4fdd\u7559\uff1b\u5c0f\u6d41\u91cf\u9a8c\u8bc1\uff0c\u5f02\u5e38\u76f4\u63a5 undo \u56de\u6eda\uff1b\u9a8c\u8bc1\u6ca1\u95ee\u9898<code>rollout resume<\/code>\u5b8c\u6210\u5168\u90e8\u6eda\u52a8\u66f4\u65b0\u3002<\/li>\n\n\n\n<li><strong>DaemonSet \u4f5c\u7528\uff0c\u548c Deployment \u533a\u522b\uff1f<\/strong> DaemonSet \u6bcf\u4e2a\u8282\u70b9\u8fd0\u884c\u4e00\u4e2a Pod\uff0c\u7528\u4e8e\u8282\u70b9\u7ea7\u670d\u52a1\uff08\u65e5\u5fd7\u3001\u76d1\u63a7\u3001\u7f51\u7edc\u63d2\u4ef6\uff09\uff0c\u4e0d\u8bbe\u7f6e replicas\uff1bDeployment \u6307\u5b9a\u526f\u672c\u6570\uff0cPod \u968f\u673a\u8c03\u5ea6\u5230\u8282\u70b9\u3002<\/li>\n\n\n\n<li><strong>Job \u4e3a\u4ec0\u4e48\u4e0d\u80fd\u7528 restartPolicy:Always\uff1f<\/strong> Job \u662f\u4e00\u6b21\u6027\u4efb\u52a1\uff0c\u5982\u679c Always\uff0c\u4efb\u52a1\u6267\u884c\u5b8c\u6210\u9000\u51fa\u540e\u4f1a\u65e0\u9650\u53cd\u590d\u91cd\u542f Pod\uff0c\u4e0d\u7b26\u5408\u4e00\u6b21\u6027\u4efb\u52a1\u8bed\u4e49\u3002<\/li>\n\n\n\n<li><strong>\u6807\u7b7e\u548c\u6807\u7b7e\u9009\u62e9\u5668\u7684\u4f5c\u7528<\/strong> \u6807\u7b7e\u662f\u8d44\u6e90\u7684\u952e\u503c\u5bf9\u5143\u6570\u636e\uff0c\u7528\u4e8e\u5206\u7c7b\uff1b\u63a7\u5236\u5668\u4f9d\u9760\u6807\u7b7e\u9009\u62e9\u5668\u7b5b\u9009\u5339\u914d\u6807\u7b7e\u7684 Pod\uff0c\u5b9e\u73b0\u6269\u7f29\u5bb9\u3001\u81ea\u6108\u7ba1\u7406\u3002<\/li>\n\n\n\n<li><strong>Replicaset \u548c Deployment \u5173\u7cfb\uff1f<\/strong> Deployment \u5e95\u5c42\u7ba1\u7406 ReplicaSet\uff1b\u6bcf\u6b21\u7248\u672c\u66f4\u65b0\u4ea7\u751f\u65b0 ReplicaSet\uff1b\u65e7 ReplicaSet \u4fdd\u7559\uff0c\u7528\u4e8e\u7248\u672c\u56de\u9000\uff1b\u4e00\u822c\u4e0d\u76f4\u63a5\u64cd\u4f5c ReplicaSet\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e5d\u3001\u91cd\u8981\u547d\u4ee4\u6c47\u603b<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#\u6807\u7b7e\nkubectl label\nkubectl get pod -l \/ --show-labels\n\n#deployment\nkubectl scale\nkubectl set image\nkubectl rollout history \/ undo \/ status \/ pause \/ resume\n\n#statefulset\nkubectl patch\nkubectl scale sts\n\n#\u67e5\u770b\u5404\u7c7b\u63a7\u5236\u5668\nkubectl get deploy,rs,sts,ds,job,cronjob<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u6807\u7b7e Label 1. \u6982\u5ff5 \u6807\u7b7e\u662f\u9644\u52a0\u5728 K8s \u8d44\u6e90\uff08Pod\u3001Deployment\u3001Service \u7b49 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":3,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xiaoxindong.cloud\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}