Compute Classes trong GKE Autopilot
Compute class là gì và tại sao quan trọng
Trong Standard GKE, bạn chọn machine type trực tiếp cho node pool: n2-standard-8, c3-highcpu-30, a2-highgpu-1g. Bạn là người quyết định hardware.
Trong Autopilot, bạn không quản lý node. Thay vào đó, bạn dùng compute class — một abstraction khai báo loại hardware bạn cần mà không cần chỉ định machine type cụ thể. Autopilot sẽ tự chọn machine type phù hợp nhất trong class đó dựa trên resource requests.
Compute class không chỉ là hardware hint. Chúng ảnh hưởng đến:
- Resource limits (min/max CPU, memory có thể request)
- CPU:memory ratio rules
- Billing model (per-Pod vs per-node)
- Security characteristics
- Availability và SLA
Built-in compute classes
GKE cung cấp các compute classes sau, và chúng được cập nhật khi Google ra VM families mới:
1. General Purpose (mặc định)
Khi không khai báo compute class, Autopilot dùng General Purpose.
VM families: E2 series (cost-optimized, shared-core) và N series trên cluster mới hơn.
Đặc điểm:
- Balanced CPU/memory cho general workloads
- Chi phí thấp nhất trong các compute classes
- Phù hợp cho web services, APIs, backend services không đặc thù
- Bursting support trên GKE 1.32.3+
Không cần khai báo gì — chỉ cần không chỉ định cloud.google.com/compute-class.
# Dùng General Purpose (ngầm định)
spec:
containers:
- name: app
resources:
requests:
cpu: "500m"
memory: "1Gi"Khi nào phù hợp: Stateless web services, REST APIs, message consumers, background jobs không yêu cầu hardware đặc biệt.
2. Balanced
VM families: N2, N2D (AMD EPYC), N4 series.
Đặc điểm:
- Performance cao hơn General Purpose với full dedicated vCPU
- Max CPU lên đến 222 vCPU, max memory 851 GiB — phù hợp cho workloads lớn hơn
- CPU:memory ratio 1:1 đến 1:8 (linh hoạt hơn General Purpose)
- Consistent CPU performance (không share core như E2)
spec:
nodeSelector:
cloud.google.com/compute-class: "balanced"
containers:
- name: app
resources:
requests:
cpu: "4"
memory: "16Gi"Khi nào phù hợp: Databases (PostgreSQL, MySQL), caching layers (Redis, Memcached), backend services cần predictable CPU performance, Java/Go services với JVM tuning cần dedicated cores.
Lưu ý: Tên class là balanced (lowercase), không phải Balanced.
3. Scale-Out
VM families: T2D (AMD EPYC Milan), T2A (ARM Ampere Altra).
Đặc điểm:
- SMT (Simultaneous Multi-Threading) bị tắt: Mỗi vCPU tương ứng 1 physical core, không phải hyperthread. Điều này cải thiện performance-per-core cho các workloads nhạy cảm với CPU sharing.
- Hỗ trợ cả x86 và ARM architecture
- CPU:memory ratio cố định 1:4 (không linh hoạt như Balanced)
- Chi phí cạnh tranh cho HPC và compute-intensive workloads
Lựa chọn architecture:
# x86 (AMD EPYC T2D)
spec:
nodeSelector:
cloud.google.com/compute-class: "scale-out"
kubernetes.io/arch: "amd64"
containers:
- name: app
resources:
requests:
cpu: "4"
memory: "16Gi" # Bắt buộc 4:16 = 1:4 ratio
# ARM (Ampere Altra T2A)
spec:
nodeSelector:
cloud.google.com/compute-class: "scale-out"
kubernetes.io/arch: "arm64"Khi nào phù hợp: CPU-bound workloads (encoding, compression, cryptography), batch processing, simulations. Đặc biệt tốt cho workloads mà CPU sharing ảnh hưởng đến latency (game servers, real-time processing).
Cẩn thận với ratio cứng: Scale-Out enforce 1:4 CPU:memory. Nếu app cần 4 vCPU và 8 GiB memory (ratio 1:2), Autopilot sẽ tăng memory lên 16 GiB — bạn trả tiền cho 16 GiB dù chỉ dùng 8 GiB.
4. Performance
VM families: C2, C2D, C3, C3D (compute-optimized), M3, M4 (memory-optimized).
Đặc điểm:
- Highest single-core performance trong Autopilot
- Không enforce CPU:memory ratio — linh hoạt hoàn toàn
- Hỗ trợ local SSD cho storage performance cao
- Chi phí cao nhất, phù hợp cho workloads cần raw compute
spec:
nodeSelector:
cloud.google.com/compute-class: "performance"
# Tùy chọn: chọn cụ thể machine series
cloud.google.com/machine-family: "c3" # Hoặc "c2", "m3", "m4"
containers:
- name: app
resources:
requests:
cpu: "20"
memory: "40Gi"Machine families trong Performance class:
| Machine Family | Đặc điểm | Use case |
|---|---|---|
| C2/C2D | Compute-optimized, high clock speed | CPU-intensive processing |
| C3/C3D | Latest generation, balanced perf | Modern high-performance apps |
| M3/M4 | Memory-optimized, lên đến 5952 GiB RAM | In-memory databases, SAP HANA |
Khi nào phù hợp: High-performance databases cần NVMe storage, in-memory analytics, compute-intensive batch jobs, video encoding.
5. Accelerator (GPU)
Đặc điểm:
- Provisioning node với NVIDIA GPUs
- Billing chuyển sang per-node (không phải per-Pod)
- Require explicit GPU request trong Pod spec
spec:
nodeSelector:
cloud.google.com/compute-class: "accelerator"
cloud.google.com/gke-accelerator: "nvidia-tesla-t4" # Loại GPU
containers:
- name: training
resources:
requests:
cpu: "4"
memory: "16Gi"
nvidia.com/gpu: "1"
limits:
nvidia.com/gpu: "1"GPU types hỗ trợ (theo khu vực):
- NVIDIA T4 (inference, entry-level training)
- NVIDIA L4 (inference-optimized, 24 GiB VRAM)
- NVIDIA A100 40GB và 80GB (large model training)
- NVIDIA H100 80GB (highest performance, MIG support)
- NVIDIA V100 (legacy)
Lưu ý về billing: Khi dùng Accelerator class, bạn trả tiền cho toàn bộ node (bao gồm GPU), ngay cả khi Pod chỉ request một phần CPU/memory của node đó. Đây là sự khác biệt quan trọng so với billing per-Pod resource của các class khác.
6. ML Inference (mới, cần kiểm tra availability theo region)
VM families: G2 (NVIDIA L4 GPU, inference-optimized).
Đặc điểm:
- Thiết kế cụ thể cho low-latency ML inference
- NVIDIA L4 GPU tối ưu cho inference workloads hơn training
- Hỗ trợ DLSS và NVENC/NVDEC hardware acceleration
spec:
nodeSelector:
cloud.google.com/compute-class: "ml-inference"
containers:
- name: inference-server
resources:
requests:
nvidia.com/gpu: "1"
cpu: "8"
memory: "24Gi"Custom ComputeClasses
Ngoài built-in compute classes, Autopilot cũng hỗ trợ Custom ComputeClasses — một Kubernetes CRD cho phép bạn định nghĩa tập node configurations cụ thể hơn.
Khi nào cần Custom ComputeClass
Built-in classes phù hợp cho hầu hết workloads. Custom ComputeClass cần thiết khi:
- Cần machine type cụ thể: Ví dụ bạn cần n2-highmem-32 thay vì Autopilot tự chọn trong Balanced class
- Cần local SSD: Workloads cần NVMe local storage cho I/O intensive operations
- Cần GPU model cụ thể: Không phải bất kỳ GPU nào, mà phải là A100 80GB
- Priority fallback: Nếu machine type ưa thích không available, fallback tự động
- Active node consolidation: Tự động migrate workloads sang ít node hơn khi có thể
Cấu trúc Custom ComputeClass
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: my-performance-class
spec:
# Danh sách node configurations theo thứ tự ưu tiên
nodeConfigurations:
- machineType: "c3-standard-22-lssd" # Ưu tiên 1: C3 với local SSD
nodePoolAutoCreation:
enabled: true
- machineType: "c3-standard-22" # Fallback 1: C3 không có local SSD
nodePoolAutoCreation:
enabled: true
- machineType: "c2-standard-16" # Fallback 2: C2 nếu C3 không available
nodePoolAutoCreation:
enabled: true
# Tự động gộp node khi workload giảm
activeMigration:
optimizeRuleName: "Consolidate"Sử dụng Custom ComputeClass
spec:
nodeSelector:
cloud.google.com/compute-class: "my-performance-class"
containers:
- name: app
resources:
requests:
cpu: "8"
memory: "32Gi"Autopilot mode trong Standard clusters
Một tính năng thú vị: bạn có thể bật Autopilot mode trên một Custom ComputeClass trong Standard cluster. Điều này cho phép một số Pods trong Standard cluster được quản lý theo cách Autopilot (tự provision node, managed lifecycle) trong khi các Pods khác vẫn dùng Standard node pools.
apiVersion: cloud.google.com/v1
kind: ComputeClass
metadata:
name: autopilot-workloads
spec:
autopilotMode:
enabled: true # Bật managed infrastructure cho class này
nodeConfigurations:
- machineType: "e2-standard-4"
nodePoolAutoCreation:
enabled: trueĐây hữu ích cho migration từ Standard sang Autopilot — bạn có thể migrate workload từng phần.
Chọn compute class: decision tree
Workload của bạn là gì?
│
├── Cần GPU/TPU?
│ ├── Inference-focused → ML Inference class
│ └── Training/general GPU → Accelerator class
│
├── Cần raw compute performance (HPC, encoding)?
│ └── Performance class (chọn C3/C4 machine family)
│
├── Cần predictable CPU, không share core?
│ ├── Và cần ARM support hoặc AMD EPYC? → Scale-Out class
│ └── Và cần flexible CPU:memory ratio? → Balanced class
│
├── General web/backend services?
│ └── General Purpose (mặc định)
│
└── Cần machine type cụ thể hoặc local SSD?
└── Custom ComputeClassTương tác giữa compute class và VPA/HPA
VPA với Autopilot: VPA có thể recommend resource adjustments, nhưng Autopilot sẽ luôn enforce min/max của compute class. Nếu VPA recommend 50m CPU nhưng minimum của compute class là 250m, Pod sẽ chạy với 250m.
HPA với Autopilot: HPA scale số lượng Pods. Mỗi Pod mới được Autopilot provision với đủ node capacity. Tuy nhiên, Autopilot cần thời gian để provision node mới (thường 1-2 phút), nên HPA cold-start latency cao hơn Standard.
Tip: Dùng minReplicas: 1 (không scale-to-zero) nếu cần HPA responsiveness tốt. Với minReplicas=0, khi traffic đến lần đầu, Autopilot phải provision node từ đầu — latency có thể vài phút.