Amazon EKS (Elastic Kubernetes Service)
Elastic Kubernetes Service, K8s Core Concepts, Node Types
Tổng quan
Amazon EKS (Elastic Kubernetes Service) là dịch vụ Kubernetes được AWS quản lý hoàn toàn (fully managed). EKS giúp bạn chạy Kubernetes trên AWS mà không cần cài đặt, vận hành và maintain Kubernetes control plane.
Kubernetes là gì?
Tại sao K8s phổ biến?
| Tiêu chí | Docker Swarm | Kubernetes |
|---|---|---|
| Độ phức tạp | ✅ Đơn giản | ❌ Phức tạp hơn |
| Tính năng | Cơ bản | ✅ Toàn diện |
| Hệ sinh thái | Nhỏ | ✅ Khổng lồ (CNCF) |
| Enterprise adoption | Ít | ✅ 96% Fortune 500 |
| Community | Nhỏ | ✅ Lớn nhất |
💡 K8s đã trở thành industry standard cho container orchestration!
EKS vs Tự cài Kubernetes
Tự quản lý Kubernetes
Amazon EKS
So sánh tổng quan
| Tiêu chí | Self-managed K8s | Amazon EKS |
|---|---|---|
| Control plane | Bạn quản lý | AWS quản lý |
| High Availability | Tự setup | Built-in (3 AZs) |
| Upgrades | Phức tạp, rủi ro | 1-click hoặc managed |
| Integration AWS | Tự cấu hình | Native (ALB, IAM, VPC) |
| Chi phí control plane | EC2 costs | $0.10/hour |
| Compliance | Tự chứng minh | SOC, PCI, HIPAA ready |
Kiến trúc EKS
📘 Kubernetes Core Concepts
1. Pod - Đơn vị nhỏ nhất
Pod manifest ví dụ:
2. Deployment - Quản lý Pods
Deployment manifest ví dụ:
3. Service - Networking abstraction
Các loại Service:
| Type | Mô tả | Use case |
|---|---|---|
| ClusterIP | Internal IP, chỉ trong cluster | Microservices gọi nhau |
| NodePort | Expose trên port của Node | Dev/testing |
| LoadBalancer | Tạo external LB (cloud) | Production, external traffic |
Service manifest ví dụ:
4. Namespace - Logical separation
5. ConfigMap & Secret
6. Ingress - HTTP routing
Ingress manifest ví dụ:
EKS Node Types
EC2 Managed Node Groups
Self-managed Node Groups
EKS Fargate
So sánh Node Types
| Tiêu chí | Managed Node Group | Self-managed | Fargate |
|---|---|---|---|
| Quản lý | AWS | Bạn | AWS |
| Scaling | Tự động | Tự cấu hình | Per-pod |
| Cost | EC2 pricing | EC2 pricing | Per vCPU/GB/s |
| Flexibility | Trung bình | Cao nhất | Thấp |
| DaemonSets | ✅ | ✅ | ❌ |
| GPU support | ✅ | ✅ | ❌ |
| Best for | General workloads | Custom needs | Stateless apps |
🔌 EKS Integrations với AWS
AWS Load Balancer Controller
IAM Roles for Service Accounts (IRSA)
Secrets Manager Integration
EKS Cluster Setup
Tạo EKS Cluster với eksctl
Tạo Cluster với Terraform
Kết nối tới Cluster
EKS vs ECS - Khi nào dùng cái nào?
Decision Matrix
| Tiêu chí | Chọn ECS | Chọn EKS |
|---|---|---|
| Team size | Nhỏ, ít DevOps | Có dedicated platform team |
| K8s experience | Không/ít | Đã có kinh nghiệm |
| Multi-cloud | Không cần | Cần portability |
| Ecosystem | AWS-native đủ | Cần Helm, Prometheus, etc. |
| Learning curve | Muốn nhanh | Sẵn sàng đầu tư |
| Cost sensitivity | Quan trọng | Có budget cho $0.10/hr |
Khi nào chọn EKS?
- Đã dùng K8s on-prem → Migrate lên EKS dễ dàng
- Multi-cloud strategy → Code K8s chạy được AWS, GCP, Azure
- Rich ecosystem needs → Helm charts, operators, service mesh
- Industry compliance → Một số compliance yêu cầu K8s
- Team expertise → Đã có K8s skills
Khi nào chọn ECS?
- Simple container needs → Không cần K8s complexity
- AWS-focused → Không cần multi-cloud
- Small team → Ít người quản lý infrastructure
- Cost conscious → Không muốn trả $0.10/hr cho control plane
- New to containers → Learning curve thấp hơn
Autoscaling trong EKS
EKS có 2 tầng autoscaling hoạt động song song:
AWS chính thức hỗ trợ 3 phương án node-level autoscaling: EKS Auto Mode, Karpenter, và Kubernetes Cluster Autoscaler. Nguồn: Best Practices for Cluster Autoscaling.
1. Kubernetes Cluster Autoscaler (CAS)
Cluster Autoscaler là dự án open-source thuộc Kubernetes SIG-Autoscaling, scale số lượng node trong cluster bằng cách điều chỉnh Auto Scaling Groups (ASG) phía dưới.
Cách CAS quyết định scale
| Sự kiện | CAS làm gì |
|---|---|
| Pod ở trạng thái Pending vì thiếu resource | Scale-out: tăng desiredCapacity của ASG phù hợp |
| Node có utilization < threshold (mặc định 50%) trong >10 phút và pods có thể chuyển đi nơi khác | Scale-in: drain node rồi giảm ASG |
CAS dựa vào Pod requests (không phải actual usage) để tính node cần thiết → request đặt sai sẽ scale sai.
Ưu / nhược điểm CAS
| ✅ Ưu | ❌ Nhược |
|---|---|
| Open-source, ổn định, được dùng rộng rãi | Phụ thuộc ASG → mỗi loại instance/AZ cần 1 ASG riêng |
| Tích hợp tốt với mọi cloud (AWS, GCP, Azure) | Scale chậm hơn (qua ASG API + EC2 launch) |
| Hành vi đơn giản, dễ debug | Bin-packing kém — không tự chọn instance type tối ưu cho pod |
| Phù hợp cluster có ít node group, workload đồng nhất | Quản lý nhiều ASG = phức tạp ở quy mô lớn |
Cài đặt nhanh CAS trên EKS
Tham số cần biết:
2. Karpenter (khuyến nghị bởi AWS cho cluster mới)
Karpenter là cluster autoscaler AWS xây dựng, provision EC2 trực tiếp qua EC2 API — không cần ASG.
Cấu hình bằng NodePool + EC2NodeClass (CRDs) — không cần tạo nhiều ASG.
3. EKS Auto Mode
EKS Auto Mode = Karpenter được AWS quản lý sẵn trong control plane. Bạn không cần install/maintain Karpenter, không cần tạo node group — AWS tự lo node provisioning, OS patching, scaling.
→ Phụ phí +12% trên giá EC2 mà Auto Mode quản lý. Đổi lại: zero-ops cho data plane.
4. So sánh CAS vs Karpenter vs EKS Auto Mode
| Tiêu chí | Cluster Autoscaler | Karpenter | EKS Auto Mode |
|---|---|---|---|
| Cơ chế | Scale ASG | Gọi EC2 API trực tiếp | Karpenter managed |
| Tốc độ scale-out | Trung bình (1-3 phút) | Nhanh (~30-60s) | Nhanh (~30-60s) |
| Bin-packing / chọn instance | Theo ASG cố định | Tự chọn instance tối ưu theo pod | Tự chọn |
| Số node group/ASG cần | Nhiều (theo type/AZ) | Không cần — dùng NodePool CRD | Không cần |
| Spot support | Có (nhưng phải cấu hình ASG) | Native, mix spot/on-demand mượt | Native |
| Consolidation | Hạn chế | ✅ Có (gộp pods, terminate node thừa) | ✅ Có |
| Operational overhead | Trung bình | Thấp | Rất thấp |
| Chi phí | EC2 thường | EC2 thường | EC2 + 12% phụ phí |
| Multi-cloud portable | ✅ Có | Hiện chỉ AWS (chính) | Chỉ AWS |
| Khi nào chọn? | Cluster đơn giản, ít node group, đã quen ASG | Cluster mới, workload đa dạng, cần tiết kiệm | Team không muốn quản lý data plane |
Khuyến nghị thực tế của AWS (2024+): Cluster mới → ưu tiên EKS Auto Mode hoặc Karpenter. Case studies như Salesforce (1,000+ EKS clusters) và BMW Connected đã migrate từ CAS → Karpenter và đạt +12% CPU utilization, tiết kiệm hàng triệu USD/năm. Nguồn: Salesforce migration · BMW migration.
5. Pod-level autoscaling (HPA & VPA) — bổ sung
Node-level autoscaler (CAS/Karpenter) chỉ phản ứng khi có pod Pending. Để pods tự scale theo tải, dùng:
| Autoscaler | Scale theo gì | Khi nào dùng |
|---|---|---|
| HPA | Số pod (replicas) theo CPU/RAM/custom metrics | Workload có thể scale ngang |
| VPA | CPU/RAM requests của pod | Workload không scale ngang dễ (DB, stateful) |
| KEDA | Pod theo event-driven (SQS, Kafka, Cron…) | Workload bursty, event-driven |
Pipeline đầy đủ: Metric tăng → HPA tăng replicas → Pod Pending → CAS/Karpenter tạo node → Pod chạy.
Production Best Practices
1. Cluster Architecture
2. Security Best Practices
3. Resource Quotas
4. Pod Disruption Budgets
Monitoring & Logging
CloudWatch Container Insights
Prometheus & Grafana Stack
Tổng kết
EKS Core Concepts
| Concept | K8s | EKS specifics |
|---|---|---|
| Cluster | K8s cluster | AWS managed control plane |
| Nodes | Worker machines | EC2, Fargate, Self-managed |
| Pods | Container wrapper | Same |
| Deployments | Pod management | Same |
| Services | Networking | Can create AWS ALB/NLB |
| Ingress | HTTP routing | AWS ALB Ingress Controller |
Khi nào dùng EKS?
✅ Đã có kinh nghiệm K8s ✅ Cần multi-cloud portability ✅ Cần rich K8s ecosystem (Helm, Operators) ✅ Enterprise-grade container orchestration ✅ Complex microservices architectures
Chi phí EKS
| Component | Cost |
|---|---|
| Control plane | $0.10/hour (~$73/month) |
| Worker nodes | EC2 pricing |
| Fargate | vCPU + Memory pricing |
| Data transfer | Standard AWS rates |