七张图了解Kubernetes内部的架构

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"是用于管理容器化应用程序集群的工具。在计算机领域中,此过程通常称为编排。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"用管弦乐编排比喻上面的服务编排是很恰当的,就像乐队指挥一样,"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"协调地将许多微服务组合在一起构成了应用程序。 "},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"会自动且持续地监视集群并对其组成进行调整。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"了解"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"架构对于部署和维护容器化的应用程序至关重要。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"什么是Kubernetes"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"或简称"},{"type":"codeinline","content":[{"type":"text","text":"k8s"}]},{"type":"text","text":",是一个用于自动执行应用程序部署的系统。现代应用程序分散在云,虚拟机和服务器之间。手动管理应用程序不再是可行的选择。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"K8s"}]},{"type":"text","text":"将虚拟机和物理机转换为统一的"},{"type":"codeinline","content":[{"type":"text","text":"API"}]},{"type":"text","text":"切面。然后,开发人员可以使用"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes API"}]},{"type":"text","text":"来部署,扩展和管理容器化的应用程序。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"它的体系结构还为分布式系统提供了一个灵活的框架。"},{"type":"codeinline","content":[{"type":"text","text":"K8s"}]},{"type":"text","text":"为您的应用程序自动协调扩展和故障转移,并提供部署模式。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"它有助于管理运行应用程序的容器,并确保生产环境中没有停机时间。例如,如果某个容器发生故障,则另一个容器会自动取代其位置,而最终用户根本不会注意到。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"不仅是一个编排系统。它是一组独立的,相互关联的控制过程。它的作用是在当前状态下连续工作,并朝着期望的方向移动过程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Kubernetes架构和组成"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"具有去中心化的架构,不会线性处理任务。它基于声明性模型运行并实现"},{"type":"text","marks":[{"type":"strong"}],"text":"\"所需状态\""},{"type":"text","text":"的概念。下面这些步骤说明了"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"的基本过程:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"bulletedlist","content":[{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"管理员创建应用程序的所需状态并将其放入清单文件"},{"type":"codeinline","content":[{"type":"text","text":"manifest.yml"}]},{"type":"text","text":"中。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"使用CLI或提供的用户界面将清单文件提供给"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes API Server"}]},{"type":"text","text":"。 "},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"的默认命令行工具称为"},{"type":"codeinline","content":[{"type":"text","text":"kubectl"}]},{"type":"text","text":"。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"将清单文件(描述了应用程序的期望状态)存储在称为键值存储(etcd)的数据库中。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"随后在集群内的所有相关应用程序上实现所需的状态。"}]}]},{"type":"listitem","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"持续监控集群的元素,以确保应用程序的当前状态不会与所需状态有所不同。"}]}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/96/96b71d895574faa3d35b3f6bc26ff093.png","alt":"标准kubernetes集群的架构图","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"现在,我们将探索标准"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"集群的各个组成部分,以更详细地了解该过程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"主节点"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"的主节点通过API从CLI(命令行界面)或UI(用户界面)接收输入。这些是你提供给"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"的命令。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"你可以定义想要让"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"维护的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":",副本集和"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"。例如,要使用的容器镜像,要公开的端口以及要运行的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"副本数量。还可以为该集群中运行的应用程序提供"},{"type":"text","marks":[{"type":"strong"}],"text":"\"所需状态\""},{"type":"text","text":"的参数。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/4b/4bac3c19b15b0b9c7bba8af04b722b54.png","alt":"Kubernetes主节点","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"API Server"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"API Server是"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"控制程序的前端,也是用户唯一可以直接进行交互的"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"组件,内部系统组件以及外部用户组件均通过相同的API进行通信。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"键值存储etcd"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"键值存储(也称为"},{"type":"codeinline","content":[{"type":"text","text":"etcd"}]},{"type":"text","text":")是"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"用来备份所有集群数据的数据库。它存储集群的整个配置和状态。主节点查询"},{"type":"codeinline","content":[{"type":"text","text":"etcd"}]},{"type":"text","text":"以检索节点,容器和容器的状态参数。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Controller"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"控制器的作用是从API Server获得"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"。它检查要控制的节点的当前状态,确定是否与"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"存在任何差异,并解决它们(如果有)。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Scheduler"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"调度程序会监视来自API Server的新请求,并将其分配给运行状况良好的节点。它对节点的质量进行排名,并将"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"部署到最适合的节点。如果没有合适的节点,则将"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"置于挂起状态,直到出现合适的节点。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"blockquote","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注意:最好不要在主节点上运行用户应用程序。让"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"主节点可以完全专注于管理集群。"}]}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"工作节点"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"工作节点监听API Server发送过来的新的工作分配;他们会执行分配给他们的工作,然后将结果报告给"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"主节点。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/08/0809893a947c559c9891772d9031fcde.png","alt":"Kubernetes工作节点","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Kubelet"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"kubelet"}]},{"type":"text","text":"在群集中的每个节点上运行。它是"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"内部的主要代理。通过安装"},{"type":"codeinline","content":[{"type":"text","text":"kubelet"}]},{"type":"text","text":",节点的"},{"type":"codeinline","content":[{"type":"text","text":"CPU"}]},{"type":"text","text":","},{"type":"codeinline","content":[{"type":"text","text":"RAM"}]},{"type":"text","text":"和存储成为所处集群的一部分。它监视从API Server发送来的任务,执行任务,并报告给主节点。它还会监视"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":",如果"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"不能完全正常运行,则会向控制程序报告。然后,基于该信息,主服务器可以决定如何分配任务和资源以达到"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Container Runtime"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器运行时从容器镜像库中拉取镜像,然后启动和停止容器。容器运行时由第三方软件或插件(例如Docker)担当。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Kube-proxy"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"kube-proxy"}]},{"type":"text","text":"确保每个节点都获得其IP地址,实现本地"},{"type":"codeinline","content":[{"type":"text","text":"iptables"}]},{"type":"text","text":"和规则以处理路由和流量负载均衡。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Pod"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"中,"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"是调度的最小元素。没有它,容器就不能成为集群的一部分。如果你需要扩展应用程序,则只能通过添加或删除"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"来实现。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"是"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"中一个抽象化概念,由一个或多个容器组合在一起得共享资源。根据资源的可用性,主节点会把"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"调度到特定工作节点上,并与容器运行时协调以启动容器。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/06/0686b4b7a52d20b68c7485f0f56b1104.png","alt":"Pod","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"意外无法执行任务的情况下,"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"不会尝试修复它们。相反,它会在其位置创建并启动一个新"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"。这个新"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"是原来的副本,除了DNS和IP地址都和以前的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"一样。此功能对开发人员设计应用程序的方式产生了深远的影响。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"由于"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"架构的灵活性,不再需要将应用程序绑定到"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"的特定实例。取而代之的是,需要对应用程序进行设计,以便在集群内任何位置创建的全新Pod可以无缝取代旧"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"。"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"会使用"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"来协助此过程。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Kubernetes Service"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"不是恒定的。 "},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"提供的最佳功能之一是无法正常运行的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"会自动被新的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"取代。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"但是,这些新的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"具有一组不同的IP。这可能导致处理问题,并且由于IP不再匹配,IP流失。如果无人看管,此属性将使吊舱高度不可靠。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了将稳定的IP地址和DNS名称引入到不稳定的Pod世界中,"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"引入了"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"来提供可靠的网络连接。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过控制进出"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"的流量,"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"提供了稳定的网络终结点-固定的IP,DNS和端口。有了"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":",可以添加或删除任何"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":",而不必担心基本网络信息会改变。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"Service是怎么工作的"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"通过称为标签(Label)和选择器(Selector)的键值对与"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"相关联。"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":"会自动发现带有与选择器匹配的标签的新"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"此过程无缝地将新的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"添加到"},{"type":"codeinline","content":[{"type":"text","text":"Service"}]},{"type":"text","text":",同时,从群集中删除已终止的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"例如,如果"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"定义了需要一个"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"的三个副本,而运行一个副本的节点发生故障,则当前状态将减少为两个Pod。"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"观察到所需的状态是三个"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"。然后,它会调度一个新副本来代替发生故障的"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":",并将其分配给集群中的另一个节点。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过添加或删除容器来更新或缩放应用程序时,同样适用。一旦我们更新了"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"的定义,"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"就会注意到差异并添加或删除"},{"type":"codeinline","content":[{"type":"text","text":"Pod"}]},{"type":"text","text":"以匹配清单文件"},{"type":"codeinline","content":[{"type":"text","text":"manifest.yml"}]},{"type":"text","text":"里定义的"},{"type":"text","marks":[{"type":"strong"}],"text":"所需状态"},{"type":"text","text":"。"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"控制面板记录,实现和运行后台协调循环,该循环会不断检查环境是否符合用户定义的环境要求。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"Container Deployment"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了充分了解"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"的编排方式和内容,我们需要了解一下容器部署的概念。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"传统部署"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"最初,开发人员在单个物理服务器上部署应用程序。这种部署带来的问题是。物理资源的共享意味着一个应用程序可以占用服务器的大部分处理能力,从而限制了同一台服务器上其他应用程序的性能。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/df/dff2c4aa58b232dd25ae414d4001f4bb.png","alt":"传统的部署方式","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"扩展硬件容量需要花费很长时间,增加很多成本。为了解决硬件限制,组织开始虚拟化物理机。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"虚拟化部署"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"虚拟化部署允许在单个物理服务器上创建隔离的虚拟环境,即虚拟机(VM)。该解决方案隔离了VM中的应用程序,限制了资源的使用并提高了安全性。一个应用程序不能再自由访问另一个应用程序处理的信息。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/6f/6ffa3449a083990e85c59641ce9ffec3.png","alt":"虚拟化部署","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过虚拟化部署,您可以快速扩展并分散单个物理服务器的资源,随意更新并控制硬件成本。每个VM都有其操作系统,并且可以在虚拟化硬件之上运行所有必要的系统。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"容器化部署"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器部署是创建更加灵活和高效的模型的下一步。就像虚拟机一样,容器具有单独的内存,系统文件和处理空间。但是,严格隔离不再是限制因素。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"现在,多个应用程序可以共享相同的基础操作系统。此功能使容器比成熟的VM效率更高。它们可跨越云,不同的设备以及几乎所有"},{"type":"codeinline","content":[{"type":"text","text":"OS"}]},{"type":"text","text":"发行版进行移植。"}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/12/12cf9d742c9310aa5f4ca80a1169e9d0.png","alt":"容器部署","title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"容器的结构还允许应用程序作为较小的独立部分运行。然后可以在多台计算机上动态部署和管理这些部分。复杂的结构和任务划分太复杂,无法手动管理。需要一个像"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"这样的自动化解决方案,以有效管理此过程中涉及的所有活动部件。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"总结"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"使用非常简单的模型进行操作。我们输入希望系统运行的方式–**所需状态**,"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"将所需状态与集群中的当前状态进行比较。然后,它的服务将两个状态对齐,并实现和维持所需状态。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"你现在应该对"},{"type":"codeinline","content":[{"type":"text","text":"Kubernetes"}]},{"type":"text","text":"架构有了更好的了解,可以继续学习执行创建和维护集群的实际任务。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/87/87ebbdca65e1725224560bbb59de7b94.png","alt":null,"title":null,"style":null,"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章