Infra 自架基礎建設系列

這個系列記錄從零建立自架 Infra 的完整知識體系。 每篇文章針對一個主題,涵蓋核心概念、實作範例、常見問題與風險。 文章按依賴順序排列,從最底層的 Network 開始,往上堆疊到自動化與編排。


系列全景圖(概念層次)

flowchart TD
    L1[L1 Network & Access] --> L2[L2 CI/CD & Delivery]
    L2 --> L3[L3 Data & Storage]
    L3 --> L4[L4 Observability]
    L4 --> L5[L5 Application Middleware]
    L5 --> L6[L6 Security & Resilience]
    L6 --> L7[L7 Automation & Orchestration]

    style L1 fill:#e3f2fd,stroke:#1976d2
    style L2 fill:#e8f5e9,stroke:#388e3c
    style L3 fill:#fff3e0,stroke:#f57c00
    style L4 fill:#fce4ec,stroke:#c62828
    style L5 fill:#ede7f6,stroke:#5e35b1
    style L6 fill:#f3e5f5,stroke:#8e24aa
    style L7 fill:#e0f7fa,stroke:#00838f

L1 — Network & Access(基座層)

#主題說明
01Network & DNS固定入口、網段切分、DNS 命名規則
02Reverse Proxy + TLS(Nginx)HTTPS 加密、反向代理、安全 header
03Container Runtime(Docker)標準化部署基座、namespace/cgroup、multi-stage build
04Identity & AccessSSO/OAuth、RBAC/ABAC、Onboarding/Offboarding

L2 — CI/CD & Delivery(交付層)

#主題說明
05CDGitLab CI pipeline、DORA metrics、標準化部署流程
06 Rollback分支策略、Semantic Versioning、回滾
07Container Registry(Harbor)私有映像庫、安全掃描、保留策略
08CD 實戰模板Pipeline 模板化、多環境部署、Monorepo

L3 — Data & Storage(資料層)

#主題說明
09Secrets & Config.env 管理、secrets 注入、rotation
10Storage Management(MinIO)物件儲存、Bucket 分層、lifecycle rule
11Database(PostgreSQL)連線池(PgBouncer)、備份還原、效能調校
12Database Landscape從 Sheets 到 Vector DB,選型決策框架
13PostgreSQL AdvancedEXPLAIN、Partition、Vacuum、Replication
14Elasticsearch Deep DiveMapping、Shard、ILM、與 PostgreSQL FTS 的分界線

L4 — Observability(可觀測層)

#主題說明
15Metrics & MonitoringPrometheus + Grafana、PromQL、Dashboard
16ELK)集中式日誌、結構化日誌、ILM
17Alerts & ChatOps告警分級、Alertmanager、Runbook
18Alert Webhook IntegrationSlack/Discord/Line 通知、冪等性
19Multi-node Monitoring多節點 Prometheus、Service Discovery

L5 — Application Middleware(中介層)

#主題說明
20 ETL排程任務、冪等性、checkpoint、Pydantic 驗證
21API Gateway & RoutingKong DB-less、限流、JWT 驗證、版本管理
22Event-driven & QueueOutbox pattern、DLQ、Redis→RabbitMQ→Kafka 選型
23WebSocket心跳機制、指數退避重連、多節點擴展
24Serverless適用場景、Cold Start、混合部署

L6 — Security & Resilience(安全與韌性)

#主題說明
25Environment SeparationDev/Staging/Prod 隔離、資源規劃
26Security ScanningSAST/SCA/DAST/SBOM、Pipeline 整合
27Secrets & Certificate ManagementVault、cert-manager、Break-glass
28Backup & Disaster RecoveryRPO/RTO、3-2-1 原則、DR 演練
29DNS、負載均衡與 CDNDNS 策略、L4/L7 LB、Cloudflare CDN
30Application SecurityOWASP Top 10、Secure Coding、AI 安全風險

L7 — Automation & Orchestration(自動化與編排)

#主題說明
31Infrastructure as CodeTerraform、Ansible、Drift 偵測、GitOps
32Docker Compose Cookbook四套即用模板:Web App、監控、日誌、開發環境
33Kubernetes Intro從 Compose 到 K8s:核心概念、清單範本、選型建議

閱讀建議

入門者

  • 先讀 L1(01-04),建立基礎網路與部署概念
  • 再讀 L2(05-08),形成可交付的 pipeline
  • 最後讀 L4(15-17),建立可觀測能力

已有經驗

  • 直接從最痛的主題開始(例如 Logs、Alerts、IaC)
  • 透過 L6(26-28)補足安全與備援

模板導向


進階路線

Level 1: Docker 化

把一個 Web App 容器化(Dockerfile + docker-compose) 相關:Container RuntimeCompose Cookbook

Level 2: 加 nginx + HTTPS

在前面加 nginx 反向代理 + Let’s Encrypt HTTPS 相關:Reverse Proxy + TLS

Level 3: CI/CD Pipeline

建立自動化部署流程 相關:CDGitLab Templates

Level 4: 監控三件套

Prometheus + Grafana + Loki 相關:Monitoring免費午餐架構

Level 5: K8s + 自動擴展

從 Docker Compose 遷移到 Kubernetes 相關:K8s 入門Compose vs K8s


相關系列

策展地圖