สถาปัตยกรรม Argo CD อธิบายทุก Component แบบเข้าใจง่าย

บทนำ

Argo CD เป็นเครื่องมือ GitOps ที่มีสถาปัตยกรรมที่ประกอบด้วยหลายคอมโพเนนต์ที่ทำงานร่วมกัน เพื่อให้เกิด Declarative Deployment ที่มีประสิทธิภาพ บทความนี้จะอธิบายสถาปัตยกรรมของ Argo CD และการทำงานของแต่ละคอมโพเนนต์แบบรายละเอียด

สถาปัตยกรรมโดยรวมของ Argo CD

Argo CD ประกอบด้วยหลาย Microservices ที่ทำงานร่วมกันในรูปของ Kubernetes Deployment โดยแต่ละคอมโพเนนต์มีบทบาทและความรับผิดชอบที่เฉพาะเจาะจง ซึ่งจะอธิบายต่อไป

Argo CD API Server

บทบาท

API Server เป็นหัวใจของ Argo CD ที่ให้บริการ REST API และ gRPC Interface สำหรับการสื่อสารระหว่าง Web UI, CLI และ External System

หน้าที่หลัก

  • ให้บริการ REST API สำหรับการจัดการ Applications
  • ให้บริการ WebSocket สำหรับ Real-time Updates
  • จัดการ User Authentication และ Authorization
  • บันทึก Audit Logs สำหรับการติดตามการเปลี่ยนแปลง
  • ให้บริการ OAuth2/OIDC Integration

ทรัพยากรที่ใช้

ปกติ API Server ใช้ Memory ประมาณ 100-500 MB ขึ้นอยู่กับจำนวน Applications และ Clusters ที่มี

Application Controller

บทบาท

Application Controller เป็นคอมโพเนนต์ที่สำคัญที่สุดใน Argo CD ที่มีหน้าที่ในการติดตามสถานะของ Application และทำให้สถานะจริง (Actual State) ตรงกับสถานะที่ต้องการ (Desired State)

หน้าที่หลัก

  • ติดตามสถานะของ Git Repository อย่างต่อเนื่อง
  • ติดตามสถานะของ Resources ใน Cluster
  • ทำการ Sync (Synchronization) เมื่อสถานะไม่ตรงกัน
  • จัดการ Sync Strategy (Automated, Manual, Selective)
  • สร้าง Hooks สำหรับการทำงานเพิ่มเติมเมื่อ Sync สำเร็จหรือล้มเหลว

กลไกการทำงาน

Application Controller จะ Reconciliation Loop ทำงานซ้ำ ๆ ในช่วงเวลาที่กำหนด (ปกติ 3 นาที) เพื่อตรวจสอบว่า Application ได้ Sync กับ Git Repository หรือไม่

Repository Server

บทบาท

Repository Server มีหน้าที่ในการเชื่อมต่อกับ Git Repository และดึงข้อมูลการตั้งค่า (Configuration) มาจาก Git

หน้าที่หลัก

  • Clone และ Fetch Git Repository
  • Render Templates (Helm, Kustomize, Jsonnet)
  • จัดการเวอร์ชันของ Git และ Branches
  • ให้บริการ gRPC API สำหรับการเรียก
  • Cache Git Data เพื่อประสิทธิภาพ

การทำงาน

Repository Server สามารถใช้ได้กับหลาย Template Language เช่น:

  • Helm – สำหรับ Helm Charts
  • Kustomize – สำหรับ Kubernetes Manifest Overlay
  • Jsonnet – สำหรับ Dynamic Configuration
  • Plain YAML – สำหรับ Kubernetes Manifest ธรรมชาติ

Dex Server (OAuth2/OIDC Provider)

บทบาท

Dex Server ให้บริการ OAuth2 และ OIDC (OpenID Connect) สำหรับการทำ Authentication แบบ Single Sign-On (SSO)

หน้าที่หลัก

  • ให้บริการ OAuth2 Authorization Endpoint
  • ให้บริการ OIDC Token Endpoint
  • เชื่อมต่อกับ External Identity Providers เช่น GitHub, GitLab, Google
  • จัดการ User Session

การตั้งค่า

Dex Server สามารถตั้งค่าให้ใช้งาน OIDC Provider ต่าง ๆ เช่น:

  • GitHub
  • GitLab
  • Google
  • Microsoft Entra ID (Azure AD)
  • Okta
  • Keycloak

Redis

บทบาท

