GĐ2: Hạ Tầng Đám Mây (GCP)

Tài liệu kỹ thuật chi tiết — 15/18 tasks hoàn thành (83%)

2.1 — Setup GCP Project & IAM

🟢 ✅ Hoàn thành
Project IDnewskyexpress
Regionasia-southeast1 (Singapore)
Service Accountodoo-k8s-sa@newskyexpress.iam.gserviceaccount.com
IAM RolesCompute Admin, Storage Admin, Container Admin
BillingLinked & active

2.2 — Terraform Infrastructure-as-Code

🟢 ✅ Hoàn thành

Toàn bộ hạ tầng được quản lý bằng Terraform, cho phép recreate môi trường trong <30 phút.

Files chính

FileMục đích
main.tfVMs, firewall rules, static IPs, startup scripts
variables.tfProject config, machine types, regions, secrets
outputs.tfIP addresses, SSH commands, URLs
terraform.tfvarsEnvironment-specific values (gitignored)
staging/Staging environment (separate state)

Firewall Rules

allow-odoo       : tcp:30069 (Odoo web)
allow-portainer   : tcp:30778 (Portainer)
allow-http-https  : tcp:80,443
allow-ssh         : tcp:22

2.3 — VPC Network & Firewall

🟢 ✅ Hoàn thành

VPC default network với firewall rules cho Odoo, Portainer, SSH, HTTP/HTTPS.

gcloud compute firewall-rules list --project=newskyexpress
# allow-odoo (30069), allow-portainer (30778), allow-ssh (22), allow-http (80,443)

2.4 — Production VM + k3s

🟢 ✅ Hoàn thành
VM Nameodoo-production
Machine Typee2-medium (2 vCPU, 4GB RAM)
OSUbuntu 22.04 LTS
Static IP35.240.147.252
Disk60GB SSD persistent
K8sk3s v1.28+ (CNCF certified Kubernetes)

k3s Info

k3s = Lightweight certified Kubernetes (by Rancher/SUSE)
- CNCF Certified: ✅ 100% compatible K8s API
- Memory footprint: ~512MB vs GKE ~2GB+
- Cost: chỉ trả tiền VM (~$25/tháng) vs GKE ($70+ cluster fee)

2.5 — Staging VM

🟢 ✅ Hoàn thành
VM Nameodoo-staging
Machine Typee2-small (2 vCPU, 2GB RAM) — Spot instance
Static IP136.110.0.245
Odoo URLhttp://136.110.0.245:30069

2.6 — PostgreSQL 16 Database

🟢 ✅ Hoàn thành

PostgreSQL 16 chạy trong Kubernetes pod với Persistent Volume Claim (PVC) 20GB SSD.

VersionPostgreSQL 16
StoragePVC 20GB SSD (host-path)
UID70 (postgres user)
BackupManual pg_dump → GCS (planned: daily cron)

Troubleshooting đã xử lý

# Permission fix (UID 70 for PG, UID 101 for Odoo)
scripts/fix_perms.sh — chown -R 70:70 /data/pg, chown -R 101:101 /data/odoo

2.7 — Odoo 17 Container Deployment

🟢 ✅ Hoàn thành

Odoo 17 CE chạy trong Kubernetes pod, expose qua NodePort 30069.

Dockerfile

FROM odoo:17
COPY ./addons /mnt/extra-addons
# Bake custom modules vào image

K8s Resources

ResourceChi tiết
Deployment1 replica, Odoo 17 CE
ServiceNodePort 30069 → 8069
PVC (filestore)20GB host-path
PVC (addons)Host-path /data/addons

2.8 — Custom Modules (22 addons)

🟢 ✅ Hoàn thành

22 custom modules đã được deploy vào Odoo 17 qua CI/CD pipeline.

GitHub: newlighttechcloud-abc/odoo-custom-modules
Branch: production → auto-deploy khi push

2.9 — CI/CD Pipeline

🟢 ✅ Hoàn thành

Tier C CI/CD: GitHub Actions → SSH → git pull → copy addons → kubectl rollout restart

Workflow: .github/workflows/deploy.yml

Trigger: push to 'production' branch
Steps:
  1. SSH vào Production VM
  2. cd /home/odoo-custom-modules && git pull
  3. cp -r addons/* /data/addons/
  4. kubectl rollout restart deployment/odoo
  5. Verify: curl http://localhost:30069

GitHub Secrets

SecretMục đích
PROD_SSH_KEYSSH private key cho Production VM
PROD_HOST35.240.147.252
PROD_USERodoo-deploy

2.10-2.12 — Database Restore & Data Migration

🟢 ✅ Hoàn thành

Database từ môi trường cũ đã được restore thành công lên Production.

Scripts đã tạo

ScriptChức năng
fix_perms.shFix ownership UID 70/101 cho PG/Odoo PVCs
fix_modules.shClear asset cache, run module update
fix_broken_views.shRemove broken views (delivery_address field)
fix_addons_mount.shReplace symlinks with real file copies
update_all_modules.shFull module update after changes

2.13 — Portainer (Container Management UI)

🟢 ✅ Hoàn thành
URLhttp://35.240.147.252:30778
VersionPortainer CE (Agent mode)
FeaturesContainer logs, restart, resource monitoring

2.14 — Backup Strategy

🟢 ✅ Hoàn thành

Database backup via pg_dump. Filestore backup via rsync/tar. Planned: daily cron to GCS bucket.

2.15 — Cloud Monitoring & Uptime

🟡 ⏳ Đang triển khai (60%)

GCP Compute Monitoring active. Uptime checks planned khi có domain.

2.16 — SSL/HTTPS

🔴 🚫 Blocked — Chờ domain

Cần domain từ Bên B để cấu hình SSL cert (Let's Encrypt) + reverse proxy.

2.17 — Security Hardening

🟢 ✅ Hoàn thành

SSH key-only auth, firewall whitelist, IAM least privilege, secrets in GitHub Secrets.

2.18 — Biên bản nghiệm thu GĐ2

🟡 ⏳ Chờ hoàn thành 2.15, 2.16

Sẽ ký khi tất cả tasks GĐ2 hoàn thành.