GitOps Deep Dive 2025

GitOps ลึกๆ

Argo CD vs Flux CD: คู่เปรียบเทียบเครื่องมือ GitOps ยอดนิยม

คู่มือเปรียบเทียบอย่างละเอียดระหว่างสองเครื่องมือ GitOps ยอดนิยม ตั้งแต่หลักการพื้นฐานจนถึงการติดตั้งและใช้งานจริง

Argo CD Flux CD GitOps

GitOps Architecture Pattern

Git Repository $ git push main $ kubectl apply -f Argo CD Flux CD Kubernetes Cluster Control Plane Git Operator Workloads Deployment Service ConfigMap Self-healing

GitOps คืออะไรและทำไมต้องสำคัญ?

นิยามของ GitOps

GitOps คือวิธีการดำเนินการและบริหารจัดการระบบ IT โดยใช้ Git เป็นแหล่งข้อมูลเดียว (Single Source of Truth) สำหรับการ deploying และ managing infrastructure

หลักการหลัก: ทุกการเปลี่ยนแปลงต้องถูก commit และ version control ใน Git Repository

หลักการ 4 ข้อของ GitOps

  • Declarative: สถานะของระบบถูกอธิบายด้วยไฟล์ YAML (Declarative)
  • Version Controlled: ทุกการเปลี่ยนแปลงถูกบันทึกใน Git พร้อมประวัติ
  • Self-Healing: System สามารถตรวจสอบและกู้คืนสถานะเองอัตโนมัติ
  • Continuity: ใช้ Git Branching สำหรับการทดสอบและ release

ข้อดีของ GitOps

  • Visibility: เห็นประวัติการเปลี่ยนแปลงทั้งหมดใน Git
  • Recovery: สามารถ rollback ได้ง่ายด้วย git revert
  • collaboration: Developer และ Ops ทำงานร่วมกันได้ดี
  • Security: Review ผ่าน pull request แบบ standard

GitOps ไม่ใช่การ Push แต่เป็น Pull Model!

หลักการสำคัญของ GitOps คือการใช้ Pull-based deployment แทนการ push:
Push Model: Git → CI/CD → Kubernetes Pull Model: Git → Agent (Argo/Flux) → Kubernetes

เปรียบเทียบ Argo CD vs Flux CD

Argo CD

CNCF Graduated Project - 2022

ลักษณะเด่น

  • UI/UX ยอดเยี่ยม: Web Dashboard ที่สวยงามและใช้งานง่าย
  • Centralized: ตัว Central Server จัดการทุก Clusters
  • Application Set: รองรับการ deploy หลาย Applications พร้อมกัน
  • RBAC: มีระบบควบคุมสิทธิ์ที่สมบูรณ์
กรณีใช้งานที่เหมาะ:

องค์กรที่ต้องการ UI สำหรับ monitoring และการจัดการ Multiple Clusters

Flux CD

CNCF Graduated Project - 2023

ลักษณะเด่น

  • Modular: แยกเป็นControllers แต่ละตัว (Git, Kustomize, Helm, etc.)
  • Kubernetes-Native: ใช้ CRDs (Custom Resource Definitions) ทั้งหมด
  • Self-Healing: ตรวจสอบและกู้คืนสถานะอัตโนมัติทุก 6 ชั่วโมง
  • Kustomize-First: ออกแบบมาเพื่อใช้กับ Kustomize เป็นหลัก
กรณีใช้งานที่เหมาะ:

ทีมที่ชอบ Infrastructure-as-Code แบบ full automation และ Kubernetes-native approach

ตารางเปรียบเทียบแบบละเอียด

หัวข้อ Argo CD Flux CD
พัฒนาโดย Intuit (ปัจจุบันเป็น CNCF) Weaveworks (ปัจจุบันเป็น CNCF)
Graduated CNCF Graduated (2022) CNCF Graduated (2023)
Deployment Model Centralized Distributed
UI Dashboard มี (Web UI) ไม่มี (CLI only)
API มี (gRPC) มี (HTTP API)
Helm Support ดีมาก ดีมาก
Kustomize Support ดี ยอดเยี่ยม (-primary)
Self-Healing มี มี (ทุก 6h)
Multi-Cluster ง่าย (Central Server) ต้องตั้งค่าเพิ่ม
Learning Curve ปานกลาง (UI ง่าย) steep (CRDs, Kustomize)
Resource Usage มากกว่า (Server + Repo) น้อยกว่า (Agent-based)

คำแนะนำในการเลือกใช้

เลือก Argo CD หาก:
  • • ต้องการ UI สำหรับดูสถานะและ debug
  • มีหลาย clusters ที่ต้องจัดการ
  • ทีมต้องการ RBAC และ permission control
  • ต้องการ integrating กับ existing system
