{"id":167,"date":"2023-05-24T13:38:35","date_gmt":"2023-05-24T05:38:35","guid":{"rendered":"https:\/\/www.dataz8.com\/?p=167"},"modified":"2023-06-05T10:19:37","modified_gmt":"2023-06-05T02:19:37","slug":"kubernetes%e6%8e%a2%e9%92%88%ef%bc%9alivenessprobe%e3%80%81readinesspro%e3%80%81startupprobe","status":"publish","type":"post","link":"https:\/\/www.dataz8.com\/?p=167","title":{"rendered":"Kubernetes\u63a2\u9488\uff1alivenessProbe\u3001readinessProbe\u3001startupProbe"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.dataz8.com\/?p=167\/#1_%E6%8E%A2%E9%92%88%E4%BB%8B%E7%BB%8D\" >1. \u63a2\u9488\u4ecb\u7ecd<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.dataz8.com\/?p=167\/#11_livenessProbe\" >1.1 livenessProbe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.dataz8.com\/?p=167\/#12_readinessProbe\" >1.2 readinessProbe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.dataz8.com\/?p=167\/#13_startupProbe\" >1.3 startupProbe<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.dataz8.com\/?p=167\/#2_%E6%9F%A5%E7%9C%8B%E6%8E%A2%E9%92%88\" >2. \u67e5\u770b\u63a2\u9488<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.dataz8.com\/?p=167\/#3_%E6%8E%A2%E9%92%88%E7%A4%BA%E4%BE%8B\" >3. \u63a2\u9488\u793a\u4f8b<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.dataz8.com\/?p=167\/#31_%E9%80%9A%E8%BF%87exec%E6%96%B9%E5%BC%8F%E5%81%9A%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\" >3.1 \u901a\u8fc7exec\u65b9\u5f0f\u505a\u5065\u5eb7\u63a2\u6d4b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.dataz8.com\/?p=167\/#32_%E9%80%9A%E8%BF%87HTTP%E6%96%B9%E5%BC%8F%E5%81%9A%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\" >3.2 \u901a\u8fc7HTTP\u65b9\u5f0f\u505a\u5065\u5eb7\u63a2\u6d4b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.dataz8.com\/?p=167\/#33_%E9%80%9A%E8%BF%87TCP%E6%96%B9%E5%BC%8F%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\" >3.3 \u901a\u8fc7TCP\u65b9\u5f0f\u5065\u5eb7\u63a2\u6d4b<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_%E6%8E%A2%E9%92%88%E4%BB%8B%E7%BB%8D\"><\/span>1. \u63a2\u9488\u4ecb\u7ecd<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c08\u63a2\u9488\u4e4b\u524d\uff0c\u5148\u6765\u8bf4\u8bf4Pod\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728k8s\u4e2d\uff0cPod\u662f\u6700\u5c0f\u7684\u8ba1\u7b97\u5355\u5143\uff0c\u4e00\u4e2aPod\u4ee3\u8868\u96c6\u7fa4\u4e2d\u8fd0\u884c\u7684\u4e00\u4e2a\u8fdb\u7a0b\u3002Pod\u5185\u90e8\u53ef\u4ee5\u5c01\u88c5\u4e00\u4e2a\u5bb9\u5668\uff0c\u4e5f\u53ef\u4ee5\u5c01\u88c5\u591a\u4e2a\u5bb9\u5668\uff0c\u5728\u8282\u70b9\u4e0a\uff0cPod\u548cPod\u4e4b\u95f4\u662f\u76f8\u4e92\u72ec\u7acb\u7684\u3002\u5f53\u521b\u5efa\u4e00\u4e2aPod\u7684\u8d44\u6e90\u5bf9\u8c61\u7684\u65f6\u5019\uff0c\u5148\u521b\u5efa\u4e00\u4e2apause\u5bb9\u5668\uff0c\u6b64\u5bb9\u5668\u4f1a\u5e2e\u52a9Pod\u521b\u5efa\u5171\u4eab\u7f51\u5361\u3001\u5171\u4eab\u5b58\u50a8\u5377\uff0c\u7f51\u5361\u548c\u6570\u636e\u5377\u90fd\u662fPod\u5185\u90e8\u5bb9\u5668\u5171\u4eab\u7684\u8d44\u6e90\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">k8s\u4e3a\u4ec0\u4e48\u8fd9\u6837\u8bbe\u8ba1Pod\u548c\u7279\u6b8a\u7ec4\u6210\u7ed3\u6784\u5450\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u56e0\u4e00\uff1a\u5728\u4e00\u7ec4\u5bb9\u5668\u4f5c\u4e3a\u4e00\u4e2a\u5355\u5143\u7684\u60c5\u51b5\u4e0b\uff0c\u96be\u4ee5\u5bf9\u6574\u4e2a\u7684\u5bb9\u5668\u7b80\u5355\u5730\u8fdb\u884c\u5224\u65ad\u4ee5\u53ca\u6709\u6548\u7684\u8fdb\u884c\u884c\u52a8\u3002\u6bd4\u5982\uff0c\u4e00\u4e2a\u5bb9\u5668\u6b7b\u4e86\uff0c\u6b64\u65f6\u662f\u7b97\u6574\u4f53\u6302\u4e86\u4e48\uff1f\u90a3\u4e48\u5f15\u5165\u4e0e\u4e1a\u52a1\u65e0\u5173\u7684pause\u5bb9\u5668\u4f5c\u4e3aPod\u7684\u6839\u5bb9\u5668\uff0c\u4ee5\u5b83\u7684\u72b6\u6001\u4ee3\u8868\u7740\u6574\u4e2a\u5bb9\u5668\u7ec4\u7684\u72b6\u6001\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u89e3\u51b3\u8be5\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u539f\u56e0\u4e8c\uff1aPod\u91cc\u7684\u591a\u4e2a\u4e1a\u52a1\u5bb9\u5668\u5171\u4eabpause\u5bb9\u5668\u7684IP\uff0c\u5171\u4eabpause\u5bb9\u5668\u6302\u8f7d\u7684volume\uff0c\u8fd9\u6837\u7b80\u5316\u4e86\u4e1a\u52a1\u5bb9\u5668\u4e4b\u95f4\u7684\u901a\u4fe1\u95ee\u9898\uff0c\u4e5f\u89e3\u51b3\u4e86\u5bb9\u5668\u4e4b\u95f4\u7684\u6587\u4ef6\u5171\u4eab\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u518d\u6765\uff0c\u6211\u4eec\u770b\u770bPod\u7684\u5e38\u89c1\u72b6\u6001\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Pending<\/strong>\uff1a\u6302\u8d77\uff0c\u5728\u521b\u5efaPod\u65f6\uff0c\u6761\u4ef6\u4e0d\u6ee1\u8db3\uff0c\u8c03\u5ea6\u6ca1\u6709\u5b8c\u6210\uff0c\u6ca1\u6709\u4efb\u4f55\u4e00\u4e2a\u8282\u70b9\u80fd\u6ee1\u8db3\u8c03\u5ea6\u6761\u4ef6\u3002\u5df2\u7ecf\u521b\u5efa\u4e86\u4f46\u662f\u6ca1\u6709\u9002\u5408\u5b83\u8fd0\u884c\u7684\u8282\u70b9\u53eb\u505a\u6302\u8d77\uff0c\u8fd9\u5176\u4e2d\u5305\u542b\u96c6\u7fa4\u4e3a\u5bb9\u5668\u521b\u5efa\u7f51\u7edc\uff0c\u6216\u8005\u4e0b\u8f7d\u955c\u50cf\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Running<\/strong>\uff1aPod\u5185\u6240\u6709\u7684\u5bb9\u5668\u90fd\u5df2\u7ecf\u88ab\u521b\u5efa\uff0c\u4e14\u81f3\u5c11\u4e00\u4e2a\u5bb9\u5668\u6b63\u5728\u5904\u4e8e\u8fd0\u884c\u72b6\u6001\u3001\u6b63\u5728\u542f\u52a8\u72b6\u6001\u6216\u8005\u91cd\u542f\u72b6\u6001\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Succeeded<\/strong>\uff1aPod\u4e2d\u5bb9\u5668\u90fd\u6267\u884c\u6210\u529f\u540e\u9000\u51fa\uff0c\u800c\u4e14\u4e0d\u5904\u4e8e\u91cd\u542f\u7684\u5bb9\u5668\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Failed<\/strong>\uff1aPod\u4e2d\u5bb9\u5668\u90fd\u5df2\u9000\u51fa\uff0c\u7136\u800c\u81f3\u5c11\u53e6\u6709\u4e00\u4e2a\u5bb9\u5668\u9000\u51fa\u65f6\u4e3a\u6389\u8d25\u60c5\u51b5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Unknown<\/strong>\uff1a\u672a\u77e5\u72b6\u6001\uff0c\u5c31\u662f\u67d0\u79cd\u539f\u56e0\u65e0\u6cd5\u83b7\u53d6Pod\u72b6\u6001\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/www.dataz8.com\/wp-content\/uploads\/2023\/05\/Pod\u5e38\u89c1\u72b6\u6001.png\" alt=\"\" width=\"575\" height=\"225\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e4b\u524d\u8bf4\u4e86Pod\uff0c\u90a3\u4e48\u5728\u8fd0\u884c\u671f\u95f4\uff0c\u53ef\u80fd\u56e0\u4e3a\u67d0\u79cd\u610f\u5916\u60c5\u51b5\u81f4\u4f7f\u7a0b\u5e8f\u6302\u6389\uff0c\u90a3\u4e48\u5982\u4f55\u6765\u76d1\u63a7\u5bb9\u5668\u72b6\u6001\u7684\u7a33\u5b9a\u6027\uff0c\u4fdd\u8bc1\u670d\u52a1\u5728\u8fd0\u884c\u671f\u95f4\u4e0d\u4f1a\u53d1\u751f\u95ee\u9898\uff0c\u5373\u4f7f\u53d1\u751f\u4e86\u95ee\u9898\u4e5f\u53ef\u4ee5\u8fdb\u884c\u91cd\u542f\u7b49\u673a\u5236\uff0c\u5c31\u6210\u4e86\u975e\u5e38\u91cd\u8981\u7684\u4e8b\u60c5\uff0c\u90a3\u4e48\uff0ck8s\u5c31\u6709\u63a2\u9488\u673a\u5236\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"11_livenessProbe\"><\/span>1.1 livenessProbe<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b58\u6d3b\u6027\u63a2\u9488\uff0c\u7528\u4e8e\u5224\u65ad\u5bb9\u5668\u662f\u5426\u5b58\u6d3b\uff08running\u72b6\u6001\uff09\uff0c\u5982\u679clivenessProbe\u63a2\u9488\u63a2\u6d4b\u5230\u5bb9\u5668\u4e0d\u5065\u5eb7\uff0c\u5219kubelet\u6740\u6389\u8be5\u5bb9\u5668\uff0c\u5e76\u6839\u636e\u5bb9\u5668\u7684\u91cd\u542f\u7b56\u7565\u505a\u76f8\u5e94\u7684\u5904\u7406\u3002\u5982\u679c\u4e00\u4e2a\u5bb9\u5668\u4e0d\u5305\u542blivenessProbe\u63a2\u9488\uff0c\u5219kubelet\u8ba4\u4e3a\u8be5\u5bb9\u5668\u7684livenessProbe\u63a2\u9488\u8fd4\u56de\u7684\u503c\u6c38\u8fdc\u662f\u201cSuccess\u201d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"12_readinessProbe\"><\/span>1.2 readinessProbe<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c31\u7eea\u6027\u63a2\u9488\uff0c\u7528\u4e8e\u5224\u65ad\u5bb9\u5668\u662f\u5426\u542f\u52a8\u5b8c\u6210\uff08ready\u72b6\u6001\uff09\uff0c\u53ef\u4ee5\u63a5\u6536\u8bf7\u6c42\u3002\u5982\u679creadinessProbe\u63a2\u9488\u68c0\u6d4b\u5230\u5931\u8d25\uff0c\u5219Pod\u7684\u72b6\u6001\u88ab\u4fee\u6539\u3002Endpoint Controller\u5c06\u4eceService\u7684Endpoint\u4e2d\u5220\u9664\u5305\u542b\u8be5\u5bb9\u5668\u6240\u5728Pod\u7684Endpoint\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"13_startupProbe\"><\/span>1.3 startupProbe<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u542f\u52a8\u63a2\u9488\uff0ck8s 1.16\u7248\u672c\u540e\u65b0\u52a0\u7684\u63a2\u9488\u65b9\u5f0f\uff0c\u4e3b\u8981\u89e3\u51b3\u5728\u6162\u542f\u52a8\u7a0b\u5e8f\u6216\u8005\u590d\u6742\u7a0b\u5e8f\u4e2dlivenessProbe\u3001readinessProbe\u63a2\u9488\u65e0\u6cd5\u8f83\u597d\u7684\u5224\u65ad\u7a0b\u5e8f\u662f\u5426\u542f\u52a8\u3001\u662f\u5426\u5b58\u6d3b\uff0c\u8fdb\u800c\u5f15\u5165startupProbe\u63a2\u9488\uff0c\u4e3alivenessProbe\u3001readinessProbe\u63a2\u9488\u670d\u52a1\u3002\u5982\u679c\u4e09\u4e2a\u63a2\u9488\u540c\u65f6\u5b58\u5728\uff0c\u5219\u5148\u6267\u884cstartupProbe\u63a2\u9488\uff0c\u5176\u4ed6\u4e24\u4e2a\u63a2\u9488\u5c06\u4f1a\u88ab\u6682\u65f6\u7981\u7528\uff0c\u76f4\u5230startupProbe\u4e00\u6b21\u63a2\u6d4b\u6210\u529f\uff0c\u5176\u4ed62\u4e2a\u63a2\u9488\u624d\u542f\u52a8\uff0c\u5982\u679cstartupProbe\u63a2\u9488\u5931\u8d25\uff0ckubelet\u5c06\u6740\u6b7b\u5bb9\u5668\uff0c\u5e76\u6839\u636erestartPolicy\u91cd\u542f\u7b56\u7565\u6765\u5224\u65ad\u5bb9\u5668\u662f\u5426\u8981\u8fdb\u884c\u91cd\u542f\u64cd\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_%E6%9F%A5%E7%9C%8B%E6%8E%A2%E9%92%88\"><\/span>2. \u67e5\u770b\u63a2\u9488<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u67e5\u770blivenessProbe<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><code>&#91;root@k8s-master ~]# kubectl explain pods.spec.containers.livenessProbe\nKIND:     Pod\nVERSION:  v1\n\nRESOURCE: livenessProbe &lt;Object&gt;\n\nDESCRIPTION:\n     Periodic probe of container liveness. Container will be restarted if the\n     probe fails. Cannot be updated. More info:\n     https:&#47;&#47;kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-lifecycle#container-probes\n\n     Probe describes a health check to be performed against a container to\n     determine whether it is alive or ready to receive traffic.\n\nFIELDS:\n   exec &lt;Object&gt;\n     One and only one of the following should be specified. Exec specifies the\n     action to take.\n\n   failureThreshold     &lt;integer&gt;\n     Minimum consecutive failures for the probe to be considered failed after\n     having succeeded. Defaults to 3. Minimum value is 1.\n\n   httpGet      &lt;Object&gt;\n     HTTPGet specifies the http request to perform.\n\n   initialDelaySeconds  &lt;integer&gt;\n     Number of seconds after the container has started before liveness probes\n     are initiated. More info:\n     https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-lifecycle#container-probes\n\n   periodSeconds        &lt;integer&gt;\n     How often (in seconds) to perform the probe. Default to 10 seconds. Minimum\n     value is 1.\n\n   successThreshold     &lt;integer&gt;\n     Minimum consecutive successes for the probe to be considered successful\n     after having failed. Defaults to 1. Must be 1 for liveness and startup.\n     Minimum value is 1.\n\n   tcpSocket    &lt;Object&gt;\n     TCPSocket specifies an action involving a TCP port. TCP hooks not yet\n     supported\n\n   terminationGracePeriodSeconds        &lt;integer&gt;\n     Optional duration in seconds the pod needs to terminate gracefully upon\n     probe failure. The grace period is the duration in seconds after the\n     processes running in the pod are sent a termination signal and the time\n     when the processes are forcibly halted with a kill signal. Set this value\n     longer than the expected cleanup time for your process. If this value is\n     nil, the pod's terminationGracePeriodSeconds will be used. Otherwise, this\n     value overrides the value provided by the pod spec. Value must be\n     non-negative integer. The value zero indicates stop immediately via the\n     kill signal (no opportunity to shut down). This is a beta field and\n     requires enabling ProbeTerminationGracePeriod feature gate. Minimum value\n     is 1. spec.terminationGracePeriodSeconds is used if unset.\n\n   timeoutSeconds       &lt;integer&gt;\n     Number of seconds after which the probe times out. Defaults to 1 second.\n     Minimum value is 1. More info:\n     https:\/\/kubernetes.io\/docs\/concepts\/workloads\/pods\/pod-lifecycle#container-probes<\/code><\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u6570\u7b80\u4ecb<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">initialDelaySeconds\uff1a\u5bb9\u5668\u542f\u52a8\u540e\u8981\u7b49\u5f85\u591a\u5c11\u79d2\u540e\u5b58\u6d3b\u548c\u5c31\u7eea\u63a2\u6d4b\u5668\u624d\u88ab\u521d\u59cb\u5316\uff0c\u9ed8\u8ba4\u662f 0 \u79d2\uff0c\u6700\u5c0f\u503c\u662f 0\u3002<br>periodSeconds\uff1a\u6267\u884c\u63a2\u6d4b\u7684\u65f6\u95f4\u95f4\u9694\uff08\u5355\u4f4d\u662f\u79d2\uff09\u3002\u9ed8\u8ba4\u662f 10 \u79d2\u3002\u6700\u5c0f\u503c\u662f 1\u3002<br>timeoutSeconds\uff1a\u63a2\u6d4b\u7684\u8d85\u65f6\u540e\u7b49\u5f85\u591a\u5c11\u79d2\u3002\u9ed8\u8ba4\u503c\u662f 1 \u79d2\u3002\u6700\u5c0f\u503c\u662f 1\u3002<br>successThreshold\uff1a\u63a2\u6d4b\u5668\u5728\u5931\u8d25\u540e\uff0c\u88ab\u89c6\u4e3a\u6210\u529f\u7684\u6700\u5c0f\u8fde\u7eed\u6210\u529f\u6570\u3002\u9ed8\u8ba4\u503c\u662f 1\u3002\u5b58\u6d3b\u63a2\u6d4b\u7684\u8fd9\u4e2a\u503c\u5fc5\u987b\u662f 1\u3002\u6700\u5c0f\u503c\u662f 1\u3002<br>failureThreshold\uff1a\u5f53 Pod \u542f\u52a8\u4e86\u5e76\u4e14\u63a2\u6d4b\u5230\u5931\u8d25\uff0cKubernetes \u7684\u91cd\u8bd5\u6b21\u6570\u3002\u5b58\u6d3b\u63a2\u6d4b\u60c5\u51b5\u4e0b\u7684\u653e\u5f03\u5c31\u610f\u5473\u7740\u91cd\u65b0\u542f\u52a8\u5bb9\u5668\u3002\u5c31\u7eea\u63a2\u6d4b\u60c5\u51b5\u4e0b\u7684\u653e\u5f03 Pod \u4f1a\u88ab\u6253\u4e0a\u672a\u5c31\u7eea\u7684\u6807\u7b7e\u3002\u9ed8\u8ba4\u503c\u662f 3\u3002\u6700\u5c0f\u503c\u662f 1\u3002<br>HTTP\u63a2\u9488\u53ef\u4ee5\u5728 httpGet \u4e0a\u914d\u7f6e\u989d\u5916\u7684\u5b57\u6bb5\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">host\uff1a\u8fde\u63a5\u4f7f\u7528\u7684\u4e3b\u673a\u540d\uff0c\u9ed8\u8ba4\u662f Pod \u7684 IP\u3002\u4e5f\u53ef\u4ee5\u5728 HTTP \u5934\u4e2d\u8bbe\u7f6e \u201cHost\u201d \u6765\u4ee3\u66ff\u3002<br>scheme\uff1a\u7528\u4e8e\u8bbe\u7f6e\u8fde\u63a5\u4e3b\u673a\u7684\u65b9\u5f0f\uff08HTTP \u8fd8\u662f HTTPS\uff09\u3002\u9ed8\u8ba4\u662f HTTP\u3002<br>path\uff1a\u8bbf\u95ee HTTP \u670d\u52a1\u7684\u8def\u5f84\u3002<br>httpHeaders\uff1a\u8bf7\u6c42\u4e2d\u81ea\u5b9a\u4e49\u7684 HTTP \u5934\u3002HTTP \u5934\u5b57\u6bb5\u5141\u8bb8\u91cd\u590d\u3002<br>port\uff1a\u8bbf\u95ee\u5bb9\u5668\u7684\u7aef\u53e3\u53f7\u6216\u8005\u7aef\u53e3\u540d\u3002\u5982\u679c\u6570\u5b57\u5fc5\u987b\u5728 1 \uff5e 65535 \u4e4b\u95f4\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>ReadinessProbe\u3001startupProbe\u5404\u9879\u53c2\u6570\u89e3\u91ca\u540c\u4e0a\u9762\u7684livenessProbe<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_%E6%8E%A2%E9%92%88%E7%A4%BA%E4%BE%8B\"><\/span>3. \u63a2\u9488\u793a\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">livenessProbe\u63a2\u9488\u793a\u4f8b<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"31_%E9%80%9A%E8%BF%87exec%E6%96%B9%E5%BC%8F%E5%81%9A%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\"><\/span>3.1 \u901a\u8fc7exec\u65b9\u5f0f\u505a\u5065\u5eb7\u63a2\u6d4b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master test]# cat liveness-exec.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: liveness-exec\n  labels:\n    app: liveness\nspec:\n  containers:\n  - name: liveness\n    image: busybox\n    args:                       #\u521b\u5efa\u6d4b\u8bd5\u63a2\u9488\u63a2\u6d4b\u7684\u6587\u4ef6\n    - \/bin\/sh\n    - -c\n    - touch \/tmp\/healthy; sleep 30; rm -rf \/tmp\/healthy; sleep 600\n    livenessProbe:\n      initialDelaySeconds: 10   #\u5ef6\u8fdf\u68c0\u6d4b\u65f6\u95f4\n      periodSeconds: 5          #\u68c0\u6d4b\u65f6\u95f4\u95f4\u9694\n      exec:                     #\u4f7f\u7528\u547d\u4ee4\u68c0\u67e5\n        command:                #\u6307\u4ee4\uff0c\u7c7b\u4f3c\u4e8e\u8fd0\u884c\u547d\u4ee4sh\n        - cat                   #sh \u540e\u7684\u7b2c\u4e00\u4e2a\u5185\u5bb9\uff0c\u76f4\u5230\u9700\u8981\u8f93\u5165\u7a7a\u683c\uff0c\u53d8\u6210\u4e0b\u4e00\u884c\n        - \/tmp\/healthy          #\u7531\u4e8e\u4e0d\u80fd\u8f93\u5165\u7a7a\u683c\uff0c\u9700\u8981\u53e6\u5916\u58f0\u660e\uff0c\u7ed3\u679c\u4e3ash cat\"\u7a7a\u683c\"\/tmp\/healthy<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># \u89e3\u91ca\u6574\u4f53\u610f\u601d\uff1a\n\u5bb9\u5668\u5728\u521d\u59cb\u5316\u540e\uff0c\u6267\u884c\uff08\/bin\/sh -c \"touch \/tmp\/healthy; sleep 30; rm -rf \/tmp\/healthy; sleep 600\"\uff09\u9996\u5148\u521b\u5efa\u4e00\u4e2a \/tmp\/healthy \u6587\u4ef6\uff0c\u7136\u540e\u6267\u884c\u7761\u7720\u547d\u4ee4\uff0c\u7761\u7720 30 \u79d2\uff0c\u5230\u65f6\u95f4\u540e\u6267\u884c\u5220\u9664 \/tmp\/healthy \u6587\u4ef6\u547d\u4ee4\u3002\u800c\u8bbe\u7f6e\u7684\u5b58\u6d3b\u63a2\u9488\u68c0\u68c0\u6d4b\u65b9\u5f0f\u4e3a\u6267\u884c shell \u547d\u4ee4\uff0c\u7528 cat \u547d\u4ee4\u8f93\u51fa healthy \u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u5982\u679c\u80fd\u6210\u529f\u6267\u884c\u8fd9\u6761\u547d\u4ee4\u4e00\u6b21(\u9ed8\u8ba4successThreshold:1)\uff0c\u5b58\u6d3b\u63a2\u9488\u5c31\u8ba4\u4e3a\u63a2\u6d4b\u6210\u529f\uff0c\u7531\u4e8e\u6ca1\u6709\u914d\u7f6e(failureThreshold\u3001timeoutSeconds)\uff0c\u6240\u4ee5\u6267\u884c\uff08cat \/tmp\/healthy\uff09\u5e76\u53ea\u7b49\u5f851s\uff0c\u5982\u679c1s\u5185\u6267\u884c\u540e\u8fd4\u56de\u5931\u8d25\uff0c\u63a2\u6d4b\u5931\u8d25\u3002\u5728\u524d 30 \u79d2\u5185\uff0c\u7531\u4e8e\u6587\u4ef6\u5b58\u5728\uff0c\u6240\u4ee5\u5b58\u6d3b\u63a2\u9488\u63a2\u6d4b\u65f6\u6267\u884c cat \/tmp\/healthy \u547d\u4ee4\u6210\u529f\u6267\u884c\u300230 \u79d2\u540e healthy \u6587\u4ef6\u88ab\u5220\u9664\uff0c\u6240\u4ee5\u6267\u884c\u547d\u4ee4\u5931\u8d25\uff0cKubernetes \u4f1a\u6839\u636e Pod \u8bbe\u7f6e\u7684\u91cd\u542f\u7b56\u7565\u6765\u5224\u65ad\uff0c\u662f\u5426\u91cd\u542f Pod\u3002<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"32_%E9%80%9A%E8%BF%87HTTP%E6%96%B9%E5%BC%8F%E5%81%9A%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\"><\/span>3.2 \u901a\u8fc7HTTP\u65b9\u5f0f\u505a\u5065\u5eb7\u63a2\u6d4b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>httpGet\u63a2\u6d4b\u65b9\u5f0f\u6709\u5982\u4e0b\u53ef\u9009\u7684\u63a7\u5236\u5b57\u6bb5:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scheme: \u7528\u4e8e\u8fde\u63a5host\u7684\u534f\u8bae\uff0c\u9ed8\u8ba4\u4e3aHTTP\u3002\nhost\uff1a\u8981\u8fde\u63a5\u7684\u4e3b\u673a\u540d\uff0c\u9ed8\u8ba4\u4e3aPod IP\uff0c\u53ef\u4ee5\u5728http request head\u4e2d\u8bbe\u7f6ehost\u5934\u90e8\u3002\nport\uff1a\u5bb9\u5668\u4e0a\u8981\u8bbf\u95ee\u7aef\u53e3\u53f7\u6216\u540d\u79f0\u3002\npath\uff1ahttp\u670d\u52a1\u5668\u4e0a\u7684\u8bbf\u95eeURI\u3002\nhttpHeaders\uff1a\u81ea\u5b9a\u4e49HTTP\u8bf7\u6c42headers\uff0cHTTP\u5141\u8bb8\u91cd\u590dheaders\u3002<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master test]# cat liveness-http.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: liveness-http\n  labels:\n    test: liveness\nspec:\n  containers:\n  - name: liveness\n    image: test\/springboot-helloworld:0.0.1\n    livenessProbe:\n      failureThreshold: 5       #\u68c0\u6d4b\u5931\u8d255\u6b21\u8868\u793a\u672a\u5c31\u7eea\n      initialDelaySeconds: 20   #\u5ef6\u8fdf\u52a0\u8f7d\u65f6\u95f4\n      periodSeconds: 10          #\u91cd\u8bd5\u65f6\u95f4\u95f4\u9694\n      timeoutSeconds: 5         #\u8d85\u65f6\u65f6\u95f4\u8bbe\u7f6e\n      successThreshold: 2       #\u68c0\u67e5\u6210\u529f\u4e3a2\u6b21\u8868\u793a\u5c31\u7eea\n      httpGet:\n        scheme: HTTP\n        port: 8081\n        path: \/actuator\/health<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># \u89e3\u91ca\u6574\u4f53\u610f\u601d\uff1a\n\u4e0a\u9762 Pod \u4e2d\u542f\u52a8\u7684\u5bb9\u5668\u662f\u4e00\u4e2a SpringBoot \u5e94\u7528\uff0c\u5176\u4e2d\u5f15\u7528\u4e86 Actuator \u7ec4\u4ef6\uff0c\u63d0\u4f9b\u4e86 \/actuator\/health \u5065\u5eb7\u68c0\u67e5\u5730\u5740\uff0c\u5728pod\u542f\u52a8\u540e\uff0c\u521d\u59cb\u5316\u7b49\u5f8520s\u540e\uff0clivenessProbe\u5f00\u59cb\u5de5\u4f5c\uff0c\u53bb\u8bf7\u6c42HTTP:\/\/podIP:8081\/actuator\/health \u63a5\u53e3\uff0c\u7c7b\u4f3c\u4e8ecurl -I HTTP:\/\/podIP:8081\/actuator\/health\u63a5\u53e3,\u8003\u8651\u5230\u8bf7\u6c42\u4f1a\u6709\u5ef6\u8fdf(curl -I\u540e\u4e00\u76f4\u51fa\u73b0\u5047\u6b7b\u72b6\u6001)\uff0c\u6240\u4ee5\u7ed9\u8fd9\u6b21\u8bf7\u6c42\u64cd\u4f5c\u4e00\u76f4\u6301\u7eed5s\uff0c\u5982\u679c5s\u5185\u8bbf\u95ee\u8fd4\u56de\u6570\u503c\u5728&gt;=200\u4e14&lt;=400\u4ee3\u8868\u7b2c\u4e00\u6b21\u68c0\u6d4bsuccess\uff0c\u5982\u679c\u662f\u5176\u4ed6\u7684\u6570\u503c\uff0c\u6216\u80055s\u540e\u8fd8\u662f\u5047\u6b7b\u72b6\u6001\uff0c\u6267\u884c\u7c7b\u4f3c\uff08ctrl+c\uff09\u4e2d\u65ad\uff0c\u5e76\u53cd\u56defailure\u5931\u8d25\u3002\u7b49\u5f8510s\u540e\uff0c\u518d\u4e00\u6b21\u7684\u53bb\u8bf7\u6c42HTTP:\/\/podIP:8081\/actuator\/health\u63a5\u53e3\u3002\u5982\u679c\u6709\u8fde\u7eed\u76842\u6b21\u90fd\u662fsuccess\uff0c\u4ee3\u8868\u65e0\u95ee\u9898\u3002\u5982\u679c\u671f\u95f4\u6709\u8fde\u7eed\u76845\u6b21\u90fd\u662ffailure\uff0c\u4ee3\u8868\u6709\u95ee\u9898\uff0c\u76f4\u63a5\u91cd\u542fpod\uff0c\u6b64\u64cd\u4f5c\u4f1a\u4f34\u968fpod\u7684\u6574\u4e2a\u751f\u547d\u5468\u671f<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"33_%E9%80%9A%E8%BF%87TCP%E6%96%B9%E5%BC%8F%E5%81%A5%E5%BA%B7%E6%8E%A2%E6%B5%8B\"><\/span>3.3 \u901a\u8fc7TCP\u65b9\u5f0f\u5065\u5eb7\u63a2\u6d4b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@k8s-master test]# cat liveness-tcp.yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: liveness-tcp\n  labels:\n    app: liveness\nspec:\n  containers:\n  - name: liveness\n    image: nginx\n    livenessProbe:\n      initialDelaySeconds: 15\n      periodSeconds: 20\n      tcpSocket:\n        port: 80<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code># \u89e3\u91ca\u6574\u4f53\u610f\u601d\uff1a\nTCP \u68c0\u67e5\u65b9\u5f0f\u548c HTTP \u68c0\u67e5\u65b9\u5f0f\u975e\u5e38\u76f8\u4f3c\uff0c\u5728\u5bb9\u5668\u542f\u52a8 initialDelaySeconds \u53c2\u6570\u8bbe\u5b9a\u7684\u65f6\u95f4\u540e\uff0ckubelet \u5c06\u53d1\u9001\u7b2c\u4e00\u4e2a livenessProbe \u63a2\u9488\uff0c\u5c1d\u8bd5\u8fde\u63a5\u5bb9\u5668\u7684 80 \u7aef\u53e3\uff0c\u7c7b\u4f3c\u4e8etelnet 80\u7aef\u53e3\uff0c\u5982\u679c\u8fde\u63a5\u5931\u8d25\u5219\u5c06\u6740\u6b7b Pod \u91cd\u542f\u5bb9\u5668\u3002\n\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53c2\u8003\u94fe\u63a5\uff1ahttps:\/\/www.akiraka.net\/kubernetes\/855.html<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/blog.csdn.net\/qq_42642159\/article\/details\/122719094<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/blog.csdn.net\/m0_45406092\/article\/details\/118997434<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">https:\/\/blog.csdn.net\/Jerry00713\/article\/details\/123894868<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. \u63a2\u9488\u4ecb\u7ecd \u8c08\u63a2\u9488\u4e4b\u524d\uff0c\u5148\u6765\u8bf4\u8bf4Pod\u3002 \u5728k8s\u4e2d\uff0cP &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_zb_attr":"","zolo_post_video_link":"","footnotes":""},"categories":[5],"tags":[],"series":[],"class_list":["post-167","post","type-post","status-publish","format-standard","hentry","category-kubernetes"],"_links":{"self":[{"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=167"}],"version-history":[{"count":37,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":205,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=\/wp\/v2\/posts\/167\/revisions\/205"}],"wp:attachment":[{"href":"https:\/\/www.dataz8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=167"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.dataz8.com\/index.php?rest_route=%2Fwp%2Fv2%2Fseries&post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}