# LotusCloud — Triển Khai Trung Tâm Dữ Liệu Vật Lý (Colocation)

> Hướng dẫn chi tiết triển khai LotusCloud trên hạ tầng rack server vật lý  
> tại các IDC Việt Nam (Viettel IDC Hòa Lạc, VNPT IDC, FPT Telecom, CMC DC, …)

---

## Migration Reality Check (2026-03-07)

Trạng thái xác thực từ `GHN Migration_Requirements.xlsx`:

- `Done`: 5
- `Done/Partial`: 6
- `Partial`: 4
- `Gap`: 10

Kết luận: chưa đạt 25/25 full done. Phần còn thiếu là hạ tầng thực địa và quyết định vận hành, không phải chỉ thiếu endpoint/code.

### Các hạng mục đã code xong trong repo

- Billing breakdown chi tiết theo SKU/resource.
- Workload identity MVP cho service principal.
- Backup cross-zone metadata + kế thừa theo policy.
- Audit logging tập trung qua gateway -> monitor-service.

### Các hạng mục cần triển khai tại hạ tầng datacenter

- DBaaS enterprise hoàn chỉnh (managed Postgres/MySQL/MongoDB + failover chủ động).
- Hub-spoke network, multi-NIC VM, scale bandwidth 1->10Gbps không downtime.
- Multi-cluster K8s 2 site + global load balancing theo trọng số.
- SLA provisioning node và benchmark hiệu năng liên site/liên VPC.

### Checklist triển khai để đóng các Gap còn lại

- Thiết lập 2 site (HN/HCM) với liên kết WAN dự phòng và kiểm thử failover định kỳ.
- Vận hành DB HA có playbook failover manual + automatic health arbitration.
- Chuẩn hóa pipeline migration dữ liệu (CDC + cutover + rollback) cho từng engine DB.
- Tích hợp observability theo KPI bắt buộc: provisioning time, latency, throughput, error budget.

## 📋 Mục Lục

