1554 lines
122 KiB
HTML
1554 lines
122 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>2.1 设计理念 · 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="objects.html" />
|
||
|
|
||
|
|
||
|
<link rel="prev" href="./" />
|
||
|
|
||
|
|
||
|
</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="./">
|
||
|
|
||
|
<a href="./">
|
||
|
|
||
|
|
||
|
2. 概念原理
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter active" data-level="1.2.1" data-path="concepts.html">
|
||
|
|
||
|
<a href="concepts.html">
|
||
|
|
||
|
|
||
|
2.1 设计理念
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2" data-path="objects.html">
|
||
|
|
||
|
<a href="objects.html">
|
||
|
|
||
|
|
||
|
2.2 主要概念
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.1" data-path="pod-overview.html">
|
||
|
|
||
|
<a href="pod-overview.html">
|
||
|
|
||
|
|
||
|
2.2.1 Pod
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.1.1" data-path="pod.html">
|
||
|
|
||
|
<a href="pod.html">
|
||
|
|
||
|
|
||
|
2.2.1.1 Pod解析
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.2" data-path="node.html">
|
||
|
|
||
|
<a href="node.html">
|
||
|
|
||
|
|
||
|
2.2.2 Node
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.3" data-path="namespace.html">
|
||
|
|
||
|
<a href="namespace.html">
|
||
|
|
||
|
|
||
|
2.2.3 Namespace
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.4" data-path="service.html">
|
||
|
|
||
|
<a href="service.html">
|
||
|
|
||
|
|
||
|
2.2.4 Service
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.5" data-path="volume.html">
|
||
|
|
||
|
<a href="volume.html">
|
||
|
|
||
|
|
||
|
2.2.5 Volume和Persistent Volume
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.6" data-path="deployment.html">
|
||
|
|
||
|
<a href="deployment.html">
|
||
|
|
||
|
|
||
|
2.2.6 Deployment
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.7" data-path="secret.html">
|
||
|
|
||
|
<a href="secret.html">
|
||
|
|
||
|
|
||
|
2.2.7 Secret
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.8" data-path="statefulset.html">
|
||
|
|
||
|
<a href="statefulset.html">
|
||
|
|
||
|
|
||
|
2.2.8 StatefulSet
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.9" data-path="daemonset.html">
|
||
|
|
||
|
<a href="daemonset.html">
|
||
|
|
||
|
|
||
|
2.2.9 DaemonSet
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.10" data-path="serviceaccount.html">
|
||
|
|
||
|
<a href="serviceaccount.html">
|
||
|
|
||
|
|
||
|
2.2.10 ServiceAccount
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.11" data-path="replicaset.html">
|
||
|
|
||
|
<a href="replicaset.html">
|
||
|
|
||
|
|
||
|
2.2.11 ReplicationController和ReplicaSet
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.12" data-path="job.html">
|
||
|
|
||
|
<a href="job.html">
|
||
|
|
||
|
|
||
|
2.2.12 Job
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.13" data-path="cronjob.html">
|
||
|
|
||
|
<a href="cronjob.html">
|
||
|
|
||
|
|
||
|
2.2.13 CronJob
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.14" data-path="ingress.html">
|
||
|
|
||
|
<a href="ingress.html">
|
||
|
|
||
|
|
||
|
2.2.14 Ingress
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.15" data-path="configmap.html">
|
||
|
|
||
|
<a href="configmap.html">
|
||
|
|
||
|
|
||
|
2.2.15 ConfigMap
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.16" data-path="horizontal-pod-autoscaling.html">
|
||
|
|
||
|
<a href="horizontal-pod-autoscaling.html">
|
||
|
|
||
|
|
||
|
2.2.16 Horizontal Pod Autoscaling
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.2.2.17" data-path="label.html">
|
||
|
|
||
|
<a href="label.html">
|
||
|
|
||
|
|
||
|
2.2.17 Label
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3" data-path="../guide/">
|
||
|
|
||
|
<a href="../guide/">
|
||
|
|
||
|
|
||
|
3. 用户指南
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.1" data-path="../guide/resource-configuration.html">
|
||
|
|
||
|
<a href="../guide/resource-configuration.html">
|
||
|
|
||
|
|
||
|
3.1 资源配置
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.1.1" data-path="../guide/configure-liveness-readiness-probes.html">
|
||
|
|
||
|
<a href="../guide/configure-liveness-readiness-probes.html">
|
||
|
|
||
|
|
||
|
3.1.1 配置Pod的liveness和readiness探针
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.1.2" data-path="../guide/configure-pod-service-account.html">
|
||
|
|
||
|
<a href="../guide/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="../guide/command-usage.html">
|
||
|
|
||
|
<a href="../guide/command-usage.html">
|
||
|
|
||
|
|
||
|
3.2 命令使用
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.2.1" data-path="../guide/using-kubectl.html">
|
||
|
|
||
|
<a href="../guide/using-kubectl.html">
|
||
|
|
||
|
|
||
|
3.2.1 使用kubectl
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.3" data-path="../guide/cluster-management.html">
|
||
|
|
||
|
<a href="../guide/cluster-management.html">
|
||
|
|
||
|
|
||
|
3.3 集群管理
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.3.1" data-path="../guide/managing-tls-in-a-cluster.html">
|
||
|
|
||
|
<a href="../guide/managing-tls-in-a-cluster.html">
|
||
|
|
||
|
|
||
|
3.3.1 管理集群中的TLS
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.4" data-path="../guide/access-kubernetes-cluster.html">
|
||
|
|
||
|
<a href="../guide/access-kubernetes-cluster.html">
|
||
|
|
||
|
|
||
|
3.4 访问 Kubernetes 集群
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.4.1" data-path="../guide/access-cluster.html">
|
||
|
|
||
|
<a href="../guide/access-cluster.html">
|
||
|
|
||
|
|
||
|
3.4.1 访问集群
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.4.2" data-path="../guide/authenticate-across-clusters-kubeconfig.html">
|
||
|
|
||
|
<a href="../guide/authenticate-across-clusters-kubeconfig.html">
|
||
|
|
||
|
|
||
|
3.4.2 使用 kubeconfig 文件配置跨集群认证
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.4.3" data-path="../guide/connecting-to-applications-port-forward.html">
|
||
|
|
||
|
<a href="../guide/connecting-to-applications-port-forward.html">
|
||
|
|
||
|
|
||
|
3.4.3 通过端口转发访问集群中的应用程序
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.4.4" data-path="../guide/service-access-application-cluster.html">
|
||
|
|
||
|
<a href="../guide/service-access-application-cluster.html">
|
||
|
|
||
|
|
||
|
3.4.4 使用 service 访问群集中的应用程序
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</li>
|
||
|
|
||
|
|
||
|
</ul>
|
||
|
|
||
|
</li>
|
||
|
|
||
|
<li class="chapter " data-level="1.3.5" data-path="../guide/application-development-deployment-flow.html">
|
||
|
|
||
|
<a href="../guide/application-development-deployment-flow.html">
|
||
|
|
||
|
|
||
|
3.5 在kubernetes中开发部署应用
|
||
|
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
<ul class="articles">
|
||
|
|
||
|
|
||
|
<li class="chapter " data-level="1.3.5.1" data-path="../guide/deploy-applications-in-kubernetes.html">
|
||
|
|
||
|
<a href="../guide/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=".." >2.1 设计理念</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="kubernetes的设计理念">Kubernetes的设计理念</h1>
|
||
|
<h3 id="kubernetes设计理念与分布式系统">Kubernetes设计理念与分布式系统</h3>
|
||
|
<p>分析和理解Kubernetes的设计理念可以使我们更深入地了解Kubernetes系统,更好地利用它管理分布式部署的云原生应用,另一方面也可以让我们借鉴其在分布式系统设计方面的经验。</p>
|
||
|
<h3 id="分层架构">分层架构</h3>
|
||
|
<p>Kubernetes设计理念和功能其实就是一个类似Linux的分层架构,如下图所示</p>
|
||
|
<figure id="fig1.2.1.1"><img src="../images/kubernetes-layers-arch.jpg" alt="分层架构示意图"><figcaption>Figure: 分层架构示意图</figcaption></figure>
|
||
|
<ul>
|
||
|
<li>核心层:Kubernetes最核心的功能,对外提供API构建高层的应用,最内提供插件式应用执行环境</li>
|
||
|
<li>应用层:部署(无状态应用、有状态应用、批处理任务、集群应用等)和路由(服务发现、DNS解析等)</li>
|
||
|
<li>管理层:系统度量(如基础设施、容器和网络的度量),自动化(如自动扩展、动态Provision等)以及策略管理(RBAC、Quota、PSP、NetworkPolicy等)</li>
|
||
|
<li>接口层:kubectl命令行工具、客户端SDK以及集群联邦</li>
|
||
|
<li>生态系统:在接口层之上的庞大容器集群管理调度的生态系统,可以划分为两个范畴<ul>
|
||
|
<li>Kubernetes外部:日志、监控、配置管理、CI、CD、Workflow、FaaS、OTS应用、ChatOps等</li>
|
||
|
<li>Kubernetes内部:CRI、CNI、CVI、镜像仓库、Cloud Provider、集群自身的配置和管理等</li>
|
||
|
</ul>
|
||
|
</li>
|
||
|
</ul>
|
||
|
<h3 id="api设计原则">API设计原则</h3>
|
||
|
<p>对于云计算系统,系统API实际上处于系统设计的统领地位,正如本文前面所说,kubernetes集群系统每支持一项新功能,引入一项新技术,一定会新引入对应的API对象,支持对该功能的管理操作,理解掌握的API,就好比抓住了kubernetes系统的牛鼻子。Kubernetes系统API的设计有以下几条原则:</p>
|
||
|
<ol>
|
||
|
<li><strong>所有API应该是声明式的</strong>。正如前文所说,声明式的操作,相对于命令式操作,对于重复操作的效果是稳定的,这对于容易出现数据丢失或重复的分布式环境来说是很重要的。另外,声明式操作更容易被用户使用,可以使系统向用户隐藏实现的细节,隐藏实现的细节的同时,也就保留了系统未来持续优化的可能性。此外,声明式的API,同时隐含了所有的API对象都是名词性质的,例如Service、Volume这些API都是名词,这些名词描述了用户所期望得到的一个目标分布式对象。 </li>
|
||
|
<li><strong>API对象是彼此互补而且可组合的</strong>。这里面实际是鼓励API对象尽量实现面向对象设计时的要求,即“高内聚,松耦合”,对业务相关的概念有一个合适的分解,提高分解出来的对象的可重用性。事实上,Kubernetes这种分布式系统管理平台,也是一种业务系统,只不过它的业务就是调度和管理容器服务。 </li>
|
||
|
<li><strong>高层API以操作意图为基础设计</strong>。如何能够设计好API,跟如何能用面向对象的方法设计好应用系统有相通的地方,高层设计一定是从业务出发,而不是过早的从技术实现出发。因此,针对Kubernetes的高层API设计,一定是以Kubernetes的业务为基础出发,也就是以系统调度管理容器的操作意图为基础设计。 </li>
|
||
|
<li><strong>低层API根据高层API的控制需要设计</strong>。设计实现低层API的目的,是为了被高层API使用,考虑减少冗余、提高重用性的目的,低层API的设计也要以需求为基础,要尽量抵抗受技术实现影响的诱惑。 </li>
|
||
|
<li><strong>尽量避免简单封装,不要有在外部API无法显式知道的内部隐藏的机制</strong>。简单的封装,实际没有提供新的功能,反而增加了对所封装API的依赖性。内部隐藏的机制也是非常不利于系统维护的设计方式,例如PetSet和ReplicaSet,本来就是两种Pod集合,那么Kubernetes就用不同API对象来定义它们,而不会说只用同一个ReplicaSet,内部通过特殊的算法再来区分这个ReplicaSet是有状态的还是无状态。 </li>
|
||
|
<li><strong>API操作复杂度与对象数量成正比</strong>。这一条主要是从系统性能角度考虑,要保证整个系统随着系统规模的扩大,性能不会迅速变慢到无法使用,那么最低的限定就是API的操作复杂度不能超过O(N),N是对象的数量,否则系统就不具备水平伸缩性了。 </li>
|
||
|
<li><strong>API对象状态不能依赖于网络连接状态</strong>。由于众所周知,在分布式环境下,网络连接断开是经常发生的事情,因此要保证API对象状态能应对网络的不稳定,API对象的状态就不能依赖于网络连接状态。 </li>
|
||
|
<li><strong>尽量避免让操作机制依赖于全局状态,因为在分布式系统中要保证全局状态的同步是非常困难的</strong>。</li>
|
||
|
</ol>
|
||
|
<h3 id="控制机制设计原则">控制机制设计原则</h3>
|
||
|
<ul>
|
||
|
<li><strong>控制逻辑应该只依赖于当前状态</strong>。这是为了保证分布式系统的稳定可靠,对于经常出现局部错误的分布式系统,如果控制逻辑只依赖当前状态,那么就非常容易将一个暂时出现故障的系统恢复到正常状态,因为你只要将该系统重置到某个稳定状态,就可以自信的知道系统的所有控制逻辑会开始按照正常方式运行。 </li>
|
||
|
<li><strong>假设任何错误的可能,并做容错处理</strong>。在一个分布式系统中出现局部和临时错误是大概率事件。错误可能来自于物理系统故障,外部系统故障也可能来自于系统自身的代码错误,依靠自己实现的代码不会出错来保证系统稳定其实也是难以实现的,因此要设计对任何可能错误的容错处理。 </li>
|
||
|
<li><strong>尽量避免复杂状态机,控制逻辑不要依赖无法监控的内部状态</strong>。因为分布式系统各个子系统都是不能严格通过程序内部保持同步的,所以如果两个子系统的控制逻辑如果互相有影响,那么子系统就一定要能互相访问到影响控制逻辑的状态,否则,就等同于系统里存在不确定的控制逻辑。 </li>
|
||
|
<li><strong>假设任何操作都可能被任何操作对象拒绝,甚至被错误解析</strong>。由于分布式系统的复杂性以及各子系统的相对独立性,不同子系统经常来自不同的开发团队,所以不能奢望任何操作被另一个子系统以正确的方式处理,要保证出现错误的时候,操作级别的错误不会影响到系统稳定性。 </li>
|
||
|
<li><strong>每个模块都可以在出错后自动恢复</strong>。由于分布式系统中无法保证系统各个模块是始终连接的,因此每个模块要有自我修复的能力,保证不会因为连接不到其他模块而自我崩溃。 </li>
|
||
|
<li><strong>每个模块都可以在必要时优雅地降级服务</strong>。所谓优雅地降级服务,是对系统鲁棒性的要求,即要求在设计实现模块时划分清楚基本功能和高级功能,保证基本功能不会依赖高级功能,这样同时就保证了不会因为高级功能出现故障而导致整个模块崩溃。根据这种理念实现的系统,也更容易快速地增加新的高级功能,以为不必担心引入高级功能影响原有的基本功能。</li>
|
||
|
</ul>
|
||
|
<h2 id="kubernetes的核心技术概念和api对象">Kubernetes的核心技术概念和API对象</h2>
|
||
|
<p>API对象是Kubernetes集群中的管理操作单元。Kubernetes集群系统每支持一项新功能,引入一项新技术,一定会新引入对应的API对象,支持对该功能的管理操作。例如副本集Replica Set对应的API对象是RS。</p>
|
||
|
<p>每个API对象都有3大类属性:元数据metadata、规范spec和状态status。元数据是用来标识API对象的,每个对象都至少有3个元数据:namespace,name和uid;除此以外还有各种各样的标签labels用来标识和匹配不同的对象,例如用户可以用标签env来标识区分不同的服务部署环境,分别用env=dev、env=testing、env=production来标识开发、测试、生产的不同服务。规范描述了用户期望Kubernetes集群中的分布式系统达到的理想状态(Desired State),例如用户可以通过复制控制器Replication Controller设置期望的Pod副本数为3;status描述了系统实际当前达到的状态(Status),例如系统当前实际的Pod副本数为2;那么复制控制器当前的程序逻辑就是自动启动新的Pod,争取达到副本数为3。</p>
|
||
|
<p>Kubernetes中所有的配置都是通过API对象的spec去设置的,也就是用户通过配置系统的理想状态来改变系统,这是Kubernetes重要设计理念之一,即所有的操作都是声明式(Declarative)的而不是命令式(Imperative)的。声明式操作在分布式系统中的好处是稳定,不怕丢操作或运行多次,例如设置副本数为3的操作运行多次也还是一个结果,而给副本数加1的操作就不是声明式的,运行多次结果就错了。</p>
|
||
|
<h3 id="pod">Pod</h3>
|
||
|
<p>Kubernetes有很多技术概念,同时对应很多API对象,最重要的也是最基础的是Pod。Pod是在Kubernetes集群中运行部署应用或服务的最小单元,它是可以支持多容器的。Pod的设计理念是支持多个容器在一个Pod中共享网络地址和文件系统,可以通过进程间通信和文件共享这种简单高效的方式组合完成服务。Pod对多容器的支持是K8最基础的设计理念。比如你运行一个操作系统发行版的软件仓库,一个Nginx容器用来发布软件,另一个容器专门用来从源仓库做同步,这两个容器的镜像不太可能是一个团队开发的,但是他们一块儿工作才能提供一个微服务;这种情况下,不同的团队各自开发构建自己的容器镜像,在部署的时候组合成一个微服务对外提供服务。</p>
|
||
|
<p>Pod是Kubernetes集群中所有业务类型的基础,可以看作运行在K8集群中的小机器人,不同类型的业务就需要不同类型的小机器人去执行。目前Kubernetes中的业务主要可以分为长期伺服型(long-running)、批处理型(batch)、节点后台支撑型(node-daemon)和有状态应用型(stateful application);分别对应的小机器人控制器为Deployment、Job、DaemonSet和PetSet,本文后面会一一介绍。</p>
|
||
|
<h3 id="副本控制器(replication-controller,rc)">副本控制器(Replication Controller,RC)</h3>
|
||
|
<p>RC是Kubernetes集群中最早的保证Pod高可用的API对象。通过监控运行中的Pod来保证集群中运行指定数目的Pod副本。指定的数目可以是多个也可以是1个;少于指定数目,RC就会启动运行新的Pod副本;多于指定数目,RC就会杀死多余的Pod副本。即使在指定数目为1的情况下,通过RC运行Pod也比直接运行Pod更明智,因为RC也可以发挥它高可用的能力,保证永远有1个Pod在运行。RC是Kubernetes较早期的技术概念,只适用于长期伺服型的业务类型,比如控制小机器人提供高可用的Web服务。</p>
|
||
|
<h3 id="副本集(replica-set,rs)">副本集(Replica Set,RS)</h3>
|
||
|
<p>RS是新一代RC,提供同样的高可用能力,区别主要在于RS后来居上,能支持更多种类的匹配模式。副本集对象一般不单独使用,而是作为Deployment的理想状态参数使用。</p>
|
||
|
<h3 id="部署(deployment)">部署(Deployment)</h3>
|
||
|
<p>部署表示用户对Kubernetes集群的一次更新操作。部署是一个比RS应用模式更广的API对象,可以是创建一个新的服务,更新一个新的服务,也可以是滚动升级一个服务。滚动升级一个服务,实际是创建一个新的RS,然后逐渐将新RS中副本数增加到理想状态,将旧RS中的副本数减小到0的复合操作;这样一个复合操作用一个RS是不太好描述的,所以用一个更通用的Deployment来描述。以Kubernetes的发展方向,未来对所有长期伺服型的的业务的管理,都会通过Deployment来管理。</p>
|
||
|
<h3 id="服务(service)">服务(Service)</h3>
|
||
|
<p>RC、RS和Deployment只是保证了支撑服务的微服务Pod的数量,但是没有解决如何访问这些服务的问题。一个Pod只是一个运行服务的实例,随时可能在一个节点上停止,在另一个节点以一个新的IP启动一个新的Pod,因此不能以确定的IP和端口号提供服务。要稳定地提供服务需要服务发现和负载均衡能力。服务发现完成的工作,是针对客户端访问的服务,找到对应的的后端服务实例。在K8集群中,客户端需要访问的服务就是Service对象。每个Service会对应一个集群内部有效的虚拟IP,集群内部通过虚拟IP访问一个服务。在Kubernetes集群中微服务的负载均衡是由Kube-proxy实现的。Kube-proxy是Kubernetes集群内部的负载均衡器。它是一个分布式代理服务器,在Kubernetes的每个节点上都有一个;这一设计体现了它的伸缩性优势,需要访问服务的节点越多,提供负载均衡能力的Kube-proxy就越多,高可用节点也随之增多。与之相比,我们平时在服务器端做个反向代理做负载均衡,还要进一步解决反向代理的负载均衡和高可用问题。</p>
|
||
|
<h3 id="任务(job)">任务(Job)</h3>
|
||
|
<p>Job是Kubernetes用来控制批处理型任务的API对象。批处理业务与长期伺服业务的主要区别是批处理业务的运行有头有尾,而长期伺服业务在用户不停止的情况下永远运行。Job管理的Pod根据用户的设置把任务成功完成就自动退出了。成功完成的标志根据不同的spec.completions策略而不同:单Pod型任务有一个Pod成功就标志完成;定数成功型任务保证有N个任务全部成功;工作队列型任务根据应用确认的全局成功而标志成功。</p>
|
||
|
<h3 id="后台支撑服务集(daemonset)">后台支撑服务集(DaemonSet)</h3>
|
||
|
<p>长期伺服型和批处理型服务的核心在业务应用,可能有些节点运行多个同类业务的Pod,有些节点上又没有这类Pod运行;而后台支撑型服务的核心关注点在Kubernetes集群中的节点(物理机或虚拟机),要保证每个节点上都有一个此类Pod运行。节点可能是所有集群节点也可能是通过nodeSelector选定的一些特定节点。典型的后台支撑型服务包括,存储,日志和监控等在每个节点上支持Kubernetes集群运行的服务。</p>
|
||
|
<h3 id="有状态服务集(petset)">有状态服务集(PetSet)</h3>
|
||
|
<p>Kubernetes在1.3版本里发布了Alpha版的PetSet功能。在云原生应用的体系里,有下面两组近义词;第一组是无状态(stateless)、牲畜(cattle)、无名(nameless)、可丢弃(disposable);第二组是有状态(stateful)、宠物(pet)、有名(having name)、不可丢弃(non-disposable)。RC和RS主要是控制提供无状态服务的,其所控制的Pod的名字是随机设置的,一个Pod出故障了就被丢弃掉,在另一个地方重启一个新的Pod,名字变了、名字和启动在哪儿都不重要,重要的只是Pod总数;而PetSet是用来控制有状态服务,PetSet中的每个Pod的名字都是事先确定的,不能更改。PetSet中Pod的名字的作用,并不是《千与千寻》的人性原因,而是关联与该Pod对应的状态。</p>
|
||
|
<p>对于RC和RS中的Pod,一般不挂载存储或者挂载共享存储,保存的是所有Pod共享的状态,Pod像牲畜一样没有分别(这似乎也确实意味着失去了人性特征);对于PetSet中的Pod,每个Pod挂载自己独立的存储,如果一个Pod出现故障,从其他节点启动一个同样名字的Pod,要挂在上原来Pod的存储继续以它的状态提供服务。</p>
|
||
|
<p>适合于PetSet的业务包括数据库服务MySQL和PostgreSQL,集群化管理服务Zookeeper、etcd等有状态服务。PetSet的另一种典型应用场景是作为一种比普通容器更稳定可靠的模拟虚拟机的机制。传统的虚拟机正是一种有状态的宠物,运维人员需要不断地维护它,容器刚开始流行时,我们用容器来模拟虚拟机使用,所有状态都保存在容器里,而这已被证明是非常不安全、不可靠的。使用PetSet,Pod仍然可以通过漂移到不同节点提供高可用,而存储也可以通过外挂的存储来提供高可靠性,PetSet做的只是将确定的Pod与确定的存储关联起来保证状态的连续性。PetSet还只在Alpha阶段,后面的设计如何演变,我们还要继续观察。</p>
|
||
|
<h3 id="集群联邦(federation)">集群联邦(Federation)</h3>
|
||
|
<p>Kubernetes在1.3版本里发布了beta版的Federation功能。在云计算环境中,服务的作用距离范围从近到远一般可以有:同主机(Host,Node)、跨主机同可用区(Available Zone)、跨可用区同地区(Region)、跨地区同服务商(Cloud Service Provider)、跨云平台。Kubernetes的设计定位是单一集群在同一个地域内,因为同一个地区的网络性能才能满足Kubernetes的调度和计算存储连接要求。而联合集群服务就是为提供跨Region跨服务商Kubernetes集群服务而设计的。</p>
|
||
|
<p>每个Kubernetes Federation有自己的分布式存储、API Server和Controller Manager。用户可以通过Federation的API Server注册该Federation的成员Kubernetes Cluster。当用户通过Federation的API Server创建、更改API对象时,Federation API Server会在自己所有注册的子Kubernetes Cluster都创建一份对应的API对象。在提供业务请求服务时,Kubernetes Federation会先在自己的各个子Cluster之间做负载均衡,而对于发送到某个具体Kubernetes Cluster的业务请求,会依照这个Kubernetes Cluster独立提供服务时一样的调度模式去做Kubernetes Cluster内部的负载均衡。而Cluster之间的负载均衡是通过域名服务的负载均衡来实现的。</p>
|
||
|
<p>所有的设计都尽量不影响Kubernetes Cluster现有的工作机制,这样对于每个子Kubernetes集群来说,并不需要更外层的有一个Kubernetes Federation,也就是意味着所有现有的Kubernetes代码和机制不需要因为Federation功能有任何变化。</p>
|
||
|
<h3 id="存储卷(volume)">存储卷(Volume)</h3>
|
||
|
<p>Kubernetes集群中的存储卷跟Docker的存储卷有些类似,只不过Docker的存储卷作用范围为一个容器,而Kubernetes的存储卷的生命周期和作用范围是一个Pod。每个Pod中声明的存储卷由Pod中的所有容器共享。Kubernetes支持非常多的存储卷类型,特别的,支持多种公有云平台的存储,包括AWS,Google和Azure云;支持多种分布式存储包括GlusterFS和Ceph;也支持较容易使用的主机本地目录hostPath和NFS。Kubernetes还支持使用Persistent Volume Claim即PVC这种逻辑存储,使用这种存储,使得存储的使用者可以忽略后台的实际存储技术(例如AWS,Google或GlusterFS和Ceph),而将有关存储实际技术的配置交给存储管理员通过Persistent Volume来配置。</p>
|
||
|
<h3 id="持久存储卷(persistent-volume,pv)和持久存储卷声明(persistent-volume-claim,pvc)">持久存储卷(Persistent Volume,PV)和持久存储卷声明(Persistent Volume Claim,PVC)</h3>
|
||
|
<p>PV和PVC使得Kubernetes集群具备了存储的逻辑抽象能力,使得在配置Pod的逻辑里可以忽略对实际后台存储技术的配置,而把这项配置的工作交给PV的配置者,即集群的管理者。存储的PV和PVC的这种关系,跟计算的Node和Pod的关系是非常类似的;PV和Node是资源的提供者,根据集群的基础设施变化而变化,由Kubernetes集群管理员配置;而PVC和Pod是资源的使用者,根据业务服务的需求变化而变化,有Kubernetes集群的使用者即服务的管理员来配置。</p>
|
||
|
<h3 id="节点(node)">节点(Node)</h3>
|
||
|
<p>Kubernetes集群中的计算能力由Node提供,最初Node称为服务节点Minion,后来改名为Node。Kubernetes集群中的Node也就等同于Mesos集群中的Slave节点,是所有Pod运行所在的工作主机,可以是物理机也可以是虚拟机。不论是物理机还是虚拟机,工作主机的统一特征是上面要运行kubelet管理节点上运行的容器。</p>
|
||
|
<h3 id="密钥对象(secret)">密钥对象(Secret)</h3>
|
||
|
<p>Secret是用来保存和传递密码、密钥、认证凭证这些敏感信息的对象。使用Secret的好处是可以避免把敏感信息明文写在配置文件里。在Kubernetes集群中配置和使用服务不可避免的要用到各种敏感信息实现登录、认证等功能,例如访问AWS存储的用户名密码。为了避免将类似的敏感信息明文写在所有需要使用的配置文件中,可以将这些信息存入一个Secret对象,而在配置文件中通过Secret对象引用这些敏感信息。这种方式的好处包括:意图明确,避免重复,减少暴漏机会。</p>
|
||
|
<h3 id="用户帐户(user-account)和服务帐户(service-account)">用户帐户(User Account)和服务帐户(Service Account)</h3>
|
||
|
<p>顾名思义,用户帐户为人提供账户标识,而服务账户为计算机进程和Kubernetes集群中运行的Pod提供账户标识。用户帐户和服务帐户的一个区别是作用范围;用户帐户对应的是人的身份,人的身份与服务的namespace无关,所以用户账户是跨namespace的;而服务帐户对应的是一个运行中程序的身份,与特定namespace是相关的。</p>
|
||
|
<h3 id="名字空间(namespace)">名字空间(Namespace)</h3>
|
||
|
<p>名字空间为Kubernetes集群提供虚拟的隔离作用,Kubernetes集群初始有两个名字空间,分别是默认名字空间default和系统名字空间kube-system,除此以外,管理员可以可以创建新的名字空间满足需要。</p>
|
||
|
<h3 id="rbac访问授权">RBAC访问授权</h3>
|
||
|
<p>Kubernetes在1.3版本中发布了alpha版的基于角色的访问控制(Role-based Access Control,RBAC)的授权模式。相对于基于属性的访问控制(Attribute-based Access Control,ABAC),RBAC主要是引入了角色(Role)和角色绑定(RoleBinding)的抽象概念。在ABAC中,Kubernetes集群中的访问策略只能跟用户直接关联;而在RBAC中,访问策略可以跟某个角色关联,具体的用户在跟一个或多个角色相关联。显然,RBAC像其他新功能一样,每次引入新功能,都会引入新的API对象,从而引入新的概念抽象,而这一新的概念抽象一定会使集群服务管理和使用更容易扩展和重用。</p>
|
||
|
<h2 id="总结">总结</h2>
|
||
|
<p>从Kubernetes的系统架构、技术概念和设计理念,我们可以看到Kubernetes系统最核心的两个设计理念:一个是<strong>容错性</strong>,一个是<strong>易扩展性</strong>。容错性实际是保证Kubernetes系统稳定性和安全性的基础,易扩展性是保证Kubernetes对变更友好,可以快速迭代增加新功能的基础。</p>
|
||
|
<p>按照分布式系统一致性算法Paxos发明人计算机科学家<a href="http://research.microsoft.com/users/lamport/pubs/pubs.html" target="_blank">Leslie Lamport</a>的理念,一个分布式系统有两类特性:安全性Safety和活性Liveness。安全性保证系统的稳定,保证系统不会崩溃,不会出现业务错误,不会做坏事,是严格约束的;活性使得系统可以提供功能,提高性能,增加易用性,让系统可以在用户“看到的时间内”做些好事,是尽力而为的。Kubernetes系统的设计理念正好与Lamport安全性与活性的理念不谋而合,也正是因为Kubernetes在引入功能和技术的时候,非常好地划分了安全性和活性,才可以让Kubernetes能有这么快版本迭代,快速引入像RBAC、Federation和PetSet这种新功能。</p>
|
||
|
<p>[1] <a href="http://www.infoq.com/cn/articles/kubernetes-and-cloud-native-applications-part01" target="_blank">http://www.infoq.com/cn/articles/kubernetes-and-cloud-native-applications-part01</a></p>
|
||
|
<footer class="page-footer-ex"> <span class="page-footer-ex-copyright">for GitBook</span>           <span class="page-footer-ex-footer-update">update
|
||
|
2017-07-18 20:26:32
|
||
|
</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="./" class="navigation navigation-prev " aria-label="Previous page: 2. 概念原理">
|
||
|
<i class="fa fa-angle-left"></i>
|
||
|
</a>
|
||
|
|
||
|
|
||
|
<a href="objects.html" class="navigation navigation-next " aria-label="Next page: 2.2 主要概念">
|
||
|
<i class="fa fa-angle-right"></i>
|
||
|
</a>
|
||
|
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<script>
|
||
|
var gitbook = gitbook || [];
|
||
|
gitbook.push(function() {
|
||
|
gitbook.page.hasChanged({"page":{"title":"2.1 设计理念","level":"1.2.1","depth":2,"next":{"title":"2.2 主要概念","level":"1.2.2","depth":2,"path":"concepts/objects.md","ref":"concepts/objects.md","articles":[{"title":"2.2.1 Pod","level":"1.2.2.1","depth":3,"path":"concepts/pod-overview.md","ref":"concepts/pod-overview.md","articles":[{"title":"2.2.1.1 Pod解析","level":"1.2.2.1.1","depth":4,"path":"concepts/pod.md","ref":"concepts/pod.md","articles":[]}]},{"title":"2.2.2 Node","level":"1.2.2.2","depth":3,"path":"concepts/node.md","ref":"concepts/node.md","articles":[]},{"title":"2.2.3 Namespace","level":"1.2.2.3","depth":3,"path":"concepts/namespace.md","ref":"concepts/namespace.md","articles":[]},{"title":"2.2.4 Service","level":"1.2.2.4","depth":3,"path":"concepts/service.md","ref":"concepts/service.md","articles":[]},{"title":"2.2.5 Volume和Persistent Volume","level":"1.2.2.5","depth":3,"path":"concepts/volume.md","ref":"concepts/volume.md","articles":[]},{"title":"2.2.6 Deployment","level":"1.2.2.6","depth":3,"path":"concepts/deployment.md","ref":"concepts/deployment.md","articles":[]},{"title":"2.2.7 Secret","level":"1.2.2.7","depth":3,"path":"concepts/secret.md","ref":"concepts/secret.md","articles":[]},{"title":"2.2.8 StatefulSet","level":"1.2.2.8","depth":3,"path":"concepts/statefulset.md","ref":"concepts/statefulset.md","articles":[]},{"title":"2.2.9 DaemonSet","level":"1.2.2.9","depth":3,"path":"concepts/daemonset.md","ref":"concepts/daemonset.md","articles":[]},{"title":"2.2.10 ServiceAccount","level":"1.2.2.10","depth":3,"path":"concepts/serviceaccount.md","ref":"concepts/serviceaccount.md","articles":[]},{"title":"2.2.11 ReplicationController和ReplicaSet","level":"1.2.2.11","depth":3,"path":"concepts/replicaset.md","ref":"concepts/replicaset.md","articles":[]},{"title":"2.2.12 Job","level":"1.2.2.12","depth":3,"path":"concepts/job.md","ref":"concepts/job.md","articles":[]},{"title":"2.2.13 CronJob","level":"1.2.2.13","depth":3,"path":"concepts/cronjob.md","ref":"concepts/cronjob.md","articles":[]},{"title":"2.2.14 Ingress","level":"1.2.2.14","depth":3,"path":"concepts/ingress.md","ref":"concepts/ingress.md","articles":[]},{"title":"2.2.15 ConfigMap","level":"1.2.2.15","depth":3,"path":"concepts/configmap.md","ref":"concepts/configmap.md","articles":[]},{"title":"2.2.16 Horizontal Pod Autoscaling","level":"1.2.2.16","depth":3,"path":"concepts/horizontal-pod-autoscaling.md","ref":"concepts/horizontal-pod-autoscaling.md","articles":[]},{"title":"2.2.17 Label","level":"1.2.2.17","depth":3,"path":"concepts/label.md","ref":"concepts/label.md","articles":[]}]},"previous":{"title":"2. 概念原理","level":"1.2","depth":1,"path":"concepts/index.md","ref":"concepts/index.md","articles":[{"title":"2.1 设计理念","level":"1.2.1","depth":2,"path":"concepts/concepts.md","ref":"concepts/concepts.md","articles":[]},{"title":"2.2 主要概念","level":"1.2.2","depth":2,"path":"concepts/objects.md","ref":"concepts/objects.md","articles":[{"title":"2.2.1 Pod","level":"1.2.2.1","depth":3,"path":"concepts/pod-overview.md","ref":"concepts/pod-overview.md","articles":[{"title":"2.2.1.1 Pod解析","level":"1.2.2.1.1","depth":4,"path":"concepts/pod.md","ref":"concepts/pod.md","articles":[]}]},{"title":"2.2.2 Node","level":"1.2.2.2","depth":3,"path":"concepts/node.md","ref":"concepts/node.md","articles":[]},{"title":"2.2.3 Namespace","level":"1.2.2.3","depth":3,"path":"concepts/namespace.md","ref":"concepts/namespace.md","articles":[]},{"title":"2.2.4 Service","level":"1.2.2.4","depth":3,"path":"concepts/service.md","ref":"concepts/service.md","articles":[]},{"title":"2.2.5 Volume和Persistent Volume","level":"1.2.2.5","depth":3,"path":"concepts/volume.md","ref":"concepts/volume.md","articles":[]},{"title":"2.2.6 Deployment","level":"1.2.2.6","depth":3,"path":"concepts/deployment.md","ref":"concepts/deployment.md","articles":[]},{"title":"2.2.7 Secret","level":"1.2.2.7","depth":3,"path":"concepts/secret.md","ref":"concepts/secret.md","articles":[]},{"title":"2.2.8 StatefulSet","level":"1.2.2.8","depth":3,"
|
||
|
});
|
||
|
</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>
|
||
|
|