เลือก Flux CD หาก:
  • ชอบ Kubernetes-native approach
  • ต้องการ minimal resource usage
  • ใช้ Kustomize เป็นหลัก
  • ชอบ pure CLI-based workflow

ติดตั้ง Argo CD และ Flux CD

ติดตั้ง Argo CD

ขั้นตอนการติดตั้งแบบ standalone

สิ่งที่ต้องเตรียม

  • Kubernetes Cluster: Kubernetes 1.25+ (recommended)
  • kubectl: Version recent (for apply)
  • Cluster admin: สามารถ create cluster-scoped resources
  • Port: ต้องเปิด port 443, 8080, 8083

1 ติดตั้ง Argo CD ด้วย kubectl

สร้าง namespace และติดตั้ง Argo CD แบบ standalone:

# Create namespace kubectl create namespace argocd # Install Argo CD (standalone mode) kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

2 รอให้ pods พร้อมใช้งาน

# รอ 3-5 นาที ให้ pods ทั้งหมด ready kubectl -n argocd get pods # Expected output: # argocd-repo-server-xxx 1/1 Running # argocd-server-xxx 1/1 Running # argocd-dex-server-xxx 1/1 Running # argocd-redis-xxx 1/1 Running

3 เข้าถึง Web UI

ใช้ Port-forward หรือ Ingress:

# Method 1: Port-forward (for testing) kubectl -n argocd port-forward svc/argocd-server 8080:443 # Method 2: Via LoadBalancer kubectl patch svc argocd-server -n argocd -p '{"spec":{"type":"LoadBalancer"}}' # Method 3: Ingress (production) # See: https://argo-cd.readthedocs.io/en/stable/operator-manual/ingress/

Username: admin
Password: ดูจาก secret `argocd-initial-admin-secret`

4 เปลี่ยนรหัสผ่าน

# เปลี่ยนรหัสผ่าน admin argocd account update-password # หรือใช้ CLI: argocd account update-password
ตรวจสอบสถานะ

เมื่อ Argo CD พร้อมใช้งาน คุณจะเห็น UI ที่ http://localhost:8080

ติดตั้ง Flux CD

ขั้นตอนการติดตั้งแบบ modular controllers

สิ่งที่ต้องเตรียม

  • Kubernetes Cluster: Kubernetes 1.24+ (recommended)
  • flux CLI: สำหรับ install และ manage
  • Cluster admin: สามารถ create CRDs
  • Git repository: สำหรับ storing manifests

1 ติดตั้ง Flux CLI

# macOS (Homebrew) brew install fluxcd/tap/flux # Linux (curl) curl -s https://fluxcd.io/install.sh | sudo bash # Linux (deb package) wget -q https://github.com/fluxcd/flux2/releases/latest/download/flux_$(dpkg --print-architecture).deb sudo dpkg -i flux_*.deb # Verify installation flux --version

2 Bootstrap Flux เข้า Cluster

หลักการ Bootstrap คือการให้ Flux สร้าง CRDs และ configure self:

# Bootstrap Flux ด้วย Git repository flux bootstrap gitlab \ --hostname=gitlab.example.com \ --namespace=flux-system \ --repository=flux-config \ --branch=main \ --path=clusters/my-cluster

หรือใช้ GitHub:

# Bootstrap สำหรับ GitHub flux bootstrap github \ --owner=your-username \ --repository=flux-config \ --branch=main \ --personal \ --path=clusters/my-cluster

3 ตรวจสอบว่าติดตั้งสำเร็จ

# Check components flux check # Expected: all checks passed ✔ gateway-api: no issues found ✔ kube version: soho compatible ✔ git provider: healthy ✔ helm driver: syncable

4 ติดตั้ง Controllers เพิ่มเติม

Flux ประกอบด้วย Controllers หลายตัว:

# ติดตั้ง Kustomize Controller flux install --component=kustomize # ติดตั้ง Helm Controller flux install --component=helm # ติดตั้ง Image Reflection Controller flux install --component=image-reflect # ติดตั้ง Image Automation Controller flux install --component=image-automation # หรือติดตั้งพร้อมกัน flux install --components-extra=kustomize,helm,image-automation,image-reflect

5 สร้าง First Sync

สร้าง App แรกที่จะ sync จาก Git Repository:

# สร้าง Kustomization untuk sync flux create kustomization \ --name=apps \ --target-namespace=production \ --source=GitRepository/apps \ --path=./apps \ --prune=true \ --interval=5m

หลังจากนี้ Flux จะ sync จาก Git ทุก 5 นาที และกู้คืนสถานะอัตโนมัติ

กรณีใช้งานจริง (Use Cases)

Large Enterprise Multi-Cluster

องค์กรขนาดใหญ่ที่มีหลาย clusters

แนะนำ: Argo CD