1. [Tổng quan kiến trúc triển khai](#-tổng-quan-kiến-trúc-triển-khai)
2. [Phương án A — Tối thiểu (1 Rack, MVP/Startup)](#-phương-án-a--tối-thiểu-1-rack-42u--mvpstartup)
3. [Phương án B — Trung bình (1-2 Rack, SMB/Enterprise)](#-phương-án-b--trung-bình-1-2-rack--smbenterprise)
4. [Chi tiết thiết bị server](#-chi-tiết-thiết-bị-server)
5. [Hạ tầng mạng (Network)](#-hạ-tầng-mạng-network)
6. [Hạ tầng bảo mật (Security)](#-hạ-tầng-bảo-mật-security)
7. [Hạ tầng lưu trữ & backup](#-hạ-tầng-lưu-trữ--backup)
8. [Auto-scaling & High Availability](#-auto-scaling--high-availability)
9. [Sơ đồ rack layout](#-sơ-đồ-rack-layout)
10. [Chi phí ước tính](#-chi-phí-ước-tính)
11. [Danh sách IDC Việt Nam](#-danh-sách-idc-việt-nam)
12. [Checklist triển khai](#-checklist-triển-khai)

---

## 🏗 Tổng Quan Kiến Trúc Triển Khai

```
                            ┌──────────────────┐
                            │   INTERNET        │
                            └────────┬─────────┘
                                     │
                            ┌────────▼─────────┐
                            │  ISP Uplink       │
                            │  (Viettel/VNPT)   │
                            └────────┬─────────┘
                                     │
                        ┌────────────▼────────────┐
                        │    FIREWALL (pfSense/   │
                        │    FortiGate)           │
                        │    + VPN Gateway        │
                        └────────────┬────────────┘
                                     │
                        ┌────────────▼────────────┐
                        │   L3 Switch / Router    │
                        │   VLAN Segmentation     │
                        └──┬─────────┬─────────┬──┘
                           │         │         │
              ┌────────────▼──┐  ┌───▼──────┐  ┌▼────────────┐
              │  DMZ VLAN     │  │ App VLAN │  │ Data VLAN   │
              │  (10.0.1.0/24)│  │(10.0.2/24)│ │(10.0.3.0/24)│
              ├───────────────┤  ├──────────┤  ├─────────────┤
              │ HAProxy/Nginx │  │ K3s/K8s  │  │ PostgreSQL  │
              │ Load Balancer │  │ Workers  │  │ Redis       │
              │               │  │ (Apps)   │  │ RabbitMQ    │
              └───────────────┘  └──────────┘  │ Backup NAS  │
                                               └─────────────┘
```

---

## 🟢 Phương Án A — Tối Thiểu (1 Rack 42U) — MVP/Startup

> Phục vụ 50-200 users, 500-2000 VMs ảo, phù hợp startup hoặc doanh nghiệp SMB.  
> Budget: **250 - 400 triệu VNĐ** (thiết bị) + **15-25 triệu/tháng** (colocation).

### Danh sách thiết bị

| # | Thiết bị | Model tham khảo | Spec | SL | U | Mục đích |
|---|----------|-----------------|------|-----|---|----------|
| 1 | **Firewall** | pfSense (self-build) hoặc FortiGate 60F | 4-port GbE, IPS/IDS | 1 | 1U | Firewall, VPN, NAT |
| 2 | **Switch L3** | MikroTik CRS326-24G-2S+ hoặc Cisco SG350-28 | 24×1GbE + 2×10G SFP+ | 1 | 1U | Core switch, VLAN |
| 3 | **Server — Control Plane** | Dell R650xs / HPE DL360 Gen10+ | 1× Xeon Silver 4314 (16C), 64GB ECC, 2× 480GB SSD RAID1 | 1 | 1U | K3s master, etcd, Gateway, monitoring |
| 4 | **Server — Worker Node 1** | Dell R650xs / HPE DL360 Gen10+ | 1× Xeon Silver 4314 (16C), 128GB ECC, 2× 960GB NVMe RAID1 | 1 | 1U | App services (IAM, Compute, Storage, Network, Billing) |
| 5 | **Server — Worker Node 2** | Dell R650xs / HPE DL360 Gen10+ | 1× Xeon Silver 4314 (16C), 128GB ECC, 2× 960GB NVMe RAID1 | 1 | 1U | App services (SQL, LB, DNS, KeyVault, Container, Monitor) + Frontend |
| 6 | **Server — Database** | Dell R750xs / HPE DL380 Gen10+ | 1× Xeon Silver 4314 (16C), 128GB ECC, 4× 1.92TB NVMe RAID10 | 1 | 2U | PostgreSQL primary, Redis, RabbitMQ |
| 7 | **NAS Backup** | Synology RS1221+ | AMD Ryzen V1500B, 4GB, 4× 4TB HDD RAID5 | 1 | 2U | Backup DB, config, logs |
| 8 | **UPS** | APC SRT3000RMXLI (3kVA) | 3000VA/2700W, rack-mount | 1 | 2U | Bảo vệ điện, 15-20 phút runtime |
| 9 | **PDU** | APC AP7922B | 16A, 230V, metered | 2 | 0U | Phân phối điện (vertical mount) |
| 10 | **Patch Panel** | Cat6A 24-port | Kết nối cáp nội bộ | 1 | 1U | Cable management |
| 11 | **KVM Console** | Aten CL5708IN | 8-port KVM, LCD 17" | 1 | 1U | Remote console |

**Tổng U sử dụng: ~12U / 42U** (còn 30U trống để mở rộng)

### Tóm tắt tài nguyên compute

| Vai trò | CPU (cores) | RAM | Storage | Network |
|---------|-------------|-----|---------|---------|
| Control Plane | 16C / 32T | 64 GB | 960 GB SSD | 2× 1GbE |
| Worker 1 | 16C / 32T | 128 GB | 1.92 TB NVMe | 2× 1GbE |
| Worker 2 | 16C / 32T | 128 GB | 1.92 TB NVMe | 2× 1GbE |
| Database | 16C / 32T | 128 GB | 7.68 TB NVMe (RAID10 → 3.84 TB usable) | 2× 1GbE |
| **Tổng** | **64C / 128T** | **448 GB** | **~8.5 TB raw** | |

### Phần mềm triển khai

| Layer | Giải pháp | Ghi chú |
|-------|-----------|---------|
| OS | Ubuntu 22.04 LTS Server | Tất cả nodes |
| Container Orchestration | K3s (lightweight K8s) | 1 master + 2 workers |
| Ingress | Traefik (built-in K3s) hoặc Nginx Ingress | TLS termination |
| Certificate | Let's Encrypt + cert-manager | Auto-renewal |
| DNS | CoreDNS (internal) + Cloudflare (external) | Split-horizon DNS |
| Monitoring | Prometheus + Grafana + Alertmanager | Trên control plane |
| Logging | Loki + Promtail | Centralized logs |
| Tracing | Jaeger | Distributed tracing |

---

## 🟡 Phương Án B — Trung Bình (1-2 Rack) — SMB/Enterprise

> Phục vụ 200-1000 users, 2000-10000 VMs, HA đầy đủ, auto-scale.  
> Budget: **800 triệu - 1.5 tỷ VNĐ** (thiết bị) + **30-50 triệu/tháng** (colocation).

### Danh sách thiết bị — Rack 1 (Compute + Network)

| # | Thiết bị | Model tham khảo | Spec | SL | U | Mục đích |
|---|----------|-----------------|------|-----|---|----------|
| 1 | **Firewall HA** | FortiGate 100F (HA pair) | 10GbE, IPS/IDS, SSL-VPN, 20Gbps throughput | 2 | 2U | Active-Passive HA firewall |
| 2 | **Core Switch** | Cisco Catalyst 9300-24T hoặc Arista 7050SX3 | 24×1GbE + 4×10G SFP+, L3 | 2 | 2U | Redundant core switching |
| 3 | **ToR Switch (10G)** | MikroTik CRS305-1G-4S+ | 4× 10G SFP+ | 2 | 1U | Server interconnect 10G |
| 4 | **Server — K8s Master 1** | Dell R660 / HPE DL360 Gen11 | 1× Xeon Gold 5416S (16C), 64GB ECC, 2× 480GB SSD RAID1 | 1 | 1U | K8s control plane |
| 5 | **Server — K8s Master 2** | Dell R660 / HPE DL360 Gen11 | 1× Xeon Gold 5416S (16C), 64GB ECC, 2× 480GB SSD RAID1 | 1 | 1U | K8s control plane |
| 6 | **Server — K8s Master 3** | Dell R660 / HPE DL360 Gen11 | 1× Xeon Gold 5416S (16C), 64GB ECC, 2× 480GB SSD RAID1 | 1 | 1U | K8s control plane |
| 7 | **Server — Worker 1** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 256GB ECC, 2× 1.92TB NVMe RAID1 | 1 | 2U | App workloads |
| 8 | **Server — Worker 2** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 256GB ECC, 2× 1.92TB NVMe RAID1 | 1 | 2U | App workloads |
| 9 | **Server — Worker 3** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 256GB ECC, 2× 1.92TB NVMe RAID1 | 1 | 2U | App workloads |
| 10 | **Server — Worker 4** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 256GB ECC, 2× 1.92TB NVMe RAID1 | 1 | 2U | App workloads (scale) |
| 11 | **UPS** | APC SRT5000RMXLI (5kVA) | 5000VA/4500W | 1 | 3U | Power protection |
| 12 | **PDU** | APC AP7932B | 32A, 230V, switched | 2 | 0U | Power distribution |
| 13 | **KVM** | Aten KN4116VA | 16-port IP KVM | 1 | 1U | Remote management |
| 14 | **Patch Panel** | Cat6A 48-port | Cable management | 2 | 2U | Cabling |

**Rack 1: ~20U / 42U**

### Danh sách thiết bị — Rack 2 (Data + Backup + DR)

| # | Thiết bị | Model tham khảo | Spec | SL | U | Mục đích |
|---|----------|-----------------|------|-----|---|----------|
| 1 | **Switch** | MikroTik CRS326-24G-2S+ | 24×1GbE + 2×10G SFP+ | 1 | 1U | Data network |
| 2 | **DB Server — Primary** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 512GB ECC, 8× 1.92TB NVMe RAID10 | 1 | 2U | PostgreSQL primary + Redis primary |
| 3 | **DB Server — Replica** | Dell R760 / HPE DL380 Gen11 | 2× Xeon Gold 5416S (32C), 256GB ECC, 8× 1.92TB NVMe RAID10 | 1 | 2U | PostgreSQL streaming replica + Redis sentinel |
| 4 | **DB Server — Replica 2** | Dell R760 / HPE DL380 Gen11 | 1× Xeon Gold 5416S (16C), 128GB ECC, 4× 1.92TB NVMe RAID10 | 1 | 2U | PostgreSQL read replica + RabbitMQ mirror |
| 5 | **NAS — Primary** | Synology RS3621xs+ | 12-bay, Xeon D-1531, 8GB, 8× 8TB SAS RAID6 | 1 | 2U | Backup, object storage, logs |
| 6 | **NAS — Offsite Cold** | Synology RS2423+ | 12-bay, 4× 16TB SATA RAID6 | 1 | 2U | Cold backup, DR copy |
| 7 | **Tape Library** *(tùy chọn)* | HPE StoreEver MSL2024 | LTO-9, 18TB/tape, 24 slots | 1 | 2U | Long-term archival |
| 8 | **UPS** | APC SRT5000RMXLI (5kVA) | 5000VA/4500W | 1 | 3U | Power protection |
| 9 | **PDU** | APC AP7932B | 32A, 230V | 2 | 0U | Power distribution |

**Rack 2: ~16U / 42U**

### Tóm tắt tài nguyên (Phương án B)

| Vai trò | Nodes | CPU (tổng) | RAM (tổng) | Storage (tổng raw) |
|---------|-------|-----------|-----------|-------------------|
| K8s Masters | 3 | 48C / 96T | 192 GB | 2.88 TB SSD |
| K8s Workers | 4 | 128C / 256T | 1 TB | 15.36 TB NVMe |
| DB Cluster | 3 | 80C / 160T | 896 GB | 30.72 TB NVMe |
| NAS/Backup | 2 | — | — | 128 TB HDD (raw) |
| **Tổng** | **12** | **256C / 512T** | **~2 TB** | **~175 TB raw** |

---

## 🖥 Chi Tiết Thiết Bị Server

### Server spec cho LotusCloud workloads

#### Control Plane Nodes (K8s Masters)

```
Model:    Dell PowerEdge R660 / HPE ProLiant DL360 Gen11
CPU:      1× Intel Xeon Gold 5416S (16C/32T, 2.0 GHz base)
RAM:      64 GB DDR5-4800 ECC RDIMM (4× 16GB)
Storage:  2× 480GB SATA SSD (RAID1 — OS + etcd)
NIC:      2× 10GbE SFP+ (bonded) + 1× 1GbE IPMI/iDRAC
PSU:      Redundant 800W 80+ Platinum

Vai trò:
  - Kubernetes API server, etcd, scheduler, controller-manager
  - CoreDNS, cert-manager, Traefik ingress
  - Prometheus, Grafana, Alertmanager (trên 1 master)
```

#### Worker Nodes (App Servers)

```
Model:    Dell PowerEdge R760 / HPE ProLiant DL380 Gen11
CPU:      2× Intel Xeon Gold 5416S (tổng 32C/64T)
RAM:      256 GB DDR5-4800 ECC RDIMM (8× 32GB)
Storage:  2× 1.92TB NVMe U.2 (RAID1)
NIC:      2× 10GbE SFP+ (bonded) + 1× 1GbE IPMI
PSU:      Redundant 1100W 80+ Titanium
GPU:      Không cần (trừ khi chạy AI/ML workloads)

Vai trò:
  - LotusCloud microservices pods
  - Gateway, IAM, Compute, Storage, Network, Billing
  - SQL, LB, DNS, KeyVault, Container, Monitor
  - Frontend (Next.js SSR)
```

#### Database Servers

```
Model:    Dell PowerEdge R760 / HPE ProLiant DL380 Gen11
CPU:      2× Intel Xeon Gold 5416S (tổng 32C/64T)
RAM:      512 GB DDR5-4800 ECC RDIMM (16× 32GB)  [Primary]
          256 GB [Replica]
Storage:  8× 1.92TB NVMe U.2 (RAID10 → ~7.68TB usable) [Primary]
          4× 1.92TB NVMe U.2 (RAID10 → ~3.84TB usable) [Replica]
NIC:      2× 25GbE SFP28 (DB replication) + 1× 1GbE IPMI
PSU:      Redundant 1400W 80+ Titanium

Vai trò:
  - PostgreSQL 16 (Primary + Streaming Replication)
  - Redis 7 (Sentinel HA)
  - RabbitMQ 3.13 (Mirrored queues)
  
Tuning PostgreSQL:
  shared_buffers:        128GB (25% RAM)
  effective_cache_size:  384GB (75% RAM)
  work_mem:              256MB
  maintenance_work_mem:  2GB
  wal_buffers:           64MB
  max_connections:       500
  max_wal_senders:       5
  synchronous_commit:    on
```

---

## 🌐 Hạ Tầng Mạng (Network)

### Thiết kế VLAN

| VLAN ID | Subnet | Tên | Mục đích |
|---------|--------|-----|----------|
| 10 | 10.0.10.0/24 | **Management** | IPMI/iDRAC, KVM, switch mgmt |
| 20 | 10.0.20.0/24 | **DMZ** | Load balancer, Ingress, public-facing |
| 30 | 10.0.30.0/24 | **Application** | K8s pod network, service mesh |
| 40 | 10.0.40.0/24 | **Database** | PostgreSQL, Redis, RabbitMQ (isolated) |
| 50 | 10.0.50.0/24 | **Backup** | NAS, tape, replication traffic |
| 60 | 10.0.60.0/24 | **Monitoring** | Prometheus, Grafana, Jaeger, Loki |
| 99 | 10.0.99.0/24 | **VPN** | Site-to-site VPN, remote admin |

### Sơ đồ network

```
Internet
    │
    │ (Public IP: x.x.x.x)
    │
┌───▼───────────────────────────────────┐
│  FortiGate 100F (Active)              │
│  FortiGate 100F (Standby)            │  VLAN 99: VPN
│  ├─ WAN: ISP uplink                  │
│  ├─ DMZ: 10.0.20.0/24               │
│  ├─ LAN: trunk to Core Switch        │
│  └─ VPN: IPSec / SSL-VPN             │
└───┬───────────────────────────────────┘
    │ trunk (all VLANs tagged)
    │
┌───▼───────────────────────────────────┐
│  Core Switch (Cisco 9300) × 2        │
│  ├─ VLAN 10: Management              │
│  ├─ VLAN 20: DMZ (HAProxy/Ingress)   │
│  ├─ VLAN 30: Application (K8s)       │
│  ├─ VLAN 40: Database (isolated)     │
│  ├─ VLAN 50: Backup                  │
│  └─ VLAN 60: Monitoring              │
└───┬──────┬──────┬──────┬──────┬──────┘
    │      │      │      │      │
   10G    10G    10G    10G    1G
    │      │      │      │      │
  Master Worker Worker  DB    NAS
```

### Firewall rules (chính)

| Src VLAN | Dst VLAN | Port | Action | Ghi chú |
|----------|----------|------|--------|---------|
| Internet | DMZ (20) | 443 | ALLOW | HTTPS ingress |
| Internet | DMZ (20) | 80 | ALLOW → redirect 443 | HTTP redirect |
| DMZ (20) | App (30) | 8080 | ALLOW | Ingress → Gateway |
| App (30) | Data (40) | 5432, 6379, 5672 | ALLOW | App → DB/Cache/MQ |
| App (30) | Monitor (60) | 9090, 3000, 16686 | ALLOW | App → Monitoring |
| Mgmt (10) | ALL | 22, 443 | ALLOW | Admin SSH/HTTPS |
| Backup (50) | Data (40) | 5432 | ALLOW | Backup → DB |
| VPN (99) | Mgmt (10) | ALL | ALLOW | VPN admin |
| ALL | ALL | * | **DENY** | Default deny |

### ISP & Bandwidth

| Phương án | Bandwidth | IP | ISP gợi ý | Chi phí/tháng |
|-----------|-----------|-----|-----------|---------------|
| Tối thiểu | 100 Mbps dedicated | 1 public IP | Viettel/VNPT | 5-8 triệu |
| Trung bình | 500 Mbps dedicated | /29 (5 usable IPs) | Viettel Business | 15-25 triệu |
| Mở rộng | 1 Gbps dedicated | /28 (13 usable IPs) | Viettel + VNPT (dual-homed) | 30-50 triệu |

---

## 🔒 Hạ Tầng Bảo Mật (Security)

### Lớp bảo mật (Defense in Depth)

```
Layer 1 — Physical Security
  └─ IDC: Vân tay, thẻ từ, camera 24/7, bảo vệ
  └─ Rack: Khóa rack, chỉ admin có key

Layer 2 — Network Security
  └─ Firewall HA (FortiGate) với IPS/IDS
  └─ VLAN segmentation (7 zones)
  └─ ACL strict: default deny all
  └─ DDoS protection (ISP level + Cloudflare)

Layer 3 — Host Security
  └─ Ubuntu hardened (CIS Benchmark)
  └─ SSH key-only (disable password auth)
  └─ Fail2ban + UFW per host
  └─ Auto security updates (unattended-upgrades)
  └─ LUKS disk encryption (sensitive servers)

Layer 4 — Application Security
  └─ JWT + RBAC (LotusCloud IAM service)
  └─ TLS everywhere (cert-manager + Let's Encrypt)
  └─ WAF (ModSecurity hoặc Cloudflare WAF)
  └─ Rate limiting (API Gateway)
  └─ Input validation + parameterized queries (GORM)

Layer 5 — Data Security
  └─ PostgreSQL: SSL connections, pg_hba.conf strict
  └─ Redis: requirepass + ACL
  └─ Encryption at rest (LUKS / dm-crypt)
  └─ Encryption in transit (TLS 1.3)
  └─ Backup encryption (GPG / age)

Layer 6 — Monitoring & Audit
  └─ Prometheus + Alertmanager (real-time alerts)
  └─ Grafana dashboards (security metrics)
  └─ Loki + Promtail (centralized logging)
  └─ Jaeger (request tracing)
  └─ Audit log (all API mutations logged)
  └─ Wazuh / OSSEC (HIDS) — tùy chọn nâng cao
```

### Danh sách thiết bị bảo mật

| Thiết bị | Model | Chi phí (VNĐ) | Bắt buộc? |
|----------|-------|---------------|-----------|
| Firewall HA pair | FortiGate 100F × 2 | ~120-150 triệu | ✅ Có |
| SSL Certificate | Let's Encrypt (free) hoặc DigiCert Wildcard | 0 - 8 triệu/năm | ✅ Có |
| WAF | Cloudflare Pro ($20/tháng) hoặc ModSecurity (free) | 0 - 500K/tháng | ✅ Có |
| DDoS Protection | Cloudflare (free tier đủ cho MVP) | 0 | ✅ Có |
| VPN | WireGuard (free, built into firewall) | 0 | ✅ Có |
| HIDS | Wazuh (open-source) | 0 | ⚡ Khuyến nghị |
| Vulnerability Scanner | Trivy (container) + OpenVAS (infra) | 0 | ⚡ Khuyến nghị |
| SIEM | Wazuh SIEM hoặc Grafana Loki-based | 0 | ⚡ Nâng cao |

### Hardening checklist

- [ ] Disable root SSH login
- [ ] SSH key-only authentication (Ed25519)
- [ ] Configure fail2ban (max 5 attempts → ban 1 hour)
- [ ] Enable UFW: only required ports per VLAN
- [ ] Apply CIS Ubuntu 22.04 Benchmark Level 1
- [ ] Enable automatic security updates
- [ ] PostgreSQL: `ssl = on`, strict `pg_hba.conf`
- [ ] Redis: `requirepass`, bind only VLAN 40
- [ ] RabbitMQ: TLS listeners, user ACL  
- [ ] Kubernetes: PodSecurityStandards (restricted), NetworkPolicy per namespace
- [ ] Container images: scan with Trivy in CI/CD, no root containers
- [ ] Rotate JWT signing keys every 90 days
- [ ] Rotate DB passwords every 90 days (via sealed-secrets)

---

## 💾 Hạ Tầng Lưu Trữ & Backup

### Chiến lược backup 3-2-1

```
3 bản copy  ──►  Production DB (NVMe) + NAS Backup + Offsite/Cloud
2 loại media ──► NVMe SSD + HDD (NAS) [+ Tape nếu cần]
1 bản offsite ─► S3-compatible (MinIO remote) hoặc Cloud (Backblaze B2)
```

### Lịch backup

| Loại | Tần suất | Retention | Phương thức | Lưu tại |
|------|----------|-----------|-------------|---------|
| **DB Full Backup** | Hàng ngày 2:00 AM | 30 ngày | `pg_basebackup` | NAS Primary |
| **DB WAL Archive** | Continuous | 7 ngày | `archive_command` | NAS Primary |
| **DB Point-in-Time** | Hàng giờ | 7 ngày | WAL replay | NAS Primary |
| **Redis RDB** | Mỗi 6 giờ | 14 ngày | `redis-cli bgsave` | NAS Primary |
| **Config & Secrets** | Mỗi thay đổi | 90 ngày | `etcdctl snapshot` + git | NAS Primary + Git |
| **Container Images** | Mỗi build | 30 tags | Registry (Harbor) | NAS Primary |
| **Full System** | Hàng tuần (CN) | 12 tuần | `rsync` | NAS Offsite Cold |
| **Offsite Cloud** | Hàng ngày | 90 ngày | `rclone sync` → B2/S3 | Backblaze B2 |

### Script backup PostgreSQL

```bash
#!/bin/bash
# /opt/lotuscloud/scripts/backup-db.sh
# Chạy qua cron: 0 2 * * * /opt/lotuscloud/scripts/backup-db.sh

set -euo pipefail

TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/mnt/nas/backups/postgresql"
RETENTION_DAYS=30

# Full backup
pg_basebackup \
  -h 10.0.40.10 -U replicator -D "${BACKUP_DIR}/base_${TIMESTAMP}" \
  --wal-method=stream --checkpoint=fast --progress

# Compress
tar -czf "${BACKUP_DIR}/base_${TIMESTAMP}.tar.gz" \
  -C "${BACKUP_DIR}" "base_${TIMESTAMP}"
rm -rf "${BACKUP_DIR}/base_${TIMESTAMP}"

# Encrypt
age -r age1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \
  "${BACKUP_DIR}/base_${TIMESTAMP}.tar.gz" \
  > "${BACKUP_DIR}/base_${TIMESTAMP}.tar.gz.age"
rm "${BACKUP_DIR}/base_${TIMESTAMP}.tar.gz"

# Cleanup old backups
find "${BACKUP_DIR}" -name "base_*.tar.gz.age" -mtime +${RETENTION_DAYS} -delete

# Sync to offsite
rclone sync "${BACKUP_DIR}/" backblaze:lotuscloud-backup/postgresql/ \
  --transfers 4 --checkers 8

echo "[$(date)] Backup completed: base_${TIMESTAMP}" >> /var/log/lotuscloud-backup.log
```

### Disaster Recovery

| Scenario | RTO | RPO | Phương án |
|----------|-----|-----|-----------|
| Disk failure (1 drive) | 0 phút | 0 | RAID rebuild tự động |
| Server failure | 5-15 phút | 0 | K8s reschedule pods sang node khác |
| DB primary failure | 1-5 phút | 0 (sync replica) | Patroni auto-failover |
| Full rack failure | 1-4 giờ | 1 giờ (WAL) | Restore từ NAS offsite |
| IDC disaster | 4-24 giờ | 24 giờ | Restore từ cloud backup (B2/S3) |

---

## ⚡ Auto-scaling & High Availability

### Kubernetes HPA (Horizontal Pod Autoscaler)

```yaml
# K8s HPA cho api-gateway
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
  name: api-gateway-hpa
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: api-gateway
  minReplicas: 2
  maxReplicas: 8
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 70
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80
  behavior:
    scaleUp:
      stabilizationWindowSeconds: 60
      policies:
      - type: Pods
        value: 2
        periodSeconds: 60
    scaleDown:
      stabilizationWindowSeconds: 300
      policies:
      - type: Pods
        value: 1
        periodSeconds: 120
```

### Service HA Matrix

| Service | Min Replicas | Max Replicas | HPA | Anti-affinity | Health Check |
|---------|-------------|-------------|-----|---------------|-------------|
| api-gateway | 2 | 8 | ✅ CPU 70% | ✅ Spread across nodes | `/health` |
| iam-service | 2 | 6 | ✅ CPU 70% | ✅ | `/health` |
| compute-service | 2 | 10 | ✅ CPU/Memory | ✅ | `/health` |
| storage-service | 2 | 10 | ✅ CPU/Memory | ✅ | `/health` |
| network-service | 2 | 6 | ✅ CPU 70% | ✅ | `/health` |
| billing-service | 2 | 4 | ✅ CPU 70% | ✅ | `/health` |
| sql-service | 2 | 6 | ✅ CPU 70% | ✅ | `/health` |
| lb-service | 2 | 4 | ✅ | ✅ | `/health` |
| dns-service | 2 | 4 | ✅ | ✅ | `/health` |
| keyvault-service | 2 | 4 | ✅ | ✅ | `/health` |
| container-service | 2 | 8 | ✅ CPU/Memory | ✅ | `/health` |
| monitor-service | 2 | 4 | ✅ | ✅ | `/health` |
| lotus-console | 2 | 6 | ✅ CPU 70% | ✅ | Next.js health |
| PostgreSQL | 1 primary + 2 replica | — | ❌ Manual | ✅ | Patroni |
| Redis | 3 (sentinel) | — | ❌ | ✅ | Sentinel |
| RabbitMQ | 3 (quorum) | — | ❌ | ✅ | Cluster |

### Mở rộng cluster (Scale-out)

```
Khi cần thêm capacity:

1. Mua thêm server (Worker Node)
   └─ Dell R760 / HPE DL380 Gen11
   └─ Rack vào slot trống (còn 20+ U trống)

2. Cài Ubuntu + join K8s cluster
   $ curl -sfL https://get.k3s.io | K3S_URL=https://master:6443 \
     K3S_TOKEN=xxx sh -

3. K8s tự động schedule pods lên node mới
   └─ HPA sẽ scale replicas khi có thêm resource

4. Thời gian: ~30 phút từ lúc rack server → ready
```

---

## 📐 Sơ Đồ Rack Layout

### Phương án A — 1 Rack 42U

```
┌─────────────────────────────────────┐
│            RACK 42U                 │
├─────────────────────────────────────┤
│ U42 │ (trống — mở rộng)            │
│ U41 │ (trống)                       │
│ ... │ (trống — 30U trống)           │
│ U12 │ (trống)                       │
├─────────────────────────────────────┤
│ U11 │ KVM Console (Aten CL5708)    │
│ U10 │ Patch Panel 24-port Cat6A    │
├─────────────────────────────────────┤
│ U09 │ ┐ UPS 3kVA (APC SRT3000)    │
│ U08 │ ┘                            │
├─────────────────────────────────────┤
│ U07 │ ┐ NAS Backup (Synology)      │
│ U06 │ ┘                            │
├─────────────────────────────────────┤
│ U05 │ ┐ Database Server (R750xs)   │
│ U04 │ ┘  PostgreSQL + Redis + MQ   │
├─────────────────────────────────────┤
│ U03 │ Worker Node 2 (R650xs)       │
│ U02 │ Worker Node 1 (R650xs)       │
│ U01 │ Control Plane (R650xs)       │
├─────────────────────────────────────┤
│     │ Switch L3 (MikroTik)          │     (bottom-of-rack)
│     │ Firewall (pfSense/FortiGate)  │
└─────────────────────────────────────┘
  PDU(A)                         PDU(B)   ← vertical mount, 0U
```

### Phương án B — 2 Rack

```
┌─────────────── RACK 1 ──────────────┐    ┌─────────────── RACK 2 ──────────────┐
│            COMPUTE + NET             │    │           DATA + BACKUP              │
├──────────────────────────────────────┤    ├──────────────────────────────────────┤
│ U42-U23 │ (trống — mở rộng)         │    │ U42-U27 │ (trống — mở rộng)         │
├──────────────────────────────────────┤    ├──────────────────────────────────────┤
│ U22 │ KVM IP (Aten KN4116VA)        │    │ U26 │ ┐ UPS 5kVA                    │
│ U21 │ Patch Panel 48-port #2        │    │ U25 │ │                              │
│ U20 │ Patch Panel 48-port #1        │    │ U24 │ ┘                              │
├──────────────────────────────────────┤    ├──────────────────────────────────────┤
│ U19 │ ┐ UPS 5kVA (APC SRT5000)     │    │ U23 │ ┐ NAS Offsite Cold             │
│ U18 │ │                              │    │ U22 │ ┘ (Synology RS2423+)          │
│ U17 │ ┘                              │    ├──────────────────────────────────────┤
├──────────────────────────────────────┤    │ U21 │ ┐ NAS Primary                  │
│ U16 │ ┐ Worker 4 (R760, scale)      │    │ U20 │ ┘ (Synology RS3621xs+)        │
│ U15 │ ┘                              │    ├──────────────────────────────────────┤
│ U14 │ ┐ Worker 3 (R760)             │    │ U19 │ ┐ Tape Library (tùy chọn)     │
│ U13 │ ┘                              │    │ U18 │ ┘ (HPE MSL2024)              │
│ U12 │ ┐ Worker 2 (R760)             │    ├──────────────────────────────────────┤
│ U11 │ ┘                              │    │ U17 │ ┐ DB Replica 2 (R760)         │
│ U10 │ ┐ Worker 1 (R760)             │    │ U16 │ ┘                              │
│ U09 │ ┘                              │    │ U15 │ ┐ DB Replica 1 (R760)         │
├──────────────────────────────────────┤    │ U14 │ ┘                              │
│ U08 │ K8s Master 3 (R660)           │    │ U13 │ ┐ DB Primary (R760)            │
│ U07 │ K8s Master 2 (R660)           │    │ U12 │ ┘                              │
│ U06 │ K8s Master 1 (R660)           │    ├──────────────────────────────────────┤
├──────────────────────────────────────┤    │ U11 │ Switch (MikroTik CRS326)      │
│ U05 │ ToR Switch 10G #2             │    └──────────────────────────────────────┘
│ U04 │ ToR Switch 10G #1             │      PDU(A)                      PDU(B)
│ U03 │ Core Switch #2 (Cisco 9300)   │
│ U02 │ Core Switch #1 (Cisco 9300)   │
│ U01 │ Firewall HA (FortiGate × 2)  │
└──────────────────────────────────────┘
  PDU(A)                         PDU(B)
```

---

## 💰 Chi Phí Ước Tính

### Phương án A — Tối thiểu (1 Rack)

| Hạng mục | Chi tiết | Chi phí (VNĐ) |
|-----------|----------|---------------|
| **Thiết bị server** | | |
| Control Plane × 1 | R650xs (16C/64G/960G SSD) | ~50-60 triệu |
| Worker × 2 | R650xs (16C/128G/1.9T NVMe) × 2 | ~120-140 triệu |
| Database × 1 | R750xs (16C/128G/7.7T NVMe) | ~80-100 triệu |
| **Network** | | |
| Firewall | pfSense (self-build) hoặc FortiGate 60F | 0 - 30 triệu |
| Switch L3 | MikroTik CRS326-24G-2S+ | ~5-8 triệu |
| **Storage** | | |
| NAS Backup | Synology RS1221+ (12TB RAID5) | ~30-40 triệu |
| **Infra** | | |
| UPS 3kVA | APC SRT3000 | ~25-30 triệu |
| PDU × 2 | APC metered | ~8-10 triệu |
| KVM + Patch Panel | | ~10-12 triệu |
| Cáp mạng + SFP+ | Cat6A + DAC cables | ~3-5 triệu |
| **Tổng thiết bị** | | **~330-425 triệu** |
| | | |
| **Chi phí hàng tháng** | | |
| Colocation 1/4 rack | Viettel IDC (10U, 3kW) | ~8-12 triệu/tháng |
| Bandwidth 100Mbps | Viettel Business dedicated | ~5-8 triệu/tháng |
| Public IP × 1 | | ~500K/tháng |
| Domain + DNS | Cloudflare (free) + .vn domain | ~500K/năm |
| SSL | Let's Encrypt | 0 |
| Offsite Backup | Backblaze B2 (~500GB) | ~$2.5/tháng (~60K) |
| **Tổng hàng tháng** | | **~15-22 triệu/tháng** |

### Phương án B — Trung bình (2 Rack)

| Hạng mục | Chi tiết | Chi phí (VNĐ) |
|-----------|----------|---------------|
| **Thiết bị server** | | |
| K8s Master × 3 | R660 (16C/64G/960G SSD) | ~150-180 triệu |
| Worker × 4 | R760 (32C/256G/3.8T NVMe) | ~400-480 triệu |
| DB Primary × 1 | R760 (32C/512G/15.4T NVMe) | ~140-170 triệu |
| DB Replica × 2 | R760 (16-32C/128-256G/7.7T NVMe) | ~160-200 triệu |
| **Network** | | |
| Firewall HA | FortiGate 100F × 2 | ~120-150 triệu |
| Core Switch × 2 | Cisco 9300-24T | ~80-100 triệu |
| ToR Switch × 2 | MikroTik CRS305-1G-4S+ | ~8-10 triệu |
| Data Switch × 1 | MikroTik CRS326 | ~5-8 triệu |
| **Storage** | | |
| NAS Primary | Synology RS3621xs+ (64TB raw) | ~80-100 triệu |
| NAS Offsite | Synology RS2423+ (64TB raw) | ~50-60 triệu |
| Tape (tùy chọn) | HPE MSL2024 + 12× LTO-9 | ~80-100 triệu |
| **Infra** | | |
| UPS 5kVA × 2 | APC SRT5000 | ~80-100 triệu |
| PDU × 4 | APC switched | ~20-24 triệu |
| KVM IP | Aten KN4116VA | ~15-18 triệu |
| Rack 42U × 2 | (IDC cung cấp hoặc mua) | ~20-30 triệu |
| Cáp mạng + SFP+ | Cat6A + DAC + SFP28 | ~10-15 triệu |
| **Tổng thiết bị** | | **~1.4 - 1.7 tỷ** |
| | | |
| **Chi phí hàng tháng** | | |
| Colocation 2 rack | Viettel IDC (2× full rack, 10kW) | ~30-40 triệu/tháng |
| Bandwidth 500Mbps | Dual ISP business dedicated | ~20-30 triệu/tháng |
| Public IP /29 | 5 usable IPs | ~2-3 triệu/tháng |
| Domain + DNS | Cloudflare Pro | ~500K/tháng |
| SSL | DigiCert Wildcard (nếu cần EV) | ~8 triệu/năm |
| Offsite Backup | Backblaze B2 (~5TB) | ~$25/tháng (~600K) |
| Support contract | Dell/HPE ProSupport NBD | ~50-80 triệu/năm |
| **Tổng hàng tháng** | | **~55-80 triệu/tháng** |

### So sánh tổng chi phí 3 năm (TCO)

| | Phương án A | Phương án B |
|---|-------------|-------------|
| **Thiết bị (CAPEX)** | 330-425 triệu | 1.4-1.7 tỷ |
| **Hàng tháng × 36** | 540-792 triệu | 1.98-2.88 tỷ |
| **TCO 3 năm** | **~870 triệu - 1.2 tỷ** | **~3.4 - 4.6 tỷ** |
| **Amortized/tháng** | **~24-33 triệu** | **~94-128 triệu** |
| **Users phục vụ** | 50-200 | 200-1000 |
| **Cost per user/tháng** | ~165-480K | ~128-470K |

---

## 🏢 Danh Sách IDC Việt Nam

| IDC | Vị trí | Tier | Colocation | Ghi chú |
|-----|--------|------|------------|---------|
| **Viettel IDC Hòa Lạc** | Hòa Lạc, Hà Nội | Tier III | ✅ | Lớn nhất miền Bắc, giá cạnh tranh |
| **Viettel IDC Tân Thuận** | Q.7, TP.HCM | Tier III | ✅ | Lớn nhất miền Nam |
| **VNPT Data Center** | Nhiều điểm | Tier III | ✅ | Backbone tốt |
| **FPT Telecom DC** | Hà Nội & HCM | Tier III | ✅ | Peering tốt |
| **CMC Data Center** | Hà Nội & HCM | Tier III+ | ✅ | Enterprise focus |
| **NTT Vietnam** | Q.7, TP.HCM | Tier III+ | ✅ | Global backbone |
| **OneAsia DC** | Q.2, TP.HCM | Tier III+ | ✅ | Cloud-ready |

### Tiêu chí chọn IDC

- [ ] Tier III trở lên (99.982% uptime, N+1 redundancy)
- [ ] Dual power feed (2 nguồn điện độc lập)
- [ ] Cooling: N+1 CRAC/CRAH
- [ ] Fire suppression: FM-200 hoặc Novec 1230
- [ ] Physical security: Biometric + CCTV 24/7 + Mantraps
- [ ] SLA: 99.99% uptime guarantee
- [ ] Hỗ trợ remote hands 24/7
- [ ] Network carrier-neutral (nhiều ISP)
- [ ] Khoảng cách từ office ≤ 2 giờ đi xe

---

## ✅ Checklist Triển Khai

### Phase 1 — Procurement (2-4 tuần)

- [ ] Chọn IDC và ký hợp đồng colocation
- [ ] Đặt mua server (Dell Direct / HPE Partner / Thế Giới Số)
- [ ] Đặt mua switch, firewall, UPS, PDU, cáp
- [ ] Đặt mua NAS + HDD
- [ ] Đăng ký ISP bandwidth + public IP
- [ ] Đăng ký domain (.vn + .com)

### Phase 2 — Physical Setup (1-2 tuần)

- [ ] Rack & stack tại IDC
- [ ] Đấu nối cáp nguồn (dual PSU → dual PDU)
- [ ] Đấu nối cáp mạng (Cat6A + SFP+)
- [ ] Cấu hình IPMI/iDRAC (VLAN 10)
- [ ] Test điện + UPS failover
- [ ] Test network connectivity

### Phase 3 — OS & Platform (1 tuần)

- [ ] Cài Ubuntu 22.04 LTS Server (tất cả nodes)
- [ ] Hardening: CIS Benchmark, SSH keys, fail2ban
- [ ] Cấu hình VLAN trên switch
- [ ] Cấu hình firewall rules
- [ ] Setup K3s/K8s cluster (3 masters + N workers)
- [ ] Setup Container Registry (Harbor) nếu cần
- [ ] Setup Helm + ArgoCD/Flux (GitOps)

### Phase 4 — Data Layer (3-5 ngày)

- [ ] Cài PostgreSQL 16 + Patroni HA (3 nodes)
- [ ] Cấu hình streaming replication
- [ ] Cài Redis Sentinel (3 instances)
- [ ] Cài RabbitMQ cluster (3 nodes, quorum queues)
- [ ] Setup backup scripts + cron
- [ ] Test failover (kill primary → auto-promote)

### Phase 5 — Application (3-5 ngày)

- [ ] Deploy LotusCloud Helm chart
- [ ] Cấu hình Ingress + TLS (cert-manager)
- [ ] Cấu hình HPA cho mỗi service
- [ ] Run database migrations
- [ ] Seed RBAC permissions
- [ ] Register admin user

### Phase 6 — Monitoring & Security (2-3 ngày)

- [ ] Deploy Prometheus + Grafana + Alertmanager
- [ ] Import LotusCloud dashboards
- [ ] Deploy Loki + Promtail
- [ ] Deploy Jaeger
- [ ] Setup alert rules (Slack/Telegram/Email)
- [ ] Setup Wazuh HIDS (nếu cần)
- [ ] Penetration test cơ bản (OpenVAS + Trivy)

### Phase 7 — Go Live (1-2 ngày)

- [ ] DNS cutover (Cloudflare → public IP)
- [ ] Smoke test toàn bộ services
- [ ] Load test (k6 / Locust)
- [ ] Verify backup/restore procedure
- [ ] Verify HA failover (kill nodes, verify recovery)
- [ ] Document runbook
- [ ] 🎉 Go Live!

**Tổng timeline: ~6-8 tuần từ lúc bắt đầu mua thiết bị → production**

---

## 📞 Liên Hệ Nhà Cung Cấp

| Loại | Nhà cung cấp gợi ý | Website |
|------|---------------------|---------|
| Server Dell | Synnex FPT, Digiworld, Dell Direct VN | dell.com/vn |
| Server HPE | Ingram Micro VN, HPE Partner | hpe.com/vn |
| Network (MikroTik) | Wireless1, MikroTik VN | mikrotik.com |
| Network (Cisco) | Synnex FPT, VSTECS | cisco.com |
| Firewall (FortiGate) | VNCS, CMC Cyber Security | fortinet.com |
| NAS (Synology) | Mỹ Tín, Phong Vũ Enterprise | synology.com |
| UPS (APC) | Schneider Electric VN | apc.com |
| Colocation | Viettel IDC: 1800 8088 | viettelidc.com.vn |
