# ☸️ Cheatsheet: Kubernetes căn bản: triển khai ứng dụng thật bằng kubectl

> This cheatsheet is part of the paid section. Sign in and purchase the course to view the full content.

Tra cứu nhanh cho toàn bộ khóa. Mỗi mục là một tầng của cùng một cơ chế: mô tả trạng thái mong muốn, controller kéo trạng thái thực tế về đó.

---

## Module 1: Kiến trúc và workload cốt lõi

### 1.1 Kiến trúc control plane, node và đường đi của `kubectl`

**Đường đi của một lệnh `kubectl apply`:**

```mermaid
flowchart LR
    K["⌨️<br/>kubectl"] --> API["🧠<br/>kube-apiserver"]
    API --> AUTH["🔐<br/>Authentication"]
    AUTH --> AUTHZ["🛂<br/>Authorization"]
    AUTHZ --> ADM["✅<br/>Admission"]
    ADM --> ETCD["🗄️<br/>etcd"]
    ETCD --> CTRL["🔁<br/>Controller"]
    CTRL --> SCHED["📍<br/>kube-scheduler"]
    SCHED --> KUBELET["⚙️<br/>kubelet"]
    KUBELET --> CRI["📦<br/>Container runtime"]
    CTRL --> PROXY["🔀<br/>kube-proxy"]
```

| Thành phần | Vai trò | Nơi chạy |
| --- | --- | --- |
| `kube-apiserver` | Cửa ngõ duy nhất, xử lý authn → authz → admission | Control plane |
| `etcd` | Key-value store, nguồn sự thật duy nhất | Control plane |
| `kube-scheduler` | Gán Pod vào node (filtering → scoring) | Control plane |
| `kube-controller-manager` | Chạy các controller (reconcile loop) | Control plane |
| `cloud-controller-manager` | Tích hợp cloud provider (LB, node lifecycle) | Control plane |
| `kubelet` | Agent trên node, đảm bảo container chạy đúng spec | Node |
| `kube-proxy` | Biến Service thành rules DNAT (iptables/ipvs) | Node |
| Container runtime (containerd, CRI-O) | Pull image, chạy container qua CRI | Node |

**Điểm cần nhớ:**
- Mọi thao tác đều đi qua `kube-apiserver`. Không component nào nói chuyện trực tiếp với `etcd` ngoài apiserver.
- Trạng thái mong muốn (`spec`) lưu trong `etcd`; trạng thái thực tế (`status`) do controller ghi lại.
- `kubectl` chỉ là client: nó gửi request HTTP tới apiserver, không "điều khiển" cluster trực tiếp.
