七張圖瞭解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}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章