Redis ใช้เป็น Cache Store สำหรับการเก็บข้อมูล Session และ Cache อื่น ๆ

หน้าที่หลัก

  • เก็บ User Session Data
  • เก็บ Cluster Information Cache
  • เก็บ Git Repository Cache
  • ให้บริการ Distributed Lock สำหรับการ Coordination

ความสำคัญ

Redis เป็นส่วนที่สำคัญสำหรับการเพิ่มประสิทธิภาพและการลดการโหลด Git Repository บ่อย ๆ

Notification Controller (ArgoCD Notifications)

บทบาท

Notification Controller ใช้ส่งการแจ้งเตือนเมื่อสถานะของ Application มีการเปลี่ยนแปลง

หน้าที่หลัก

  • ส่ง Notification ผ่าน Slack, Teams, Email
  • ส่ง Webhook Events ไปยัง External System
  • จัดการ Notification Template
  • ให้การแจ้งเตือนเมื่อ Sync สำเร็จหรือล้มเหลว

Notification Channel ที่รองรับ

  • Slack
  • Microsoft Teams
  • Email
  • Discord
  • Telegram
  • Webhook

Argo CD Repo Server Cache

บทบาท

ทำให้ Repository Server มีประสิทธิภาพสูงขึ้นโดยเก็บ Git Data ไว้ใน Cache

รายละเอียด

  • ลดการเข้าถึง Git Repository บ่อย ๆ
  • เร่งความเร็วในการ Render Templates
  • ลดการใช้ Bandwidth

Kubernetes API Server Connector

บทบาท

ให้บริการการเชื่อมต่อระหว่าง Argo CD กับ Kubernetes API Server เพื่อดึง Resource Status

หน้าที่หลัก

  • ดึง Resource Status จาก Kubernetes
  • Apply Manifest ไปยัง Kubernetes
  • Watch Resource Change Events

โครงสร้างการ Deploy ของ Argo CD

Argo CD ปกติจะ Deploy ใน Namespace ชื่อ argocd ดังนี้:

argocd/
├── argocd-api-server (Deployment)
├── argocd-application-controller (Deployment)
├── argocd-repo-server (Deployment)
├── argocd-dex-server (Deployment)
├── argocd-redis (Deployment)
├── argocd-notifications-controller (Deployment)
├── argocd-server (Service - Web UI)
├── argocd-repo-server-service (Service - gRPC)
└── ConfigMaps, Secrets, PersistentVolume

ข้อมูลการไหลของ Argo CD

Sync Flow

  1. User สั่ง Sync ผ่าน Web UI หรือ CLI
  2. API Server รับคำขอและสง Message ไปยัง Application Controller
  3. Application Controller ร้องขอ Repository Server ให้ดึงข้อมูลจาก Git
  4. Repository Server Clone/Fetch Git Repository และ Render Templates
  5. Application Controller ทำการ Diff เพื่อดูการเปลี่ยนแปลง
  6. Application Controller Apply Manifest ไปยัง Kubernetes Cluster
  7. Notification Controller ส่งการแจ้งเตือนถึงผล

การใช้งาน Argo CD บน ผู้ให้บริการโฮสติ้ง Cloud VPS

หากคุณต้องการติดตั้ง Argo CD บน ผู้ให้บริการโฮสติ้ง Cloud VPS ของเรา คุณจะสามารถได้รับ:

  • ทรัพยากร CPU/Memory ที่เพียงพอสำหรับ Argo CD
  • Network Bandwidth ที่สูงสำหรับการดึง Git Data
  • ความสถียรของ Infrastructure 99.9% Uptime SLA
  • ความยืดหยุ่นในการขยายตัวตามความต้องการ
  • ความปลอดภัยด้วย Firewall และ Security Configuration

นอกจากนี้ ผู้ให้บริการโฮสติ้ง Cloud Hosting ยังเป็นตัวเลือกที่ดีสำหรับการเก็บ Git Repository บน Server ที่มีความเสถียร

บทสรุป

Argo CD มีสถาปัตยกรรมที่ประกอบด้วยหลาย Microservices ที่ทำงานร่วมกัน โดยแต่ละคอมโพเนนต์มีบทบาทที่สำคัญในการให้ GitOps Workflow ทำงานได้อย่างมีประสิทธิภาพ การเข้าใจสถาปัตยกรรมนี้จะช่วยให้คุณสามารถตั้งค่า Argo CD ได้อย่างถูกต้องและแก้ไขปัญหาได้อย่างมีประสิทธิภาพ