Argo CD ดีกว่าสำหรับการจัดการหลาย clusters ด้วย Central Server และมี UI ที่ดีสำหรับ monitoring

Use case: บริษัทที่มี clusters หลายอัน (Dev, Staging, Prod, multiple regions)

Cloud-Native Startup

Startup ที่ใช้ cloud-native approach

แนะนำ: Flux CD

Flux CD เหมาะกับ team ที่ชอบ full automation และใช้ GitOps แบบเต็มรูปแบบ

Use case: บริษัทที่ไม่มี DevOps team ชัดเจน และต้องการ minimal manual intervention

Migrating from Jenkins

องค์กรที่กำลัง migrate จาก traditional CI/CD

แนะนำ: Argo CD

Argo CD มี UI ที่ดีกว่าสำหรับ transition และมี integration ที่หลากหลาย

Use case: องค์กรที่ต้องการ step-by-step migration พร้อม visibility

Low-Resource Environments

Environment ที่ resource มีจำกัด

แนะนำ: Flux CD

Flux CD มี resource usage น้อยกว่า เพราะใช้ agent-based model

Use case: องค์กรที่ใช้ clusters เล็กหรือมีข้อจำกัดด้าน compute

Hybrid Approach - ใช้ทั้งสอง tool

บางองค์กรใช้ทั้ง Argo CD และ Flux CD ใน environment เดียวกัน:

  • Argo CD: ใช้สำหรับ production clusters (มี UI และ RBAC)
  • Flux CD: ใช้สำหรับ development/staging (lightweight, automation)
  • Split teams: DevOps ใช้ Argo, Developers ใช้ Flux

Best Practices ในการใช้งาน GitOps

Version Control Everything

ทุกอย่างใน Git - including configuration, manifests, dan security policies. ใช้ branches สำหรับ environments ต่างๆ

Use Namespaces Separate

แยก GitOps tool (Argo/Flux) แต่ละ cluster ด้วย separate namespace (เช่น argocd, flux-system)

Secret Management

อย่าเก็บ secrets ใน Git! ใช้ External Secrets Operator (ESO), Sealed Secrets, หรือ Vault

Manual Override Bad

ก็เลยไม่ควรใช้ kubectl edit/apply โดยตรง! ทุกการเปลี่ยนแปลงต้องผ่าน Git PR process

Use Kustomize/Helm

ใช้ Kustomize overlays หรือ Helm values สำหรับ environments ต่างๆ แทนการ duplicating manifests

Monitoring is Key

ติดตั้ง monitoring และ alerting สำหรับ GitOps tool ด้วย ตรวจสอบ sync health และ drift detection

Troubleshooting Common Issues

Argo CD Repo Server Connection Failed

Error: dial tcp x.x.x.x:443: connect: connection refused

Solution: Check network policies, firewall rules, และว่า repo-server pod ทำงานอยู่

# ตรวจสอบสถานะ pods kubectl -n argocd get pods kubectl -n argocd logs argocd-repo-server-xxx # Check service kubectl -n argocd get svc argocd-repo-server

Flux Git Source Not Found

Error: unable to clone 'https://github.com/...': repository not found

Solution: Check Git credentials, ว่า repository public/private, และ network access

# ตรวจสอบ Flux GitRepository status flux get sources git # ตรวจสอบ secret kubectl -n flux-system get secrets # Reconcile flux reconcile source git flux-system

Drift Detection

Issue: สถานะไม่ตรงกับ Git (Out of Sync)

Solution: ใช้ Argo CD UI หรือ CLI เพื่อ sync / rollback หรือใช้ auto-sync

# Argo CD - Sync Manual argocd app sync my-app # Argo CD - Enable Auto-Sync argocd app set my-app --auto-sync # Flux - Reconcile flux reconcile kustomization apps

สรุปและคำแนะนำ

GitOps คืออนาคตของการ Deploy ครับ!

ArgoCD vs FluxCD - สรุปสั้นๆ

  • Argo CD: UI ยอดเยี่ยม, Centralized, ดีสำหรับ multi-cluster
  • Flux CD: Kubernetes-native, Modular, Resource-efficient
  • ทั้งสอง tool เป็น CNCF Graduated Projects (มาตรฐานสูง)
  • เลือกตาม use case และ team preference ได้เลย

Recommendations

  • 1
    เริ่มต้นด้วย Argo CD ถ้าต้องการ UI ง่ายๆ
  • 2
    ลอง Flux CD ถ้าชอบ automation และ CLI work
  • 3
    ทดลองติดตั้งใน dev cluster จริงก่อน deploy จริง
  • 4
    ติดตั้ง monitoring และ alerting พร้อมกัน

บทความนี้ใช้เวลาเขียนประมาณ 15 นาที - หวังว่าจะมีประโยชน์กับทุกคนครับ! 🚀

บทความที่เกี่ยวข้อง