# k8s核心組件

[![image-1737708797625.png](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/scaled-1680-/VHfefOFyJ2w3ujxH-image-1737708797625.png)](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/VHfefOFyJ2w3ujxH-image-1737708797625.png)

[![image-1775714710761.png](https://bookstack.treemanou.com/uploads/images/gallery/2026-04/scaled-1680-/wGSVTF0PqNV9DXob-image-1775714710761.png)](https://bookstack.treemanou.com/uploads/images/gallery/2026-04/wGSVTF0PqNV9DXob-image-1775714710761.png)

**3. k8s 集群架構組件**

- **Master**（主控節點）和 **Node**（工作節點）

**(1) Master 組件**

- **apiserver**  
    集群統一入口，以 RESTful 方式，交給 etcd 存儲
- **scheduler**  
    節點調度，選擇 Node 節點應用部署
- **controller-manager**  
    處理集群中常規的後台任務，一個資源對應一個控制器
- **etcd**  
    存儲系統，用於保存集群相關的數據

**(2) Node 組件**

- **kubelet**
    
    
    - Master 排到 Node 節點代表，管理本機容器。
- **kube-proxy**
    
    
    - 提供網絡代理，負載均衡等操作。

[![image-1737710111332.png](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/scaled-1680-/9yvSvsn0UIJSvrjb-image-1737710111332.png)](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/9yvSvsn0UIJSvrjb-image-1737710111332.png)

[![image-1737712398081.png](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/scaled-1680-/xmcWqhFoJCkTOuXa-image-1737712398081.png)](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/xmcWqhFoJCkTOuXa-image-1737712398081.png)

---

**K8S 核心概念**

1. **Pod**
    
    
    - 最小部署單元
    - 一組容器的集合
    - 共享網絡
    - 生命週期是短暫的
2. **Controller**
    
    
    - 確保預期的 Pod 副本數量
    - 無狀態應用部署
    - 有狀態應用部署
    - 確保所有的 Node 運行同一個 Pod
    - 一次性任務和定時任務
3. **Service**
    
    
    - 定義一組 Pod 的訪問規則

---

如有其他需求，請隨時告訴我！

[![image-1737708872912.png](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/scaled-1680-/nPoPBQnry7LR1o2F-image-1737708872912.png)](https://bookstack.treemanou.com/uploads/images/gallery/2025-01/nPoPBQnry7LR1o2F-image-1737708872912.png)

kubectl run podtest --image=nginx

  
1\. kubectl向apiserver發送一個創建pod的請求，apiserver會將數據放到etcd存儲。

2\. Scheduler通過list-watch的方式，收到未綁定pod資源，通過自身調度算法選擇一個合適的node進行綁定，然後響應給apiserver，把信息更新到etcd中。

3\. Kubelet同樣通過list-watch的方式，收到分配到自己節點上pod，調用docker api創建容器，然後將容器狀態響應給apiserver，同時，把容器的信息、事件及狀態也通過apiserver寫入到etcd中。