{"id":11977,"date":"2023-08-20T16:43:06","date_gmt":"2023-08-20T08:43:06","guid":{"rendered":"http:\/\/92it.top\/?p=11977"},"modified":"2025-07-21T21:02:54","modified_gmt":"2025-07-21T13:02:54","slug":"k8s%e6%b7%b1%e5%85%a5%e5%ad%a6%e4%b9%a0-health-check","status":"publish","type":"post","link":"https:\/\/92it.top\/?p=11977","title":{"rendered":"K8S\u6df1\u5165\u5b66\u4e60 Health Check"},"content":{"rendered":"\n<p>\u8f6c\u8f7d\uff1a<a href=\"https:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_k8s_deepstudy_part6.html\">https:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_k8s_deepstudy_part6.html<\/a><\/p>\n\n\n\n<p><strong>\u4e00\u3001\u5173\u4e8eK8S\u4e2d\u7684Health Check<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"788\" height=\"454\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204.png\" alt=\"\" class=\"wp-image-11978\" style=\"width:465px;height:268px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204.png 788w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204-300x173.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204-768x442.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204-230x133.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204-350x202.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-204-480x277.png 480w\" sizes=\"(max-width: 788px) 100vw, 788px\" \/><\/figure><\/div>\n\n\n<p>\u6240\u8c13Health Check\uff0c\u5c31\u662f\u5065\u5eb7\u68c0\u67e5\uff0c\u5373\u9632\u5fae\u675c\u6e10\u3002K8S\u662f\u4e00\u4e2a\u7f16\u6392\u5f15\u64ce\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5feb\u6377\u5730\u90e8\u7f72\u5bb9\u5668\u96c6\u7fa4\uff0c\u5982\u679c\u90e8\u7f72\u4e0a\u9519\u8bef\u7684\u5bb9\u5668\u5bfc\u81f4\u670d\u52a1\u5d29\u6e83\uff0c\u901a\u5e38\u60c5\u51b5\u4e0b\u6211\u4eec\u90fd\u4f1a\u901a\u8fc7\u4e00\u4e9b\u9ad8\u53ef\u7528\u673a\u5236\u8fdb\u884c\u6545\u969c\u8f6c\u79fb\u3002\u4f46\u662f\uff0c\u524d\u63d0\u6761\u4ef6\u662f\u6709\u5065\u5eb7\u68c0\u67e5\u3002<\/p>\n\n\n\n<p>K8S\u81ea\u7136\u5e2e\u6211\u4eec\u8003\u8651\u5230\u4e86\u8fd9\u4e2a\u95ee\u9898\uff0c\u5065\u5eb7\u68c0\u67e5\u662fK8S\u7684\u91cd\u8981\u7279\u6027\u4e4b\u4e00\uff0c\u9ed8\u8ba4\u6709\u5065\u5eb7\u68c0\u67e5\u673a\u5236\uff0c\u6b64\u5916\u8fd8\u53ef\u4ee5\u4e3b\u52a8\u8bbe\u7f6e\u4e00\u4e9b\u81ea\u5b9a\u4e49\u7684\u5065\u5eb7\u68c0\u67e5\u3002<\/p>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u5bb9\u5668\u542f\u52a8\u65f6\u90fd\u4f1a\u6267\u884c\u4e00\u4e2a\u8fdb\u7a0b\uff0c\u7531Dockerfile\u4e2d\u7684CMD\u6216ENTRYPOINT\u6307\u5b9a\u3002\u5982\u679c\u8fdb\u7a0b\u9000\u51fa\u65f6\u7684\u8fd4\u56de\u7801\u4e0d\u4e3a0\uff0c\u5219\u8ba4\u4e3a\u5bb9\u5668\u53d1\u751f\u4e86\u6545\u969c\uff0cK8S\u4f1a\u6839\u636e\u91cd\u542f\u7b56\u7565\uff08restartPolicy\uff09\u91cd\u542f\u5bb9\u5668\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\u4e0b\u9762\u8fd9\u4e2a\u4f8b\u5b50\uff0c\u5b83\u6a21\u62df\u4e86\u5bb9\u5668\u53d1\u751f\u6545\u969c\u7684\u573a\u666f\uff0c\u6ce8\u610f\u4e0b\u9762\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684args\u9009\u9879\u7684\u5b9a\u4e49\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  name: edc-healthcheck-demo\n  labels:\n    test: healthcheck\nspec:\n  restartPolicy: OnFailure\n  containers:\n    - name: healthcheck\n      image: busybox\n      imagePullPolicy: IfNotPresent\n      args:\n      - \/bin\/sh\n      - -c\n      - sleep 10; exit 1<\/pre>\n\n\n\n<p>\u5176\u4e2d sleep 10; exit 1\u4ee3\u8868\u542f\u52a810\u79d2\u4e4b\u540e\u5c31\u975e\u6b63\u5e38\u9000\u51fa\uff08\u8fd4\u56de\u7801\u4e0d\u4e3a0\uff09\uff0c\u7136\u540e\u901a\u8fc7kubectl\u521b\u5efaPod\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f health-check.yaml<\/pre>\n\n\n\n<p>\u8fc7\u4e00\u6bb5\u65f6\u95f4\u540e\u67e5\u770bPod\u7684\u72b6\u6001\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"385\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-1024x385.png\" alt=\"\" class=\"wp-image-11979\" style=\"width:563px;height:211px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-1024x385.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-300x113.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-768x289.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-830x312.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-230x87.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-350x132.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205-480x181.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-205.png 1212w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u53ef\u4ee5\u770b\u5230\uff0c\u8be5\u5bb9\u5668\u5df2\u7ecf\u91cd\u542f\u4e862\u6b21\u3002\u4e5f\u53ef\u4ee5\u770b\u51fa\uff0crestartPolicy\u7b80\u5355\u76f4\u63a5\u66b4\u529b\u6709\u6548\uff0c\u4e0d\u7531\u611f\u53f9\u91cd\u542f\u5927\u6cd5\u597d\uff01<\/p>\n\n\n\n<p>\u4f46\u662f\uff0c\u4e5f\u8981\u6b63\u89c6\u4e00\u4e2a\u95ee\u9898\uff1a<strong>\u5fc5\u987b\u7b49\u5230\u8fdb\u7a0b\u9000\u51fa\u540e\u7684\u8fd4\u56de\u503c\u662f\u975e\u96f6\u624d\u4f1a\u89e6\u53d1\u91cd\u542f\u7b56\u7565\uff0c\u4e0d\u80fd\u76f4\u63a5\u76d1\u6d4b\u5bb9\u5668\u662f\u5426\u662f\u5065\u5eb7<\/strong>\u3002<\/p>\n\n\n\n<p>\u90a3\u4e48\uff0cK8S\u4e2d\u6709\u6ca1\u6709\u66f4\u597d\u7684\u673a\u5236\u80fd\u591f\u5b9e\u73b0\u667a\u80fd\u4e00\u70b9\u7684\u5065\u5eb7\u68c0\u67e5\u5462\uff1f\u7b54\u6848\u5c31\u662f\u4f7f\u7528Liveness\u4e0eReadinesss\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e8c\u3001Liveness\u63a2\u6d4b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><strong>2.1 Liveness\u521d\u4f53\u9a8c<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4e00\u53e5\u8bddLiveness\uff1a\u5982\u679c\u68c0\u6d4b\u6709\u95ee\u9898\uff08\u5982\u679c\u5065\u5eb7\u68c0\u67e5\u5931\u8d25\uff09\uff0c\u91cd\u542fpod\uff01\u81f3\u4e8e\u600e\u4e48\u68c0\u6d4b\uff0c\u4f60\u8bf4\u4e86\u7b97\uff08\u81ea\u5b9a\u4e49\u5224\u65ad\u5bb9\u5668\u662f\u5426\u5065\u5eb7\u7684\u6761\u4ef6\uff09\uff01<\/pre>\n\n\n\n<p>Liveness\u63d0\u4f9b\u4e86\u4e00\u4e9b\u91cd\u8981\u7684\u53c2\u6570\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">initialDelaySeconds\uff1a\u5bb9\u5668\u542f\u52a8\u540e\u7b2c\u4e00\u6b21\u6267\u884c\u63a2\u6d4b\u662f\u9700\u8981\u7b49\u5f85\u591a\u5c11\u79d2,\u770b\u8fd0\u884c\u7684\u670d\u52a1\u800c\u5b9a\u3002\nperiodSeconds\uff1a\u6267\u884c\u63a2\u6d4b\u7684\u9891\u7387\uff0c\u9ed8\u8ba4\u662f10\u79d2\uff0c\u6700\u5c0f1\u79d2\u3002\ntimeoutSeconds\uff1a\u63a2\u6d4b\u8d85\u65f6\u65f6\u95f4\uff0c\u9ed8\u8ba41\u79d2\uff0c\u6700\u5c0f1\u79d2\u3002\nsuccessThreshold\uff1a\u63a2\u6d4b\u5931\u8d25\u540e\uff0c\u6700\u5c11\u8fde\u7eed\u63a2\u6d4b\u6210\u529f\u591a\u5c11\u6b21\u624d\u88ab\u8ba4\u5b9a\u4e3a\u6210\u529f\uff0c\u9ed8\u8ba4\u662f1\uff0c\u5bf9\u4e8eliveness\u5fc5\u987b\u662f1\uff0c\u6700\u5c0f\u503c\u662f1\u3002\nfailureThreshold\uff1a\u63a2\u6d4b\u6210\u529f\u540e\uff0c\u6700\u5c11\u8fde\u7eed\u63a2\u6d4b\u5931\u8d25\u591a\u5c11\u6b21\u624d\u88ab\u8ba4\u5b9a\u4e3a\u5931\u8d25\u3002\u9ed8\u8ba4\u662f3\u3002\u6700\u5c0f\u503c\u662f1.<\/pre>\n\n\n\n<p>\u4e0b\u9762\u5b9e\u8df5\u4e00\u4e2a\u5c0f\u4f8b\u5b50\u521b\u5efa\u4e00\u4e2aPod\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#command\u81ea\u5df1\u5b9a\u4e49\uff0c\u4f8b\u5b50\u4e3a \/tmp\/healthy \u4e0d\u5b58\u5728\u5219\u8ba4\u4e3apod\u6709\u95ee\u9898\uff0c\u5927\u5bb6\u6839\u636e\u5b9e\u9645\u4e1a\u52a1\u6765\u81ea\u5b9a\u4e49\u3002\napiVersion: v1\nkind: Pod\nmetadata:\n  labels:\n    test: liveness\n  name: liveness-demo\nspec:\n  containers:\n  - name: liveness\n    image: busybox\n    args:\n    - \/bin\/sh\n    - -c\n    - touch \/tmp\/healthy; sleep 30; rm -rf\/tmp\/healthy; sleep 10\n    livenessProbe:\n      exec:\n        command:\n        - cat\n        - \/tmp\/healthy\n      initialDelaySeconds: 10\n      periodSeconds: 5<\/pre>\n\n\n\n<p>\u8fd9\u91cc\u542f\u52a8pod\u540e\u4f1a\u521b\u5efa\u6587\u4ef6\u5939 \/tmp\/healthy\uff0c30\u79d2\u540e\u5220\u9664\uff0c\u5728\u6211\u4eec\u7684\u8bbe\u7f6e\u4e2d\uff0c\u5982\u679c \/tmp\/healthy \u5b58\u5728\uff0c\u5219\u8ba4\u4e3a\u5bb9\u5668\u5904\u4e8e\u6b63\u5e38\u72b6\u6001\uff0c\u5426\u5219\u8ba4\u4e3a\u53d1\u751f\u6545\u969c\u3002<\/p>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u5c31\u662flivenessProbe\u90e8\u5206\u7684\u5b9a\u4e49\u4e86\uff1a<\/p>\n\n\n\n<p>\uff081\uff09\u63a2\u6d4b\u65b9\u6cd5\uff1a\u901a\u8fc7cat\u547d\u4ee4\u67e5\u770b\/tmp\/healthy\u662f\u5426\u5b58\u5728\uff1b\u5982\u679c\u8fd4\u56de\u503c\u4e3a0\uff0c\u5219\u63a2\u6d4b\u6210\u529f\uff1b\u5426\u5219\uff0c\u63a2\u6d4b\u5931\u8d25\uff1b<\/p>\n\n\n\n<p>\uff082\uff09initialDelaySeconds: 10 =&gt; \u5bb9\u5668\u542f\u52a810\u79d2\u4e4b\u540e\u5f00\u59cb\u6267\u884cliveness\u63a2\u6d4b\uff1b<\/p>\n\n\n\n<p>\uff083\uff09periodSeconds: 5 =&gt; \u6bcf5\u79d2\u6267\u884c\u4e00\u6b21liveness\u63a2\u6d4b\uff1b\u5982\u679c\u8fde\u7eed\u6267\u884c3\u6b21\u63a2\u6d4b\u90fd\u5931\u8d25\uff0c\u90a3\u4e48\u5c31\u4f1a\u6740\u6389\u5e76\u91cd\u542f\u5bb9\u5668\uff1b<\/p>\n\n\n\n<p>\u4e0b\u9762\u5feb\u901f\u5730\u9a8c\u8bc1\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<p>\uff081\uff09kubectl\u521b\u5efademo<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl apply -f liveness-demo.yaml<\/pre>\n\n\n\n<p>\uff082\uff09\u67e5\u770bpod\u65e5\u5fd7<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">kubectl describe pod liveness-demo<\/pre>\n\n\n\n<p>\u7ed3\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"226\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-1024x226.png\" alt=\"\" class=\"wp-image-11980\" style=\"width:547px;height:120px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-1024x226.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-300x66.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-768x170.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-830x183.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-230x51.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-350x77.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206-480x106.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-206.png 1204w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>30\u79d2\u4e4b\u540e\uff0c\/tmp\/healthy \u88ab\u5220\u9664\u4e86\uff0cliveness\u63a2\u6d4b\u5931\u8d25\uff0c\u53c8\u8fc7\u4e86\u51e0\u5341\u79d2\uff0c\u91cd\u590d\u63a2\u6d4b\u5747\u5931\u8d25\u540e\uff0c\u5f00\u542f\u4e86\u91cd\u542f\u5bb9\u5668\u3002<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"130\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-1024x130.png\" alt=\"\" class=\"wp-image-11981\" style=\"width:563px;height:71px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-1024x130.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-300x38.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-768x98.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-830x105.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-230x29.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-350x44.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207-480x61.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-207.png 1212w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p><strong>2.2 Liveness\u63a2\u9488<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u4e0a\u9762\u7684\u4f8b\u5b50\u4f7f\u7528\u7684\u662fLiveness\u7684exec\u63a2\u9488\uff0c\u6b64\u5916K8S\u8fd8\u6709\u51e0\u79cd\u5176\u4ed6\u7c7b\u578b\u7684\u63a2\u9488\uff1a<\/p>\n\n\n\n<ul>\n<li>exec\uff1a\u5728\u5bb9\u5668\u4e2d\u6267\u884c\u4e00\u4e2a\u547d\u4ee4\uff0c\u5982\u679c\u547d\u4ee4\u9000\u51fa\u7801\u8fd4\u56de0\u5219\u8868\u793a\u63a2\u6d4b\u6210\u529f\uff0c\u5426\u5219\u8868\u793a\u5931\u8d25<\/li>\n\n\n\n<li>tcpSocket\uff1a\u5bf9\u6307\u5b9a\u7684\u5bb9IP\u53ca\u7aef\u53e3\u6267\u884c\u4e00\u4e2aTCP\u68c0\u67e5\uff0c\u5982\u679c\u7aef\u53e3\u662f\u5f00\u653e\u7684\u5219\u8868\u793a\u63a2\u6d4b\u6210\u529f\uff0c\u5426\u5219\u8868\u793a\u5931\u8d25<\/li>\n\n\n\n<li>httpGet\uff1a\u5bf9\u6307\u5b9a\u7684\u5bb9\u5668IP\u3001\u7aef\u53e3\u53ca\u8def\u5f84\u6267\u884c\u4e00\u4e2aHTTP Get\u8bf7\u6c42\uff0c\u5982\u679c\u8fd4\u56de\u7684\u72b6\u6001\u7801\u5728 [200,400)\u4e4b\u95f4\u5219\u8868\u793a\u63a2\u6d4b\u6210\u529f\uff0c\u5426\u5219\u8868\u793a\u5931\u8d25<\/li>\n<\/ul>\n\n\n\n<p>\u9488\u5bf9tcpSocket\u7684\u4f8b\u5b50\uff1a\u8fd9\u91cc\u4f1a\u68c0\u6d4b80\u7aef\u53e3\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\uff1b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u68c0\u6d4b80\u7aef\u53e3\u662f\u5426\u8054\u901a\napiVersion: v1\nkind: Pod\nmetadata:\n  labels:\n    test: readiness\n  name: readiness-tcp\nspec:\n  containers: \n  - name: readiness\n    image: nginx\n    readinessProbe:\n      failureThreshold: 3\n      tcpSocket:\n        port: 80\n      initialDelaySeconds: 10\n      periodSeconds: 10\n      successThreshold: 1\n      timeoutSeconds: 10<\/pre>\n\n\n\n<p>\u9488\u5bf9httpGet\u7684\u4f8b\u5b50\uff1a\u8fd9\u91cc\u4f1a\u68c0\u6d4bindex.html\u6587\u4ef6\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u8bbf\u95ee\uff1b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">#\u8bbf\u95ee80\u7aef\u53e3\u7684index.html\u6587\u4ef6\u662f\u5426\u5b58\u5728\napiVersion: v1\nkind: Pod\nmetadata:\n  labels:\n    test: readiness\n  name: readiness-httpget\nspec:\n  containers:\n  - name: readiness\n    image: nginx\n    readinessProbe:\n      failureThreshold: 3\n      httpGet:\n        path: \/index.html\n        port: 80\n        scheme: HTTP\n      initialDelaySeconds: 10\n      periodSeconds: 10\n      successThreshold: 1\n      timeoutSeconds: 10<\/pre>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u4e09\u3001Readiness\u63a2\u6d4b<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<pre class=\"wp-block-preformatted\">\u4e00\u53e5\u8bddReadiness\uff1a\u5982\u679c\u68c0\u67e5\u5931\u8d25\uff0cK8S\u4f1a\u5c06\u8be5Pod\u4ece\u670d\u52a1\u4ee3\u7406\u7684\u5206\u53d1\u540e\u7aef\u53bb\u9664\uff0c\u4e0d\u518d\u8ba9\u5176\u63a5\u5ba2\uff08\u5206\u53d1\u8bf7\u6c42\u7ed9\u8be5Pod\uff09\u3002\u5982\u679c\u68c0\u6d4b\u6210\u529f\uff0c\u90a3\u4e48K8S\u5c31\u4f1a\u5c06\u5bb9\u5668\u52a0\u5165\u5230\u5206\u53d1\u540e\u7aef\uff0c\u91cd\u65b0\u5bf9\u5916\u63a5\u5ba2\uff08\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff09\u3002\u3000<\/pre>\n\n\n\n<p>\u4e0b\u9762\u7ee7\u7eed\u4ee5\u4e0a\u9762Liveness\u7684\u4f8b\u5b50\u6765\u5b9e\u8df5\u4e00\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: v1\nkind: Pod\nmetadata:\n  labels:\n    test: readiness\n  name: readiness-demo\nspec:\n  containers:\n  - name: readiness\n    image: busybox\n    args:\n    - \/bin\/sh\n    - -c\n    - touch \/tmp\/healthy; sleep 30; rm -rf\/tmp\/healthy; sleep 10\n    readinessProbe:\n      exec:\n        command:\n        - cat\n        - \/tmp\/healthy\n      initialDelaySeconds: 10\n      periodSeconds: 5<\/pre>\n\n\n\n<p>readinessProbe\u7684\u914d\u7f6e\u8bed\u6cd5\u4e0elivenessProbe\u5b8c\u5168\u4e00\u81f4\uff0c\u4f46\u6267\u884c\u540e\u7684\u6548\u679c\u5374\u4e0d\u4e00\u6837\uff0c\u89c1\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"322\" src=\"http:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-1024x322.png\" alt=\"\" class=\"wp-image-11982\" style=\"width:477px;height:150px\" srcset=\"https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-1024x322.png 1024w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-300x94.png 300w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-768x242.png 768w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-830x261.png 830w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-230x72.png 230w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-350x110.png 350w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208-480x151.png 480w, https:\/\/92it.top\/wp-content\/uploads\/2023\/08\/\u56fe\u7247-208.png 1208w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>\u53ef\u4ee5\u770b\u51fa\uff1a<\/p>\n\n\n\n<p>\uff081\uff09\u521a\u88ab\u521b\u5efa\u65f6\uff0c\u5176READY\u72b6\u6001\u4e3a\u4e0d\u53ef\u7528\uff1b<\/p>\n\n\n\n<p>\uff082\uff0915\u79d2\uff08initialDelaySeconds + periodSeconds = 10 + 5 = 15\uff09\u4e4b\u540e\uff0c\u7b2c\u4e00\u6b21\u8fdb\u884cReadiness\u63a2\u6d4b\u6210\u529f\uff0c\u5176READY\u72b6\u6001\u53d8\u4e3a\u53ef\u7528\u3002<\/p>\n\n\n\n<p>\uff083\uff0930\u79d2\u4e4b\u540e\uff0c\/tmp\/healthy\u88ab\u5220\u9664\uff0c\u8fde\u7eed3\u6b21Readiness\u63a2\u6d4b\u5747\u5931\u8d25\u540e\uff0c\u5176READY\u72b6\u6001\u53c8\u53d8\u4e3a\u4e86\u4e0d\u53ef\u7528\u3002<\/p>\n\n\n\n<p>\u6b64\u5916\uff0c\u6211\u4eec\u4e5f\u53ef\u4ee5\u901a\u8fc7&nbsp;kubectl describe pod readiness-demo \u67e5\u770b\u5230\u66f4\u60f3\u8d77\u7684\u65e5\u5fd7\u4fe1\u606f\u3002<\/p>\n\n\n\n<p><strong>3.2 \u4e0eLiveness\u7684\u5bf9\u6bd4<\/strong><\/p>\n\n\n\n<p>Liveness\u4e0eReadiness\u90fd\u662fK8S\u7684Health Check\u673a\u5236\uff0cLiveness\u63a2\u6d4b\u662f\u91cd\u542f\u5bb9\u5668\uff0c\u800cReadiness\u63a2\u6d4b\u5219\u662f\u5c06\u5bb9\u5668\u8bbe\u7f6e\u4e3a\u4e0d\u53ef\u7528\uff0c\u4e0d\u8ba9\u5176\u518d\u63a5\u53d7Service\u8f6c\u53d1\u7684\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p>Liveness\u4e0eReadiness\u662f\u72ec\u7acb\u6267\u884c\u7684\uff0c\u4e8c\u8005\u65e0\u4f9d\u8d56\uff0c\u53ef\u4ee5\u5355\u72ec\u4f7f\u7528\u4e5f\u53ef\u4ee5\u540c\u65f6\u4f7f\u7528\u3002<\/p>\n\n\n\n<p>\u3000<\/p>\n\n\n\n<p><strong>\u56db\u3001Health Check\u5728K8S\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p><strong>4.1 \u5728Scale Up\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n\n\n\n<p>\u5bf9\u4e8e\u591a\u526f\u672c\u5e94\u7528\uff0c\u5f53\u6267\u884cScale Up\u64cd\u4f5c\u65f6\uff0c\u65b0\u7684\u526f\u672c\u4f1a\u4f5c\u4e3a\u540e\u7aef\u670d\u52a1\u52a0\u5165\u5230Service\u7684\u8d1f\u8f7d\u5747\u8861\u5217\u8868\u4e2d\u3002\u4f46\u662f\uff0c\u5f88\u591a\u65f6\u5019\u5e94\u7528\u7684\u542f\u52a8\u90fd\u9700\u8981\u4e00\u5b9a\u7684\u65f6\u95f4\u505a\u51c6\u5907\uff08\u6bd4\u5982\u52a0\u8f7d\u7f13\u5b58\u3001\u8fde\u63a5\u6570\u636e\u5e93\u7b49\u7b49\uff09\uff0c\u8fd9\u65f6\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7Readiness\u63a2\u6d4b\u5224\u65ad\u5bb9\u5668\u662f\u5426\u771f\u6b63\u5c31\u7eea\uff0c\u4ece\u800c\u907f\u514d\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u8fd8\u672a\u771f\u6b63\u5c31\u7eea\u7684\u540e\u7aef\u670d\u52a1\u3002<\/p>\n\n\n\n<p>\u4e0b\u9762\u4e00\u4e2a\u793a\u4f8bYAML\u914d\u7f6e\u6587\u4ef6\u5b9a\u4e49\u4e86Readiness\u63a2\u6d4b\uff0c\u91cd\u70b9\u5173\u6ce8readinessProbe\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: edc-webapi-deployment\n  namespace: aspnetcore\nspec:\n  replicas: 2\n  selector:\n    matchLabels:\n      name: edc-webapi\n  template:\n    metadata:\n      labels:\n        name: edc-webapi\n    spec:\n      containers:\n      - name: edc-webapi-container\n        image: edisonsaonian\/k8s-demo:1.2\n        ports:\n        - containerPort: 80\n        imagePullPolicy: IfNotPresent\n        readinessProbe:\n          httpGet:\n            scheme: HTTP\n            path: \/api\/health\n            port: 80\n          initialDelaySeconds: 10\n          periodSeconds: 5\n\n---\n\napiVersion: v1\nkind: Service\nmetadata:\n  name: edc-webapi-service\n  namespace: aspnetcore\nspec:\n  type: NodePort\n  ports:\n    - nodePort: 31000 \n      port: 8080\n      targetPort: 80\n  selector:\n    name: edc-webapi<\/pre>\n\n\n\n<p>\u5bf9\u4e8ereadinessProbe\u90e8\u5206\uff1a<\/p>\n\n\n\n<p>\uff081\uff09schema\u6307\u5b9a\u4e86\u534f\u8bae\uff0c\u8fd9\u91cc\u662fHTTP\u534f\u8bae\uff0c\u4e5f\u53ef\u4ee5\u662fHTTPS\u534f\u8bae\uff1b<\/p>\n\n\n\n<p>\uff082\uff09path\u6307\u5b9a\u8bbf\u95ee\u8def\u5f84\uff0c\u8fd9\u91cc\u662f\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u4e00\u4e2aController\u4e2d\u7684\u63a5\u53e3\uff1a\u7b80\u5355\u5730\u8fd4\u56de\u4e00\u4e2a\u72b6\u6001\u7801\u4e3a200\u7684\u54cd\u5e94\uff1b<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">[Produces(\"application\/json\")]\n    [Route(\"api\/Health\")]\n    public class HealthController : Controller\n    {\n        [HttpGet]\n        public IActionResult Get() => Ok(\"ok\");\n    }<\/pre>\n\n\n\n<p>\uff083\uff09port\u6307\u5b9a\u7aef\u53e3\uff0c\u8fd9\u91cc\u662f\u5bb9\u5668\u7684\u7aef\u53e380\uff1b<\/p>\n\n\n\n<p>\uff084\uff09initialDelaySeconds\u548cperiodSeconds\u6307\u5b9a\u4e86\u5bb9\u5668\u542f\u52a810\u79d2\u4e4b\u540e\u5f00\u59cb\u63a2\u6d4b\uff0c\u7136\u540e\u6bcf\u96945\u79d2\u6267\u884c\u63a2\u6d4b\uff0c\u5982\u679c\u53d1\u751f3\u6b21\u4ee5\u4e0a\u63a2\u6d4b\u5931\u8d25\uff0c\u5219\u8be5\u5bb9\u5668\u4f1a\u4eceService\u7684\u8d1f\u8f7d\u5747\u8861\u4e2d\u79fb\u9664\uff0c\u76f4\u5230\u4e0b\u6b21\u63a2\u6d4b\u6210\u529f\u540e\u624d\u4f1a\u91cd\u65b0\u52a0\u5165\u3002<\/p>\n\n\n\n<p><strong>4.2 \u5728Rolling Update\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u73b0\u5728\u6709\u4e00\u4e2a\u6b63\u5e38\u8fd0\u884c\u7684\u591a\u526f\u672c\u5e94\u7528\uff0c\u6211\u4eec\u8981\u5bf9\u5176\u8fdb\u884c\u6eda\u52a8\u66f4\u65b0\u5373Rolling Update\uff0cK8S\u4f1a\u9010\u6b65\u7528\u65b0Pod\u66ff\u6362\u65e7Pod\uff0c\u7ed3\u679c\u5c31\u6709\u53ef\u80fd\u53d1\u751f\u8fd9\u6837\u7684\u4e00\u4e2a\u573a\u666f\uff1a\u5f53\u6240\u6709\u65e7\u526f\u672c\u88ab\u66ff\u6362\u4e4b\u540e\uff0c\u800c\u65b0\u7684Pod\u7531\u4e8e\u4eba\u4e3a\u914d\u7f6e\u9519\u8bef\u4e00\u76f4\u65e0\u6cd5\u542f\u52a8\uff0c\u56e0\u6b64\u6574\u4e2a\u5e94\u7528\u5c06\u65e0\u6cd5\u5904\u7406\u8bf7\u6c42\uff0c\u65e0\u6cd5\u5bf9\u5916\u63d0\u4f9b\u670d\u52a1\uff0c\u540e\u679c\u5f88\u4e25\u91cd\uff01<\/p>\n\n\n\n<p>\u56e0\u6b64\uff0cReadiness\u63a2\u6d4b\u8fd8\u63d0\u4f9b\u4e86\u7528\u4e8e\u907f\u514d\u6eda\u52a8\u66f4\u65b0\u4e2d\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u7684\u4e00\u4e9b\u89e3\u51b3\u529e\u6cd5\uff0c\u6bd4\u5982maxSurge\u548cmaxUnavailable\u4e24\u4e2a\u53c2\u6570\uff0c\u7528\u6765\u63a7\u5236\u526f\u672c\u66ff\u6362\u7684\u6570\u91cf\u3002<\/p>\n\n\n\n<p>\u7ee7\u7eed\u4ee5\u4e0a\u9762\u7684YAML\u914d\u7f6e\u6587\u4ef6\u4e3a\u4f8b\uff0c\u91cd\u70b9\u5173\u6ce8strategy\u90e8\u5206\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: edc-webapi-deployment\n  namespace: aspnetcore\nspec:\n  strategy:\n    rollingupdate:\n      maxSurge: 25%\n      maxUnavailable: 25%\n  replicas: 10\n  selector:\n    matchLabels:\n      name: edc-webapi\n  template:\n    metadata:\n      labels:\n        name: edc-webapi\n    spec:\n      containers:\n      - name: edc-webapi-container\n        image: edisonsaonian\/k8s-demo:1.2\n        ports:\n        - containerPort: 80\n        imagePullPolicy: IfNotPresent\n        readinessProbe:\n          httpGet:\n            scheme: HTTP\n            path: \/api\/health\n            port: 80\n          initialDelaySeconds: 10\n          periodSeconds: 5\n\n---\n\napiVersion: v1\nkind: Service\nmetadata:\n  name: edc-webapi-service\n  namespace: aspnetcore\nspec:\n  type: NodePort\n  ports:\n    - nodePort: 31000 \n      port: 8080\n      targetPort: 80\n  selector:\n    name: edc-webapi<\/pre>\n\n\n\n<p>\uff081\uff09maxSurge : 25% =&gt; \u63a7\u5236\u6eda\u52a8\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u526f\u672c\u603b\u6570\u8d85\u8fc7\u9884\u671f\uff08\u8fd9\u91cc\u9884\u671f\u662f10\u4e2a\u526f\u672c replicas: 10\uff09\u7684\u4e0a\u9650\uff0c\u53ef\u4ee5\u662f\u6570\u503c\u4e5f\u53ef\u4ee5\u662f\u767e\u5206\u6bd4\uff0c\u7136\u540e<strong>\u5411\u4e0a\u53d6\u6574<\/strong>\u3002\u8fd9\u91cc\u5199\u7684\u767e\u5206\u6bd4\uff0c\u9ed8\u8ba4\u503c\u662f25%\uff1b<\/p>\n\n\n\n<p>\u5982\u679c\u9884\u671f\u526f\u672c\u6570\u4e3a10\uff0c\u90a3\u4e48\u526f\u672c\u603b\u6570\u7684\u6700\u5927\u503c\u4e3aRoundUp(10 + 10 * 25%)=13\u4e2a\u3002<\/p>\n\n\n\n<p>\uff082\uff09maxUnavailable : 25% =&gt; \u63a7\u5236\u6eda\u52a8\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u4e0d\u53ef\u7528\u7684\u526f\u672c\uff08\u8fd9\u91cc\u9884\u671f\u662f10\u4e2a\u526f\u672c replicas: 10\uff09\u5360\u9884\u671f\u7684\u6700\u5927\u6bd4\u4f8b\uff0c\u53ef\u4ee5\u662f\u6570\u503c\u4e5f\u53ef\u4ee5\u662f\u767e\u5206\u6bd4\uff0c\u7136\u540e<strong>\u5411\u4e0b\u53d6\u6574<\/strong>\uff0c\u540c\u6837\u5730\u9ed8\u8ba4\u503c\u4e5f\u662f25%\uff1b<\/p>\n\n\n\n<p>\u5982\u679c\u9884\u671f\u526f\u672c\u603b\u6570\u4e3a10\uff0c\u90a3\u4e48\u53ef\u7528\u7684\u526f\u672c\u6570\u81f3\u5c11\u8981\u4e3a10-roundDown(10 * 25%)=10-2=8\u4e2a\u3002<\/p>\n\n\n\n<p>\u7efc\u4e0a\u770b\u6765\uff0cmaxSurge\u7684\u503c\u8d8a\u5927\uff0c\u521d\u59cb\u521b\u5efa\u7684\u65b0\u526f\u672c\u6570\u91cf\u5c31\u8d8a\u591a\uff1bmaxUnavaliable\u503c\u8d8a\u5927\uff0c\u521d\u59cb\u9500\u6bc1\u7684\u65e7\u526f\u672c\u6570\u91cf\u5c31\u8d8a\u591a\uff1b<\/p>\n\n\n\n<p><span style=\"color: rgba(0, 0, 0, 0.85); font-family: Inter, -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;SF Pro SC&quot;, &quot;SF Pro Display&quot;, &quot;SF Pro Icons&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;\">\u5728 Kubernetes \u7684<\/span><code style=\"-webkit-font-smoothing: antialiased; box-sizing: border-box; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); background: none 0% 0% \/ auto repeat scroll padding-box border-box rgba(0, 0, 0, 0.06); border-radius: 4px; color: rgba(0, 0, 0, 0.85); font-size: 16px; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; overflow-anchor: auto; font-weight: 400; line-height: 28px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;\">rollingUpdate<\/code><span style=\"color: rgba(0, 0, 0, 0.85); font-family: Inter, -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;SF Pro SC&quot;, &quot;SF Pro Display&quot;, &quot;SF Pro Icons&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;\">\u66f4\u65b0\u7b56\u7565\u4e2d\uff0c\u662f<\/span>\u5148\u521b\u5efa\u65b0 Pod\uff0c\u518d\u5220\u9664\u65e7 Pod<span style=\"color: rgba(0, 0, 0, 0.85); font-family: Inter, -apple-system, &quot;system-ui&quot;, &quot;Segoe UI&quot;, &quot;SF Pro SC&quot;, &quot;SF Pro Display&quot;, &quot;SF Pro Icons&quot;, &quot;PingFang SC&quot;, &quot;Hiragino Sans GB&quot;, &quot;Microsoft YaHei&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;\"><span>\u00a0<\/span><\/span><\/p>\n\n\n\n<p>Kubernetes \u4f1a\u6839\u636e<code>rollingUpdate<\/code>\u914d\u7f6e\u4e2d\u7684<code>maxSurge<\/code>\u548c<code>maxUnavailable<\/code>\u53c2\u6570\u6765\u534f\u8c03\u65b0 Pod \u521b\u5efa\u548c\u65e7 Pod \u5220\u9664\u7684\u8fc7\u7a0b\uff1a<\/p>\n\n\n\n<ul>\n<li><strong><code>maxSurge<\/code><\/strong>\uff1a\u5728\u6eda\u52a8\u66f4\u65b0\u671f\u95f4\uff0c\u5141\u8bb8\u8d85\u8fc7<code>replicas<\/code>\u6570\u91cf\u7684\u6700\u5927 Pod \u6570\u91cf\uff0c\u5b83\u51b3\u5b9a\u4e86\u5148\u989d\u5916\u521b\u5efa\u591a\u5c11\u65b0 Pod\u3002<\/li>\n\n\n\n<li><strong><code>maxUnavailable<\/code><\/strong>\uff1a\u6eda\u52a8\u66f4\u65b0\u671f\u95f4\uff0c\u4e0d\u53ef\u7528 Pod \u7684\u6700\u5927\u6570\u91cf\uff0c\u5b83\u51b3\u5b9a\u4e86\u5728\u65b0 Pod \u51c6\u5907\u597d\u540e\uff0c\u53ef\u4ee5\u5220\u9664\u591a\u5c11\u65e7 Pod\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\u5206\u6790<\/strong><\/p>\n\n\n\n<p>\u5047\u8bbe\u4e00\u4e2a Deployment \u7684\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">apiVersion: apps\/v1\nkind: Deployment\nmetadata:\n  name: my-app\nspec:\n  replicas: 3\n  strategy:\n    type: RollingUpdate\n    rollingUpdate:\n      maxUnavailable: 1\n      maxSurge: 1\n  selector:\n    matchLabels:\n      app: my-app\n  template:\n    metadata:\n      labels:\n        app: my-app<\/pre>\n\n\n\n<ol>\n<li>\u5f00\u59cb\u66f4\u65b0\uff1a<br>\u5f53\u9700\u8981\u66f4\u65b0\u8be5 Deployment \u4e2d\u7684\u5e94\u7528\uff08\u6bd4\u5982\u66f4\u65b0\u955c\u50cf\u7248\u672c\uff09\u65f6\uff0cKubernetes \u9996\u5148\u4f1a\u6839\u636e<code>maxSurge<\/code>\u7684\u503c\uff0c\u989d\u5916\u521b\u5efa\u65b0\u7684 Pod\u3002\u8fd9\u91cc<code>maxSurge<\/code>\u4e3a 1\uff0c\u90a3\u4e48\u4f1a\u5148\u521b\u5efa 1 \u4e2a\u8fd0\u884c\u65b0\u7248\u672c\u5e94\u7528\u7684 Pod\u3002<\/li>\n\n\n\n<li>\u65b0 Pod \u5c31\u7eea\uff1a<br>\u65b0\u521b\u5efa\u7684 Pod \u542f\u52a8\u540e\uff0c\u4f1a\u7ecf\u8fc7\u5c31\u7eea\u63a2\u9488\uff08\u5982\u679c\u914d\u7f6e\u4e86\u7684\u8bdd\uff09\u68c0\u67e5\uff0c\u5f53\u65b0 Pod \u901a\u8fc7\u68c0\u67e5\uff0c\u5904\u4e8e\u5c31\u7eea\u72b6\u6001\u540e\uff0cKubernetes \u4f1a\u6839\u636e<code>maxUnavailable<\/code>\u7684\u503c\uff0c\u5220\u9664\u65e7\u7248\u672c\u7684 Pod\u3002\u8fd9\u91cc<code>maxUnavailable<\/code>\u4e3a 1\uff0c\u6240\u4ee5\u4f1a\u5220\u9664 1 \u4e2a\u65e7\u7248\u672c\u7684 Pod\u3002<\/li>\n\n\n\n<li>\u6301\u7eed\u66f4\u65b0\uff1a<br>\u91cd\u590d\u4e0a\u8ff0\u8fc7\u7a0b\uff0c\u5373\u518d\u6b21\u521b\u5efa\u65b0 Pod\uff0c\u7b49\u65b0 Pod \u5c31\u7eea\u540e\uff0c\u518d\u5220\u9664\u4e00\u4e2a\u65e7 Pod\uff0c\u76f4\u5230\u6240\u6709\u65e7\u7248\u672c\u7684 Pod \u90fd\u88ab\u66ff\u6362\u4e3a\u65b0\u7248\u672c\u7684 Pod \uff0c\u6700\u7ec8\u4fdd\u6301<code>replicas<\/code>\u6570\u91cf\u7684\u65b0\u7248\u672c Pod \u5728\u8fd0\u884c\u3002<\/li>\n<\/ol>\n\n\n\n<p><strong>\u8fd9\u6837\u8bbe\u8ba1\u7684\u4f18\u52bf<\/strong><\/p>\n\n\n\n<ul>\n<li>\u4fdd\u969c\u670d\u52a1\u53ef\u7528\u6027\uff1a\u5148\u521b\u5efa\u65b0 Pod\uff0c\u518d\u5220\u9664\u65e7 Pod \u7684\u65b9\u5f0f\uff0c\u53ef\u4ee5\u6700\u5927\u7a0b\u5ea6\u5730\u4fdd\u8bc1\u670d\u52a1\u7684\u8fde\u7eed\u6027\u3002\u56e0\u4e3a\u5728\u6574\u4e2a\u66f4\u65b0\u8fc7\u7a0b\u4e2d\uff0c\u59cb\u7ec8\u6709\u8db3\u591f\u6570\u91cf\u7684 Pod \u5728\u8fd0\u884c\uff0c\u51cf\u5c11\u4e86\u56e0 Pod \u6570\u91cf\u4e0d\u8db3\u5bfc\u81f4\u670d\u52a1\u4e2d\u65ad\u7684\u98ce\u9669\u3002<\/li>\n\n\n\n<li>\u964d\u4f4e\u66f4\u65b0\u98ce\u9669\uff1a\u5148\u8ba9\u65b0 Pod \u5c31\u7eea\uff0c\u518d\u5220\u9664\u65e7 Pod\uff0c\u80fd\u53ca\u65f6\u53d1\u73b0\u65b0 Pod \u662f\u5426\u5b58\u5728\u95ee\u9898\uff08\u5982\u542f\u52a8\u5931\u8d25\u3001\u65e0\u6cd5\u63d0\u4f9b\u670d\u52a1\u7b49\uff09\u3002\u5982\u679c\u65b0 Pod \u6709\u95ee\u9898\uff0c\u8fd8\u53ef\u4ee5\u505c\u6b62\u66f4\u65b0\u8fc7\u7a0b\uff0c\u4fdd\u7559\u5927\u90e8\u5206\u65e7 Pod \u7ee7\u7eed\u63d0\u4f9b\u670d\u52a1\uff0c\u964d\u4f4e\u66f4\u65b0\u5931\u8d25\u5bf9\u4e1a\u52a1\u7684\u5f71\u54cd\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u3000\u3000<\/p>\n\n\n\n<p><strong>\u4e94\u3001\u5c0f\u7ed3<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>\u672c\u6587\u63a2\u7d22\u4e86K8S\u4e2d\u7684\u9ed8\u8ba4\u5065\u5eb7\u68c0\u67e5\u673a\u5236\u4ee5\u53caLiveness\u548cReadiness\u4e24\u79cd\u5404\u6709\u7279\u70b9\u7684\u63a2\u6d4b\u673a\u5236\uff0c\u5e76\u901a\u8fc7\u4e00\u4e9b\u5c0f\u4f8b\u5b50\u8fdb\u884c\u4e86\u8bf4\u660e\u3002\u4e0d\u8fc7\u7531\u4e8e\u7b14\u8005\u4e5f\u662f\u521d\u5b66\uff0c\u5bf9\u4e8e\u8fd9\u4e00\u5757\u6ca1\u6709\u8fc7\u591a\u5b9e\u8df5\u7ecf\u9a8c\uff0c\u56e0\u6b64\u4e5f\u662f\u8bb2\u7684\u6bd4\u8f83\u7c97\u6d45\uff0c\u4e5f\u5e0c\u671b\u4ee5\u540e\u80fd\u591f\u6709\u66f4\u591a\u7684\u5b9e\u9645\u7ecf\u9a8c\u5206\u4eab\u4e0e\u5404\u4f4d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f6c\u8f7d\uff1ahttps:\/\/www.cnblogs.com\/edisonchou\/p\/aspnet_core_on_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"_links":{"self":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11977"}],"collection":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=11977"}],"version-history":[{"count":6,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11977\/revisions"}],"predecessor-version":[{"id":18480,"href":"https:\/\/92it.top\/index.php?rest_route=\/wp\/v2\/posts\/11977\/revisions\/18480"}],"wp:attachment":[{"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=11977"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=11977"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/92it.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=11977"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}