1662 lines
87 KiB
HTML
1662 lines
87 KiB
HTML
|
|
|||
|
<!DOCTYPE HTML>
|
|||
|
<html lang="zh-cn" >
|
|||
|
<head>
|
|||
|
<meta charset="UTF-8">
|
|||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|||
|
<title>3.1.1 配置Pod的liveness和readiness探针 · Kubernetes Handbook</title>
|
|||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|||
|
<meta name="description" content="">
|
|||
|
<meta name="generator" content="GitBook 3.2.2">
|
|||
|
<meta name="author" content="Jimmy Song">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/style.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-image-captions/image-captions.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-page-footer-ex/style/plugin.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search-plus/search.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<meta name="HandheldFriendly" content="true"/>
|
|||
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|||
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|||
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|||
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
|
|||
|
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
|
|||
|
|
|||
|
|
|||
|
<link rel="next" href="configure-pod-service-account.html" />
|
|||
|
|
|||
|
|
|||
|
<link rel="prev" href="resource-configuration.html" />
|
|||
|
|
|||
|
|
|||
|
</head>
|
|||
|
<body>
|
|||
|
|
|||
|
<div class="book">
|
|||
|
<div class="book-summary">
|
|||
|
|
|||
|
|
|||
|
<div id="book-search-input" role="search">
|
|||
|
<input type="text" placeholder="輸入並搜尋" />
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
<nav role="navigation">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="summary">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.1" data-path="../">
|
|||
|
|
|||
|
<a href="../">
|
|||
|
|
|||
|
|
|||
|
1. 前言
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2" data-path="../concepts/">
|
|||
|
|
|||
|
<a href="../concepts/">
|
|||
|
|
|||
|
|
|||
|
2. 概念原理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.1" data-path="../concepts/concepts.html">
|
|||
|
|
|||
|
<a href="../concepts/concepts.html">
|
|||
|
|
|||
|
|
|||
|
2.1 设计理念
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2" data-path="../concepts/objects.html">
|
|||
|
|
|||
|
<a href="../concepts/objects.html">
|
|||
|
|
|||
|
|
|||
|
2.2 主要概念
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.1" data-path="../concepts/pod-overview.html">
|
|||
|
|
|||
|
<a href="../concepts/pod-overview.html">
|
|||
|
|
|||
|
|
|||
|
2.2.1 Pod
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.1.1" data-path="../concepts/pod.html">
|
|||
|
|
|||
|
<a href="../concepts/pod.html">
|
|||
|
|
|||
|
|
|||
|
2.2.1.1 Pod解析
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.2" data-path="../concepts/node.html">
|
|||
|
|
|||
|
<a href="../concepts/node.html">
|
|||
|
|
|||
|
|
|||
|
2.2.2 Node
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.3" data-path="../concepts/namespace.html">
|
|||
|
|
|||
|
<a href="../concepts/namespace.html">
|
|||
|
|
|||
|
|
|||
|
2.2.3 Namespace
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.4" data-path="../concepts/service.html">
|
|||
|
|
|||
|
<a href="../concepts/service.html">
|
|||
|
|
|||
|
|
|||
|
2.2.4 Service
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.5" data-path="../concepts/volume.html">
|
|||
|
|
|||
|
<a href="../concepts/volume.html">
|
|||
|
|
|||
|
|
|||
|
2.2.5 Volume和Persistent Volume
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.6" data-path="../concepts/deployment.html">
|
|||
|
|
|||
|
<a href="../concepts/deployment.html">
|
|||
|
|
|||
|
|
|||
|
2.2.6 Deployment
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.7" data-path="../concepts/secret.html">
|
|||
|
|
|||
|
<a href="../concepts/secret.html">
|
|||
|
|
|||
|
|
|||
|
2.2.7 Secret
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.8" data-path="../concepts/statefulset.html">
|
|||
|
|
|||
|
<a href="../concepts/statefulset.html">
|
|||
|
|
|||
|
|
|||
|
2.2.8 StatefulSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.9" data-path="../concepts/daemonset.html">
|
|||
|
|
|||
|
<a href="../concepts/daemonset.html">
|
|||
|
|
|||
|
|
|||
|
2.2.9 DaemonSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.10" data-path="../concepts/serviceaccount.html">
|
|||
|
|
|||
|
<a href="../concepts/serviceaccount.html">
|
|||
|
|
|||
|
|
|||
|
2.2.10 ServiceAccount
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.11" data-path="../concepts/replicaset.html">
|
|||
|
|
|||
|
<a href="../concepts/replicaset.html">
|
|||
|
|
|||
|
|
|||
|
2.2.11 ReplicationController和ReplicaSet
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.12" data-path="../concepts/job.html">
|
|||
|
|
|||
|
<a href="../concepts/job.html">
|
|||
|
|
|||
|
|
|||
|
2.2.12 Job
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.13" data-path="../concepts/cronjob.html">
|
|||
|
|
|||
|
<a href="../concepts/cronjob.html">
|
|||
|
|
|||
|
|
|||
|
2.2.13 CronJob
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.14" data-path="../concepts/ingress.html">
|
|||
|
|
|||
|
<a href="../concepts/ingress.html">
|
|||
|
|
|||
|
|
|||
|
2.2.14 Ingress
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.15" data-path="../concepts/configmap.html">
|
|||
|
|
|||
|
<a href="../concepts/configmap.html">
|
|||
|
|
|||
|
|
|||
|
2.2.15 ConfigMap
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.16" data-path="../concepts/horizontal-pod-autoscaling.html">
|
|||
|
|
|||
|
<a href="../concepts/horizontal-pod-autoscaling.html">
|
|||
|
|
|||
|
|
|||
|
2.2.16 Horizontal Pod Autoscaling
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.2.2.17" data-path="../concepts/label.html">
|
|||
|
|
|||
|
<a href="../concepts/label.html">
|
|||
|
|
|||
|
|
|||
|
2.2.17 Label
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3" data-path="./">
|
|||
|
|
|||
|
<a href="./">
|
|||
|
|
|||
|
|
|||
|
3. 用户指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.1" data-path="resource-configuration.html">
|
|||
|
|
|||
|
<a href="resource-configuration.html">
|
|||
|
|
|||
|
|
|||
|
3.1 资源配置
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter active" data-level="1.3.1.1" data-path="configure-liveness-readiness-probes.html">
|
|||
|
|
|||
|
<a href="configure-liveness-readiness-probes.html">
|
|||
|
|
|||
|
|
|||
|
3.1.1 配置Pod的liveness和readiness探针
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.1.2" data-path="configure-pod-service-account.html">
|
|||
|
|
|||
|
<a href="configure-pod-service-account.html">
|
|||
|
|
|||
|
|
|||
|
3.1.2 配置Pod的Service Account
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.2" data-path="command-usage.html">
|
|||
|
|
|||
|
<a href="command-usage.html">
|
|||
|
|
|||
|
|
|||
|
3.2 命令使用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.2.1" data-path="using-kubectl.html">
|
|||
|
|
|||
|
<a href="using-kubectl.html">
|
|||
|
|
|||
|
|
|||
|
3.2.1 使用kubectl
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.3" data-path="cluster-management.html">
|
|||
|
|
|||
|
<a href="cluster-management.html">
|
|||
|
|
|||
|
|
|||
|
3.3 集群管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.3.1" data-path="managing-tls-in-a-cluster.html">
|
|||
|
|
|||
|
<a href="managing-tls-in-a-cluster.html">
|
|||
|
|
|||
|
|
|||
|
3.3.1 管理集群中的TLS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.4" data-path="access-kubernetes-cluster.html">
|
|||
|
|
|||
|
<a href="access-kubernetes-cluster.html">
|
|||
|
|
|||
|
|
|||
|
3.4 访问 Kubernetes 集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.4.1" data-path="access-cluster.html">
|
|||
|
|
|||
|
<a href="access-cluster.html">
|
|||
|
|
|||
|
|
|||
|
3.4.1 访问集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.4.2" data-path="authenticate-across-clusters-kubeconfig.html">
|
|||
|
|
|||
|
<a href="authenticate-across-clusters-kubeconfig.html">
|
|||
|
|
|||
|
|
|||
|
3.4.2 使用 kubeconfig 文件配置跨集群认证
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.4.3" data-path="connecting-to-applications-port-forward.html">
|
|||
|
|
|||
|
<a href="connecting-to-applications-port-forward.html">
|
|||
|
|
|||
|
|
|||
|
3.4.3 通过端口转发访问集群中的应用程序
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.4.4" data-path="service-access-application-cluster.html">
|
|||
|
|
|||
|
<a href="service-access-application-cluster.html">
|
|||
|
|
|||
|
|
|||
|
3.4.4 使用 service 访问群集中的应用程序
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.5" data-path="application-development-deployment-flow.html">
|
|||
|
|
|||
|
<a href="application-development-deployment-flow.html">
|
|||
|
|
|||
|
|
|||
|
3.5 在kubernetes中开发部署应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.3.5.1" data-path="deploy-applications-in-kubernetes.html">
|
|||
|
|
|||
|
<a href="deploy-applications-in-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
3.5.1 适用于kubernetes的应用开发部署流程
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4" data-path="../practice/">
|
|||
|
|
|||
|
<a href="../practice/">
|
|||
|
|
|||
|
|
|||
|
4. 最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1" data-path="../practice/install-kbernetes1.6-on-centos.html">
|
|||
|
|
|||
|
<a href="../practice/install-kbernetes1.6-on-centos.html">
|
|||
|
|
|||
|
|
|||
|
4.1 在CentOS上部署kubernetes1.6集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.1" data-path="../practice/create-tls-and-secret-key.html">
|
|||
|
|
|||
|
<a href="../practice/create-tls-and-secret-key.html">
|
|||
|
|
|||
|
|
|||
|
4.1.1 创建TLS证书和秘钥
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.2" data-path="../practice/create-kubeconfig.html">
|
|||
|
|
|||
|
<a href="../practice/create-kubeconfig.html">
|
|||
|
|
|||
|
|
|||
|
4.1.2 创建kubeconfig文件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.3" data-path="../practice/etcd-cluster-installation.html">
|
|||
|
|
|||
|
<a href="../practice/etcd-cluster-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.3 创建高可用etcd集群
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.4" data-path="../practice/kubectl-installation.html">
|
|||
|
|
|||
|
<a href="../practice/kubectl-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.4 安装kubectl命令行工具
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.5" data-path="../practice/master-installation.html">
|
|||
|
|
|||
|
<a href="../practice/master-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.5 部署master节点
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.6" data-path="../practice/node-installation.html">
|
|||
|
|
|||
|
<a href="../practice/node-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.6 部署node节点
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.7" data-path="../practice/kubedns-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/kubedns-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.7 安装kubedns插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.8" data-path="../practice/dashboard-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/dashboard-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.8 安装dashboard插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.9" data-path="../practice/heapster-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/heapster-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.9 安装heapster插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.1.10" data-path="../practice/efk-addon-installation.html">
|
|||
|
|
|||
|
<a href="../practice/efk-addon-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.1.10 安装EFK插件
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.2" data-path="../practice/service-discovery-and-loadbalancing.html">
|
|||
|
|
|||
|
<a href="../practice/service-discovery-and-loadbalancing.html">
|
|||
|
|
|||
|
|
|||
|
4.2 服务发现与负载均衡
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.2.1" data-path="../practice/traefik-ingress-installation.html">
|
|||
|
|
|||
|
<a href="../practice/traefik-ingress-installation.html">
|
|||
|
|
|||
|
|
|||
|
4.2.1 安装Traefik ingress
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.2.2" data-path="../practice/distributed-load-test.html">
|
|||
|
|
|||
|
<a href="../practice/distributed-load-test.html">
|
|||
|
|
|||
|
|
|||
|
4.2.2 分布式负载测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.2.3" data-path="../practice/network-and-cluster-perfermance-test.html">
|
|||
|
|
|||
|
<a href="../practice/network-and-cluster-perfermance-test.html">
|
|||
|
|
|||
|
|
|||
|
4.2.3 网络和集群性能测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.2.4" data-path="../practice/edge-node-configuration.html">
|
|||
|
|
|||
|
<a href="../practice/edge-node-configuration.html">
|
|||
|
|
|||
|
|
|||
|
4.2.4 边缘节点配置
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3" data-path="../practice/operation.html">
|
|||
|
|
|||
|
<a href="../practice/operation.html">
|
|||
|
|
|||
|
|
|||
|
4.3 运维管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.1" data-path="../practice/service-rolling-update.html">
|
|||
|
|
|||
|
<a href="../practice/service-rolling-update.html">
|
|||
|
|
|||
|
|
|||
|
4.3.1 服务滚动升级
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.2" data-path="../practice/app-log-collection.html">
|
|||
|
|
|||
|
<a href="../practice/app-log-collection.html">
|
|||
|
|
|||
|
|
|||
|
4.3.2 应用日志收集
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.3" data-path="../practice/configuration-best-practice.html">
|
|||
|
|
|||
|
<a href="../practice/configuration-best-practice.html">
|
|||
|
|
|||
|
|
|||
|
4.3.3 配置最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.4" data-path="../practice/monitor.html">
|
|||
|
|
|||
|
<a href="../practice/monitor.html">
|
|||
|
|
|||
|
|
|||
|
4.3.4 集群及应用监控
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.5" data-path="../practice/jenkins-ci-cd.html">
|
|||
|
|
|||
|
<a href="../practice/jenkins-ci-cd.html">
|
|||
|
|
|||
|
|
|||
|
4.3.5 使用Jenkins进行持续构建与发布
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.3.6" data-path="../practice/data-persistence-problem.html">
|
|||
|
|
|||
|
<a href="../practice/data-persistence-problem.html">
|
|||
|
|
|||
|
|
|||
|
4.3.6 数据持久化问题
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.4" data-path="../practice/storage.html">
|
|||
|
|
|||
|
<a href="../practice/storage.html">
|
|||
|
|
|||
|
|
|||
|
4.4 存储管理
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.4.1" data-path="../practice/glusterfs.html">
|
|||
|
|
|||
|
<a href="../practice/glusterfs.html">
|
|||
|
|
|||
|
|
|||
|
4.4.1 GlusterFS
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.4.1.1" data-path="../practice/using-glusterfs-for-persistent-storage.html">
|
|||
|
|
|||
|
<a href="../practice/using-glusterfs-for-persistent-storage.html">
|
|||
|
|
|||
|
|
|||
|
4.4.1.1 使用GlusterFS做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.4.4.1.2" data-path="../practice/storage-for-containers-using-glusterfs-with-openshift.html">
|
|||
|
|
|||
|
<a href="../practice/storage-for-containers-using-glusterfs-with-openshift.html">
|
|||
|
|
|||
|
|
|||
|
4.4.1.2 在OpenShift中使用GlusterFS做持久化存储
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5" data-path="../usecases/">
|
|||
|
|
|||
|
<a href="../usecases/">
|
|||
|
|
|||
|
|
|||
|
5. 领域应用
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1" data-path="../usecases/microservices.html">
|
|||
|
|
|||
|
<a href="../usecases/microservices.html">
|
|||
|
|
|||
|
|
|||
|
5.1 微服务架构
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.1" data-path="../usecases/istio.html">
|
|||
|
|
|||
|
<a href="../usecases/istio.html">
|
|||
|
|
|||
|
|
|||
|
5.1.1 Istio
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.1.1" data-path="../usecases/istio-installation.html">
|
|||
|
|
|||
|
<a href="../usecases/istio-installation.html">
|
|||
|
|
|||
|
|
|||
|
5.1.1.1 安装istio
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.1.2" data-path="../usecases/configuring-request-routing.html">
|
|||
|
|
|||
|
<a href="../usecases/configuring-request-routing.html">
|
|||
|
|
|||
|
|
|||
|
5.1.1.2 配置请求的路由规则
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.2" data-path="../usecases/linkerd.html">
|
|||
|
|
|||
|
<a href="../usecases/linkerd.html">
|
|||
|
|
|||
|
|
|||
|
5.1.2 Linkerd
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.2.1" data-path="../usecases/linkerd-user-guide.html">
|
|||
|
|
|||
|
<a href="../usecases/linkerd-user-guide.html">
|
|||
|
|
|||
|
|
|||
|
5.1.2.1 Linkerd 使用指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.1.3" data-path="../usecases/service-discovery-in-microservices.html">
|
|||
|
|
|||
|
<a href="../usecases/service-discovery-in-microservices.html">
|
|||
|
|
|||
|
|
|||
|
5.1.3 微服务中的服务发现
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.2" data-path="../usecases/big-data.html">
|
|||
|
|
|||
|
<a href="../usecases/big-data.html">
|
|||
|
|
|||
|
|
|||
|
5.2 大数据
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.5.2.1" data-path="../usecases/spark-on-kubernetes.html">
|
|||
|
|
|||
|
<a href="../usecases/spark-on-kubernetes.html">
|
|||
|
|
|||
|
|
|||
|
5.2.1 Spark on Kubernetes
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.6" data-path="../develop/">
|
|||
|
|
|||
|
<a href="../develop/">
|
|||
|
|
|||
|
|
|||
|
6. 开发指南
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.6.1" data-path="../develop/developing-environment.html">
|
|||
|
|
|||
|
<a href="../develop/developing-environment.html">
|
|||
|
|
|||
|
|
|||
|
6.1 开发环境搭建
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.6.2" data-path="../develop/testing.html">
|
|||
|
|
|||
|
<a href="../develop/testing.html">
|
|||
|
|
|||
|
|
|||
|
6.2 单元测试和集成测试
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.6.3" data-path="../develop/client-go-sample.html">
|
|||
|
|
|||
|
<a href="../develop/client-go-sample.html">
|
|||
|
|
|||
|
|
|||
|
6.3 client-go示例
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.6.4" data-path="../develop/contribute.html">
|
|||
|
|
|||
|
<a href="../develop/contribute.html">
|
|||
|
|
|||
|
|
|||
|
6.4 社区贡献
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.7" data-path="../appendix/">
|
|||
|
|
|||
|
<a href="../appendix/">
|
|||
|
|
|||
|
|
|||
|
7. 附录
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<ul class="articles">
|
|||
|
|
|||
|
|
|||
|
<li class="chapter " data-level="1.7.1" data-path="../appendix/docker-best-practice.html">
|
|||
|
|
|||
|
<a href="../appendix/docker-best-practice.html">
|
|||
|
|
|||
|
|
|||
|
7.1 Docker最佳实践
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.7.2" data-path="../appendix/issues.html">
|
|||
|
|
|||
|
<a href="../appendix/issues.html">
|
|||
|
|
|||
|
|
|||
|
7.2 问题记录
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
<li class="chapter " data-level="1.7.3" data-path="../appendix/tricks.html">
|
|||
|
|
|||
|
<a href="../appendix/tricks.html">
|
|||
|
|
|||
|
|
|||
|
7.3 使用技巧
|
|||
|
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
</ul>
|
|||
|
|
|||
|
</li>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<li class="divider"></li>
|
|||
|
|
|||
|
<li>
|
|||
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
|||
|
本書使用 GitBook 釋出
|
|||
|
</a>
|
|||
|
</li>
|
|||
|
</ul>
|
|||
|
|
|||
|
|
|||
|
</nav>
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
<div class="book-body">
|
|||
|
|
|||
|
<div class="body-inner">
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<div class="book-header" role="navigation">
|
|||
|
|
|||
|
|
|||
|
<!-- Title -->
|
|||
|
<h1>
|
|||
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
|||
|
<a href=".." >3.1.1 配置Pod的liveness和readiness探针</a>
|
|||
|
</h1>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<div class="page-wrapper" tabindex="-1" role="main">
|
|||
|
<div class="page-inner">
|
|||
|
|
|||
|
<div class="search-plus" id="book-search-results">
|
|||
|
<div class="search-noresults">
|
|||
|
|
|||
|
<section class="normal markdown-section">
|
|||
|
|
|||
|
<h1 id="配置pod的liveness和readiness探针">配置Pod的liveness和readiness探针</h1>
|
|||
|
<p>当你使用kuberentes的时候,有没有遇到过Pod在启动后一会就挂掉然后又重新启动这样的恶性循环?你有没有想过kubernetes是如何检测pod是否还存活?虽然容器已经启动,但是kubernetes如何知道容器的进程是否准备好对外提供服务了呢?让我们通过kuberentes官网的这篇文章<a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/" target="_blank">Configure Liveness and Readiness Probes</a>,来一探究竟。</p>
|
|||
|
<p>本文将向展示如何配置容器的存活和可读性探针。</p>
|
|||
|
<p>Kubelet使用liveness probe(存活探针)来确定何时重启容器。例如,当应用程序处于运行状态但无法做进一步操作,liveness探针将捕获到deadlock,重启处于该状态下的容器,使应用程序在存在bug的情况下依然能够继续运行下去(谁的程序还没几个bug呢)。</p>
|
|||
|
<p>Kubelet使用readiness probe(就绪探针)来确定容器是否已经就绪可以接受流量。只有当Pod中的容器都处于就绪状态时kubelet才会认定该Pod处于就绪状态。该信号的作用是控制哪些Pod应该作为service的后端。如果Pod处于非就绪状态,那么它们将会被从service的load balancer中移除。</p>
|
|||
|
<h2 id="定义-liveness命令">定义 liveness命令</h2>
|
|||
|
<p>许多长时间运行的应用程序最终会转换到broken状态,除非重新启动,否则无法恢复。Kubernetes提供了liveness probe来检测和补救这种情况。</p>
|
|||
|
<p>在本次练习将基于 <code>gcr.io/google_containers/busybox</code>镜像创建运行一个容器的Pod。以下是Pod的配置文件<code>exec-liveness.yaml</code>:</p>
|
|||
|
<pre><code class="lang-Yaml"><span class="hljs-attr">apiVersion:</span> v1
|
|||
|
<span class="hljs-attr">kind:</span> Pod
|
|||
|
<span class="hljs-attr">metadata:</span>
|
|||
|
<span class="hljs-attr"> labels:</span>
|
|||
|
<span class="hljs-attr"> test:</span> liveness
|
|||
|
<span class="hljs-attr"> name:</span> liveness-exec
|
|||
|
<span class="hljs-attr">spec:</span>
|
|||
|
<span class="hljs-attr"> containers:</span>
|
|||
|
<span class="hljs-attr"> - name:</span> liveness
|
|||
|
<span class="hljs-attr"> args:</span>
|
|||
|
<span class="hljs-bullet"> -</span> /bin/sh
|
|||
|
<span class="hljs-bullet"> -</span> -c
|
|||
|
<span class="hljs-bullet"> -</span> touch /tmp/healthy; sleep <span class="hljs-number">30</span>; rm -rf /tmp/healthy; sleep <span class="hljs-number">600</span>
|
|||
|
<span class="hljs-attr"> image:</span> gcr.io/google_containers/busybox
|
|||
|
<span class="hljs-attr"> livenessProbe:</span>
|
|||
|
<span class="hljs-attr"> exec:</span>
|
|||
|
<span class="hljs-attr"> command:</span>
|
|||
|
<span class="hljs-bullet"> -</span> cat
|
|||
|
<span class="hljs-bullet"> -</span> /tmp/healthy
|
|||
|
<span class="hljs-attr"> initialDelaySeconds:</span> <span class="hljs-number">5</span>
|
|||
|
<span class="hljs-attr"> periodSeconds:</span> <span class="hljs-number">5</span>
|
|||
|
</code></pre>
|
|||
|
<p>该配置文件给Pod配置了一个容器。<code>periodSeconds</code> 规定kubelet要每隔5秒执行一次liveness probe。 <code>initialDelaySeconds</code> 告诉kubelet在第一次执行probe之前要的等待5秒钟。探针检测命令是在容器中执行 <code>cat /tmp/healthy</code> 命令。如果命令执行成功,将返回0,kubelet就会认为该容器是活着的并且很健康。如果返回非0值,kubelet就会杀掉这个容器并重启它。</p>
|
|||
|
<p>容器启动时,执行该命令:</p>
|
|||
|
<pre><code class="lang-shell">/bin/sh -c "touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600"
|
|||
|
</code></pre>
|
|||
|
<p>在容器生命的最初30秒内有一个 <code>/tmp/healthy</code> 文件,在这30秒内 <code>cat /tmp/healthy</code>命令会返回一个成功的返回码。30秒后, <code>cat /tmp/healthy</code> 将返回失败的返回码。</p>
|
|||
|
<p>创建Pod:</p>
|
|||
|
<pre><code class="lang-shell">kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/exec-liveness.yaml
|
|||
|
</code></pre>
|
|||
|
<p>在30秒内,查看Pod的event:</p>
|
|||
|
<pre><code>kubectl describe pod liveness-exec
|
|||
|
</code></pre><p>结果显示没有失败的liveness probe:</p>
|
|||
|
<pre><code class="lang-shell">FirstSeen LastSeen Count From SubobjectPath Type Reason Message
|
|||
|
--------- -------- ----- ---- ------------- -------- ------ -------
|
|||
|
24s 24s 1 {default-scheduler } Normal Scheduled Successfully assigned liveness-exec to worker0
|
|||
|
23s 23s 1 {kubelet worker0} spec.containers{liveness} Normal Pulling pulling image "gcr.io/google_containers/busybox"
|
|||
|
23s 23s 1 {kubelet worker0} spec.containers{liveness} Normal Pulled Successfully pulled image "gcr.io/google_containers/busybox"
|
|||
|
23s 23s 1 {kubelet worker0} spec.containers{liveness} Normal Created Created container with docker id 86849c15382e; Security:[seccomp=unconfined]
|
|||
|
23s 23s 1 {kubelet worker0} spec.containers{liveness} Normal Started Started container with docker id 86849c15382e
|
|||
|
</code></pre>
|
|||
|
<p>启动35秒后,再次查看pod的event:</p>
|
|||
|
<pre><code class="lang-shell">kubectl describe pod liveness-exec
|
|||
|
</code></pre>
|
|||
|
<p>在最下面有一条信息显示liveness probe失败,容器被删掉并重新创建。</p>
|
|||
|
<pre><code class="lang-shell">FirstSeen LastSeen Count From SubobjectPath Type Reason Message
|
|||
|
--------- -------- ----- ---- ------------- -------- ------ -------
|
|||
|
37s 37s 1 {default-scheduler } Normal Scheduled Successfully assigned liveness-exec to worker0
|
|||
|
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Pulling pulling image "gcr.io/google_containers/busybox"
|
|||
|
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Pulled Successfully pulled image "gcr.io/google_containers/busybox"
|
|||
|
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Created Created container with docker id 86849c15382e; Security:[seccomp=unconfined]
|
|||
|
36s 36s 1 {kubelet worker0} spec.containers{liveness} Normal Started Started container with docker id 86849c15382e
|
|||
|
2s 2s 1 {kubelet worker0} spec.containers{liveness} Warning Unhealthy Liveness probe failed: cat: can't open '/tmp/healthy': No such file or directory
|
|||
|
</code></pre>
|
|||
|
<p>再等30秒,确认容器已经重启:</p>
|
|||
|
<pre><code class="lang-shell">kubectl get pod liveness-exec
|
|||
|
</code></pre>
|
|||
|
<p>从输出结果来<code>RESTARTS</code>值加1了。</p>
|
|||
|
<pre><code class="lang-shell">NAME READY STATUS RESTARTS AGE
|
|||
|
liveness-exec 1/1 Running 1 1m
|
|||
|
</code></pre>
|
|||
|
<h2 id="定义一个liveness-http请求">定义一个liveness HTTP请求</h2>
|
|||
|
<p>我们还可以使用HTTP GET请求作为liveness probe。下面是一个基于<code>gcr.io/google_containers/liveness</code>镜像运行了一个容器的Pod的例子<code>http-liveness.yaml</code>:</p>
|
|||
|
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> v1
|
|||
|
<span class="hljs-attr">kind:</span> Pod
|
|||
|
<span class="hljs-attr">metadata:</span>
|
|||
|
<span class="hljs-attr"> labels:</span>
|
|||
|
<span class="hljs-attr"> test:</span> liveness
|
|||
|
<span class="hljs-attr"> name:</span> liveness-http
|
|||
|
<span class="hljs-attr">spec:</span>
|
|||
|
<span class="hljs-attr"> containers:</span>
|
|||
|
<span class="hljs-attr"> - name:</span> liveness
|
|||
|
<span class="hljs-attr"> args:</span>
|
|||
|
<span class="hljs-bullet"> -</span> /server
|
|||
|
<span class="hljs-attr"> image:</span> gcr.io/google_containers/liveness
|
|||
|
<span class="hljs-attr"> livenessProbe:</span>
|
|||
|
<span class="hljs-attr"> httpGet:</span>
|
|||
|
<span class="hljs-attr"> path:</span> /healthz
|
|||
|
<span class="hljs-attr"> port:</span> <span class="hljs-number">8080</span>
|
|||
|
<span class="hljs-attr"> httpHeaders:</span>
|
|||
|
<span class="hljs-attr"> - name:</span> X-Custom-Header
|
|||
|
<span class="hljs-attr"> value:</span> Awesome
|
|||
|
<span class="hljs-attr"> initialDelaySeconds:</span> <span class="hljs-number">3</span>
|
|||
|
<span class="hljs-attr"> periodSeconds:</span> <span class="hljs-number">3</span>
|
|||
|
</code></pre>
|
|||
|
<p>该配置文件只定义了一个容器,<code>livenessProbe</code> 指定kubelete需要每隔3秒执行一次liveness probe。<code>initialDelaySeconds</code> 指定kubelet在该执行第一次探测之前需要等待3秒钟。该探针将向容器中的server的8080端口发送一个HTTP GET请求。如果server的<code>/healthz</code>路径的handler返回一个成功的返回码,kubelet就会认定该容器是活着的并且很健康。如果返回失败的返回码,kubelet将杀掉该容器并重启它。</p>
|
|||
|
<p>任何大于200小于400的返回码都会认定是成功的返回码。其他返回码都会被认为是失败的返回码。</p>
|
|||
|
<p>查看该server的源码:<a href="http://k8s.io/docs/user-guide/liveness/image/server.go" target="_blank">server.go</a>.</p>
|
|||
|
<p>最开始的10秒该容器是活着的, <code>/healthz</code> handler返回200的状态码。这之后将返回500的返回码。</p>
|
|||
|
<pre><code class="lang-go">http.HandleFunc(<span class="hljs-string">"/healthz"</span>, <span class="hljs-keyword">func</span>(w http.ResponseWriter, r *http.Request) {
|
|||
|
duration := time.Now().Sub(started)
|
|||
|
<span class="hljs-keyword">if</span> duration.Seconds() > <span class="hljs-number">10</span> {
|
|||
|
w.WriteHeader(<span class="hljs-number">500</span>)
|
|||
|
w.Write([]<span class="hljs-keyword">byte</span>(fmt.Sprintf(<span class="hljs-string">"error: %v"</span>, duration.Seconds())))
|
|||
|
} <span class="hljs-keyword">else</span> {
|
|||
|
w.WriteHeader(<span class="hljs-number">200</span>)
|
|||
|
w.Write([]<span class="hljs-keyword">byte</span>(<span class="hljs-string">"ok"</span>))
|
|||
|
}
|
|||
|
})
|
|||
|
</code></pre>
|
|||
|
<p>容器启动3秒后,kubelet开始执行健康检查。第一次健康监测会成功,但是10秒后,健康检查将失败,kubelet将杀掉和重启容器。</p>
|
|||
|
<p>创建一个Pod来测试一下HTTP liveness检测:</p>
|
|||
|
<pre><code class="lang-shell">kubectl create -f https://k8s.io/docs/tasks/configure-pod-container/http-liveness.yaml
|
|||
|
</code></pre>
|
|||
|
<p>After 10 seconds, view Pod events to verify that liveness probes have failed and
|
|||
|
the Container has been restarted:</p>
|
|||
|
<p>10秒后,查看Pod的event,确认liveness probe失败并重启了容器。</p>
|
|||
|
<pre><code class="lang-shell">kubectl describe pod liveness-http
|
|||
|
</code></pre>
|
|||
|
<h2 id="定义tcp-liveness探针">定义TCP liveness探针</h2>
|
|||
|
<p>第三种liveness probe使用TCP Socket。 使用此配置,kubelet将尝试在指定端口上打开容器的套接字。 如果可以建立连接,容器被认为是健康的,如果不能就认为是失败的。</p>
|
|||
|
<pre><code class="lang-yaml"><span class="hljs-attr">apiVersion:</span> v1
|
|||
|
<span class="hljs-attr">kind:</span> Pod
|
|||
|
<span class="hljs-attr">metadata:</span>
|
|||
|
<span class="hljs-attr"> name:</span> goproxy
|
|||
|
<span class="hljs-attr"> labels:</span>
|
|||
|
<span class="hljs-attr"> app:</span> goproxy
|
|||
|
<span class="hljs-attr">spec:</span>
|
|||
|
<span class="hljs-attr"> containers:</span>
|
|||
|
<span class="hljs-attr"> - name:</span> goproxy
|
|||
|
<span class="hljs-attr"> image:</span> gcr.io/google_containers/goproxy:<span class="hljs-number">0.1</span>
|
|||
|
<span class="hljs-attr"> ports:</span>
|
|||
|
<span class="hljs-attr"> - containerPort:</span> <span class="hljs-number">8080</span>
|
|||
|
<span class="hljs-attr"> readinessProbe:</span>
|
|||
|
<span class="hljs-attr"> tcpSocket:</span>
|
|||
|
<span class="hljs-attr"> port:</span> <span class="hljs-number">8080</span>
|
|||
|
<span class="hljs-attr"> initialDelaySeconds:</span> <span class="hljs-number">5</span>
|
|||
|
<span class="hljs-attr"> periodSeconds:</span> <span class="hljs-number">10</span>
|
|||
|
<span class="hljs-attr"> livenessProbe:</span>
|
|||
|
<span class="hljs-attr"> tcpSocket:</span>
|
|||
|
<span class="hljs-attr"> port:</span> <span class="hljs-number">8080</span>
|
|||
|
<span class="hljs-attr"> initialDelaySeconds:</span> <span class="hljs-number">15</span>
|
|||
|
<span class="hljs-attr"> periodSeconds:</span> <span class="hljs-number">20</span>
|
|||
|
</code></pre>
|
|||
|
<p>如您所见,TCP检查的配置与HTTP检查非常相似。 此示例同时使用了readiness和liveness probe。 容器启动后5秒钟,kubelet将发送第一个readiness probe。 这将尝试连接到端口8080上的goproxy容器。如果探测成功,则该pod将被标记为就绪。Kubelet将每隔10秒钟执行一次该检查。</p>
|
|||
|
<p>除了readiness probe之外,该配置还包括liveness probe。 容器启动15秒后,kubelet将运行第一个liveness probe。 就像readiness probe一样,这将尝试连接到goproxy容器上的8080端口。如果liveness probe失败,容器将重新启动。</p>
|
|||
|
<h2 id="使用命名的端口">使用命名的端口</h2>
|
|||
|
<p>可以使用命名的ContainerPort作为HTTP或TCP liveness检查:</p>
|
|||
|
<pre><code class="lang-yaml"><span class="hljs-attr">ports:</span>
|
|||
|
<span class="hljs-attr">- name:</span> liveness-port
|
|||
|
<span class="hljs-attr"> containerPort:</span> <span class="hljs-number">8080</span>
|
|||
|
<span class="hljs-attr"> hostPort:</span> <span class="hljs-number">8080</span>
|
|||
|
|
|||
|
<span class="hljs-attr">livenessProbe:</span>
|
|||
|
<span class="hljs-attr"> httpGet:</span>
|
|||
|
<span class="hljs-attr"> path:</span> /healthz
|
|||
|
<span class="hljs-attr"> port:</span> liveness-port
|
|||
|
</code></pre>
|
|||
|
<h2 id="定义readiness探针">定义readiness探针</h2>
|
|||
|
<p>有时,应用程序暂时无法对外部流量提供服务。 例如,应用程序可能需要在启动期间加载大量数据或配置文件。 在这种情况下,你不想杀死应用程序,但你也不想发送请求。 Kubernetes提供了readiness probe来检测和减轻这些情况。 Pod中的容器可以报告自己还没有准备,不能处理Kubernetes服务发送过来的流量。</p>
|
|||
|
<p>Readiness probe的配置跟liveness probe很像。唯一的不同是使用 <code>readinessProbe</code>而不是<code>livenessProbe</code>。</p>
|
|||
|
<pre><code class="lang-yaml"><span class="hljs-attr">readinessProbe:</span>
|
|||
|
<span class="hljs-attr"> exec:</span>
|
|||
|
<span class="hljs-attr"> command:</span>
|
|||
|
<span class="hljs-bullet"> -</span> cat
|
|||
|
<span class="hljs-bullet"> -</span> /tmp/healthy
|
|||
|
<span class="hljs-attr"> initialDelaySeconds:</span> <span class="hljs-number">5</span>
|
|||
|
<span class="hljs-attr"> periodSeconds:</span> <span class="hljs-number">5</span>
|
|||
|
</code></pre>
|
|||
|
<p>Readiness probe的HTTP和TCP的探测器配置跟liveness probe一样。</p>
|
|||
|
<p>Readiness和livenss probe可以并行用于同一容器。 使用两者可以确保流量无法到达未准备好的容器,并且容器在失败时重新启动。</p>
|
|||
|
<h2 id="配置probe">配置Probe</h2>
|
|||
|
<p><a href="https://kubernetes.io/docs/api-reference/v1.6/#probe-v1-core" target="_blank">Probe</a>中有很多精确和详细的配置,通过它们你能准确的控制liveness和readiness检查:</p>
|
|||
|
<ul>
|
|||
|
<li><code>initialDelaySeconds</code>:容器启动后第一次执行探测是需要等待多少秒。</li>
|
|||
|
<li><code>periodSeconds</code>:执行探测的频率。默认是10秒,最小1秒。</li>
|
|||
|
<li><code>timeoutSeconds</code>:探测超时时间。默认1秒,最小1秒。</li>
|
|||
|
<li><code>successThreshold</code>:探测失败后,最少连续探测成功多少次才被认定为成功。默认是1。对于liveness必须是1。最小值是1。 </li>
|
|||
|
<li><code>failureThreshold</code>:探测成功后,最少连续探测失败多少次才被认定为失败。默认是3。最小值是1。</li>
|
|||
|
</ul>
|
|||
|
<p><a href="https://kubernetes.io/docs/api-reference/v1.6/#httpgetaction-v1-core" target="_blank">HTTP probe</a>中可以给 <code>httpGet</code>设置其他配置项:</p>
|
|||
|
<ul>
|
|||
|
<li><code>host</code>:连接的主机名,默认连接到pod的IP。你可能想在http header中设置"Host"而不是使用IP。</li>
|
|||
|
<li><code>scheme</code>:连接使用的schema,默认HTTP。</li>
|
|||
|
<li><code>path</code>: 访问的HTTP server的path。</li>
|
|||
|
<li><code>httpHeaders</code>:自定义请求的header。HTTP运行重复的header。</li>
|
|||
|
<li><code>port</code>:访问的容器的端口名字或者端口号。端口号必须介于1和65525之间。</li>
|
|||
|
</ul>
|
|||
|
<p>对于HTTP探测器,kubelet向指定的路径和端口发送HTTP请求以执行检查。 Kubelet将probe发送到容器的IP地址,除非地址被<code>httpGet</code>中的可选<code>host</code>字段覆盖。 在大多数情况下,你不想设置主机字段。 有一种情况下你可以设置它。 假设容器在127.0.0.1上侦听,并且Pod的<code>hostNetwork</code>字段为true。 然后,在<code>httpGet</code>下的<code>host</code>应该设置为127.0.0.1。 如果你的pod依赖于虚拟主机,这可能是更常见的情况,你不应该是用<code>host</code>,而是应该在<code>httpHeaders</code>中设置<code>Host</code>头。</p>
|
|||
|
<h2 id="参考">参考</h2>
|
|||
|
<ul>
|
|||
|
<li>关于 <a href="../docs/concepts/workloads/pods/pod-lifecycle#container-probes">Container Probes</a> 的更多信息 </li>
|
|||
|
</ul>
|
|||
|
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright">for GitBook</span>           <span class="page-footer-ex-footer-update">update
|
|||
|
2017-07-23 18:57:26
|
|||
|
</span></footer>
|
|||
|
|
|||
|
</section>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="search-results">
|
|||
|
<div class="has-results">
|
|||
|
|
|||
|
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
|||
|
<ul class="search-results-list"></ul>
|
|||
|
|
|||
|
</div>
|
|||
|
<div class="no-results">
|
|||
|
|
|||
|
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
</div>
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<a href="resource-configuration.html" class="navigation navigation-prev " aria-label="Previous page: 3.1 资源配置">
|
|||
|
<i class="fa fa-angle-left"></i>
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
<a href="configure-pod-service-account.html" class="navigation navigation-next " aria-label="Next page: 3.1.2 配置Pod的Service Account">
|
|||
|
<i class="fa fa-angle-right"></i>
|
|||
|
</a>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</div>
|
|||
|
|
|||
|
<script>
|
|||
|
var gitbook = gitbook || [];
|
|||
|
gitbook.push(function() {
|
|||
|
gitbook.page.hasChanged({"page":{"title":"3.1.1 配置Pod的liveness和readiness探针","level":"1.3.1.1","depth":3,"next":{"title":"3.1.2 配置Pod的Service Account","level":"1.3.1.2","depth":3,"path":"guide/configure-pod-service-account.md","ref":"guide/configure-pod-service-account.md","articles":[]},"previous":{"title":"3.1 资源配置","level":"1.3.1","depth":2,"path":"guide/resource-configuration.md","ref":"guide/resource-configuration.md","articles":[{"title":"3.1.1 配置Pod的liveness和readiness探针","level":"1.3.1.1","depth":3,"path":"guide/configure-liveness-readiness-probes.md","ref":"guide/configure-liveness-readiness-probes.md","articles":[]},{"title":"3.1.2 配置Pod的Service Account","level":"1.3.1.2","depth":3,"path":"guide/configure-pod-service-account.md","ref":"guide/configure-pod-service-account.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["github","codesnippet","splitter","page-toc-button","image-captions","page-footer-ex","editlink","-lunr","-search","search-plus","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"github":{"url":"https://github.com/rootsongjc/kubernetes-handbook"},"editlink":{"label":"编辑本页","multilingual":false,"base":"https://github.com/rootsongjc/kubernetes-handbook/blob/master/"},"livereload":{},"page-footer-ex":{"copyright":"for GitBook","update_format":"YYYY-MM-DD HH:mm:ss","update_label":"update"},"splitter":{},"codesnippet":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"page-toc-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"search-plus":{},"image-captions":{"variable_name":"_pictures"}},"page-footer-ex":{"copyright":"Jimmy Song","update_label":"最后更新:","update_format":"YYYY-MM-DD HH:mm:ss"},"theme":"default","author":"Jimmy Song","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{"_pictures":[{"backlink":"index.html#fig1.1.1","level":"1.1","list_caption":"Figure: wercker status","alt":"wercker status","nro":1,"url":"https://app.wercker.com/status/b8b69e593784e17ddcfd1286adfd8f3c/s/master","index":1,"caption_template":"Figure: _CAPTION_","label":"wercker status","attributes":{},"title":"wercker status","skip":false,"key":"1.1.1"},{"backlink":"concepts/index.html#fig1.2.1","level":"1.2","list_caption":"Figure: Borg架构","alt":"Borg架构","nro":2,"url":"../images/borg.png","index":1,"caption_template":"Figure: _CAPTION_","label":"Borg架构","attributes":{},"skip":false,"key":"1.2.1"},{"backlink":"concepts/index.html#fig1.2.2","level":"1.2","list_caption":"Figure: Kubernetes架构","alt":"Kubernetes架构","nro":3,"url":"../images/architecture.png","index":2,"caption_template":"Figure: _CAPTION_","label":"Kubernetes架构","attributes":{},"skip":false,"key":"1.2.2"},{"backlink":"concepts/index.html#fig1.2.3","level":"1.2","list_caption":"Figure: kubernetes整体架构示意图","alt":"kubernetes整体架构示意图","nro":4,"url":"../images/kubernetes-whole-arch.png","index":3,"caption_template":"Figure: _CAPTION_","label":"kubernetes整体架构示意图","attributes":{},"skip":false,"key":"1.2.3"},{"backlink":"concepts/index.html#fig1.2.4","level":"1.2","list_caption":"Figure: Kubernetes master架构示意图","alt":"Kubernetes master架构示意图","nro":5,"url":"../images/kubernetes-master-arch.png","index":4,"caption_template":"Figure: _CAPTION_","label":"Kubernetes master架构<E69EB6><E69E84>
|
|||
|
});
|
|||
|
</script>
|
|||
|
</div>
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook.js"></script>
|
|||
|
<script src="../gitbook/theme.js"></script>
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-editlink/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-search-plus/search.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
|||
|
|
|||
|
|
|||
|
|
|||
|
</body>
|
|||
|
</html>
|
|||
|
|