ai

ArgoCD ApplicationSet Container Orchestration

ArgoCD ApplicationSet Container Orchestration
DevOps

โดย อ. บอมกิตติทัศน์เจริญพนาสิทธิ์ | อัปเดต 24 ก. พ. 2026 | อ่าน 16 นาที

GitOps คืออะไร — แนวคิดพื้นฐาน

ArgoCD ApplicationSet Container Orchestration

GitOps เป็นแนวคิดที่ Weaveworks นำเสนอในปี 2017 หลักการคือใช้ Git Repository เป็น Single Source of Truth สำหรับ Infrastructure และ Application ทุกการเปลี่ยนแปลง (Deploy, Config Change, Scale) ต้องผ่าน Git Commit โดยส่ง Pull Request, Code Review, Approve แล้ว Merge จากนั้น GitOps Operator จะ Sync ให้ Cluster ตรงกับ Git อัตโนมัติ

ข้อดีของ GitOps ได้แก่ Audit Trail ทุกการเปลี่ยนแปลงมี Git History, Rollback ง่าย แค่ Revert Git Commit, Consistency ทุก Environment ตรงกับ Git, Security ไม่ต้องให้ CI/CD เข้าถึง Cluster โดยตรง (Pull-based) และ Self-healing ถ้ามีคนแก้ Cluster โดยตรง ArgoCD จะ Sync กลับให้ตรง Git

ArgoCD คืออะไร — GitOps CD สำหรับ Kubernetes

ArgoCD เป็น Declarative GitOps Continuous Delivery Tool สำหรับ Kubernetes เป็น CNCF Graduated Project ที่นิยมที่สุดในหมวด GitOps ทำงานโดยเปรียบเทียบ Desired State (ใน Git) กับ Actual State (บน Cluster) ถ้าต่างกันจะแสดงว่า OutOfSync และ Sync ให้ตรงกันอัตโนมัติ (ถ้าตั้ง Auto-sync) หรือรอ Manual Sync

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ Phishing 202602181318

ArgoCD มี Web UI ที่สวยงามมากแสดง Application Status, Resource Tree, Diff ระหว่าง Git กับ Cluster, Sync History และ Rollback ได้จาก UI เลยนอกจากนี้ยังมี CLI, gRPC API และ Webhook สำหรับ Automation

ติดตั้ง ArgoCD บน Kubernetes

# ติดตั้งด้วย kubectl

kubectl create namespace argocd

kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml



# หรือติดตั้งด้วย Helm (แนะนำ)

helm repo add argo https://argoproj.github.io/argo-helm

helm install argocd argo/argo-cd \

 --namespace argocd \

 --create-namespace \

 --set server.service.type=LoadBalancer



# ดึง Admin Password

kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d



# ติดตั้ง CLI

curl -sSL -o argocd https://github.com/argoproj/argo-cd/releases/latest/download/argocd-linux-amd64

chmod +x argocd && sudo mv argocd /usr/local/bin/



# Login

argocd login <ARGOCD_SERVER> --username admin --password <PASSWORD>

สร้าง Application แรก — Sync จาก Git

apiVersion: argoproj.io/v1alpha1

kind: Application

metadata:

 name: my-api

 namespace: argocd

spec:

 project: default

 source:

 repoURL: https://github.com/myorg/k8s-manifests.git

 targetRevision: main

 path: apps/my-api/overlays/production

 destination:

 server: https://kubernetes.default.svc

 namespace: production

 syncPolicy:

 automated:

 prune: true # ลบ Resource ที่ไม่มีใน Git

 selfHeal: true # แก้ไข Manual Change กลับให้ตรง Git

 allowEmpty: false

 syncOptions:

 - CreateNamespace=true

 - PrunePropagationPolicy=foreground

 retry:

 limit: 5

 backoff:

 duration: 5s

 factor: 2

 maxDuration: 3m

Sync Policy — Auto vs Manual

Policyลักษณะเหมาะกับ
Manual Syncต้องกด Sync เองProduction ที่ต้อง Approval ก่อน Deploy
Auto SyncSync อัตโนมัติเมื่อ Git เปลี่ยนDev/Staging ที่ต้องการ Deploy ทันที
Auto Sync + Pruneลบ Resource ที่ไม่มีใน Git ด้วยต้องการ Git เป็น Truth 100%
Auto Sync + Self-healแก้ Manual Change กลับป้องกัน Drift จาก kubectl edit

ApplicationSet — สร้างหลาย Application จาก Template

ApplicationSet เป็น CRD ที่สร้าง ArgoCD Application หลายตัวจาก Template เดียวแทนที่จะเขียน Application YAML ซ้ำๆสำหรับทุก Service หรือทุก Cluster

แนะนำเพิ่มเติม — ระบบเทรดของ iCafeForex

apiVersion: argoproj.io/v1alpha1

kind: ApplicationSet

metadata:

 name: microservices

 namespace: argocd

spec:

 generators:

 - list:

 elements:

 - name: user-api

 namespace: user

 - name: order-api

 namespace: order

 - name: payment-api

 namespace: payment

 - name: notification-api

 namespace: notification

 template:

 metadata:

 name: '{{name}}'

 spec:

 project: default

 source:

 repoURL: https://github.com/myorg/k8s-manifests.git

 targetRevision: main

 path: 'apps/{{name}}/overlays/production'

 destination:

 server: https://kubernetes.default.svc

 namespace: '{{namespace}}'

 syncPolicy:

 automated:

 prune: true

 selfHeal: true

ApplicationSet นี้สร้าง 4 Application (user-api, order-api, payment-api, notification-api) จาก Template เดียวถ้าเพิ่ม Service ใหม่แค่เพิ่ม Element ใน List

Generator Types — List, Cluster, Git, Matrix

GeneratorSourceUse Case
ListStatic List ใน YAMLจำนวน Service/Cluster น้อยและคงที่
ClusterArgoCD Cluster SecretsDeploy ไปทุก Cluster ที่ลงทะเบียนกับ ArgoCD
Git DirectoryDirectory ใน Git RepoMonorepo ที่แต่ละ Directory คือ 1 Service
Git FileJSON/YAML File ใน GitConfig File กำหนด Parameter ต่อ Environment
MatrixCombine 2 GeneratorsDeploy ทุก Service ไปทุก Cluster (Cartesian Product)
MergeMerge หลาย GeneratorsOverride Parameter ต่อ Cluster
Pull RequestGitHub/GitLab PRสร้าง Preview Environment ต่อ PR

Multi-cluster Deployment ด้วย ApplicationSet

# Deploy ทุก Service ไปทุก Cluster ด้วย Matrix Generator

apiVersion: argoproj.io/v1alpha1

kind: ApplicationSet

metadata:

 name: multi-cluster-apps

 namespace: argocd

spec:

 generators:

 - matrix:

 generators:

 # Generator 1: Clusters

 - clusters:

 selector:

 matchLabels:

 env: production

 # Generator 2: Services

 - git:

 repoURL: https://github.com/myorg/k8s-manifests.git

 revision: main

 directories:

 - path: apps/*

 template:

 metadata:

 name: '{{path.basename}}-{{name}}'

 spec:

 project: default

 source:

 repoURL: https://github.com/myorg/k8s-manifests.git

 targetRevision: main

 path: '{{path}}/overlays/{{metadata.labels.env}}'

 destination:

 server: '{{server}}'

 namespace: '{{path.basename}}'

Container Orchestration Concepts

Container Orchestration คือการจัดการ Container จำนวนมากให้ทำงานร่วมกัน Kubernetes เป็น Orchestrator ที่นิยมที่สุดจัดการ Scheduling (วาง Pod บน Node ที่เหมาะสม), Scaling (เพิ่ม/ลด Pod ตาม Load), Networking (Service Discovery, Load Balancing), Storage (Persistent Volume), Health Check (Restart Pod ที่ล่ม) และ Rolling Update (อัปเดตทีละ Pod ไม่ Downtime)

เนื้อหาเกี่ยวข้อง — ดูเพิ่มเติมเรื่อง alias domain คือ — ข้อมูลครบถ้วน 2026

ArgoCD เป็นส่วนสำคัญของ Container Orchestration เพราะจัดการ Deployment Lifecycle ทั้งหมดตั้งแต่ Desired State ใน Git จนถึง Actual State บน Cluster ทำให้ Deployment เป็น Declarative, Auditable และ Reproducible

Rolling Update, Blue-Green, Canary

ArgoCD ApplicationSet Container Orchestration
  • Rolling Update — อัปเดตทีละ Pod แทนที่ Old Pod ด้วย New Pod ไม่มี Downtime เป็น Default ของ Kubernetes Deployment
  • Blue-Green — Deploy Version ใหม่ (Green) ขนานกับ Version เก่า (Blue) แล้วสลับ Traffic ทั้งหมดไป Green ถ้ามีปัญหาสลับกลับ Blue ได้ทันที
  • Canary — ส่ง Traffic ส่วันนี้อย (เช่น 5%) ไป Version ใหม่ก่อนดู Metrics ว่าปกติแล้วค่อยๆเพิ่มเป็น 25% → 50% → 100% ถ้ามีปัญหา Rollback ทันที

Argo Rollouts — Progressive Delivery

apiVersion: argoproj.io/v1alpha1

kind: Rollout

metadata:

 name: my-api

spec:

 replicas: 5

 strategy:

 canary:

 steps:

 - setWeight: 10

 - pause: {duration: 5m}

 - setWeight: 30

 - pause: {duration: 5m}

 - setWeight: 60

 - pause: {duration: 5m}

 - setWeight: 100

 canaryService: my-api-canary

 stableService: my-api-stable

 trafficRouting:

 nginx:

 stableIngress: my-api-ingress

 analysis:

 templates:

 - templateName: success-rate

 startingStep: 2

 args:

 - name: service-name

 value: my-api-canary

 selector:

 matchLabels:

 app: my-api

 template:

 metadata:

 labels:

 app: my-api

 spec:

 containers:

 - name: api

 image: my-api:v2.0

 ports:

 - containerPort: 8080

ArgoCD กับ Helm และ Kustomize

ArgoCD รองรับหลาย Config Management Tool

# Helm Source

source:

 repoURL: https://charts.bitnami.com/bitnami

 chart: postgresql

 targetRevision: 13.4.0

 helm:

 values: |

 primary:

 persistence:

 size: 50Gi

 auth:

 postgresPassword: secret



# Kustomize Source

source:

 repoURL: https://github.com/myorg/k8s-manifests.git

 path: apps/my-api/overlays/production

 kustomize:

 images:

 - my-api=registry.example.com/my-api:v2.0

RBAC และ SSO

ArgoCD มี RBAC ในตัวกำหนดว่าใครทำอะไรกับ Application/Project ไหนได้รองรับ SSO ผ่าน OIDC, SAML, LDAP, GitHub, GitLab, Okta, Keycloak

แนะนำเพิ่มเติม — SiamCafeBook

# argocd-rbac-cm ConfigMap

policy.csv: |

 p, role:dev, applications, get, */*, allow

 p, role:dev, applications, sync, dev/*, allow

 p, role:ops, applications, *, */*, allow

 g, dev-team, role:dev

 g, ops-team, role:ops

Monitoring และ Notifications

  • Prometheus Metrics — ArgoCD Export Metrics สำหรับ Grafana Dashboard (Sync Status, Health, Latency)
  • ArgoCD Notifications — ส่งแจ้งเตือนไป Slack, Teams, Email เมื่อ Sync สำเร็จ/ล้มเหลว
  • Web UI — ดู Application Status, Resource Tree, Diff, Sync History

Best Practices และสรุป

  • แยก App Repo กับ Config Repo — Application Code อยู่ Repo หนึ่ง Kubernetes Manifests อยู่อีก Repo
  • ใช้ ApplicationSet แทน Application ซ้ำๆ — ลด Duplication จัดการง่าย
  • ตั้ง Auto-sync + Self-heal สำหรับ Non-prod — Manual Sync สำหรับ Production
  • ใช้ Argo Rollouts สำหรับ Canary — ไม่ใช่ Kubernetes Deployment ปกติ
  • ใช้ RBAC — จำกัดสิทธิ์ตาม Team และ Environment
  • ใช้ Project — แยก Application ตาม Team/Environment ด้วย ArgoCD Project
  • Notification — ตั้งแจ้งเตือน Slack เมื่อ Sync ล้มเหลว
  • Backup ArgoCD — Export Application/Project YAML เก็บใน Git

ArgoCD + ApplicationSet เป็นเครื่องมือ GitOps ที่ทรงพลังสำหรับ Container Orchestration บน Kubernetes ทำให้ Deployment เป็น Declarative, Auditable และ Self-healing ลดความผิดพลาดจาก Manual Deployment ได้อย่างมากติดตามบทความใหม่ๆได้ที่ SiamCafe.net

เนื้อหาเกี่ยวข้อง — แนะนำให้อ่าน LocalAI Self-hosted AR VR Development —

อ. บอมกิตติทัศน์เจริญพนาสิทธิ์
IT Infrastructure Expert | Thaiware Award | ประสบการณ์กว่า 25 ปี — ผู้ก่อตั้ง SiamCafe.net Since 2000-2026

Q: ArgoCD คืออะไร

GitOps CD Tool สำหรับ Kubernetes ใช้ Git เป็น Source of Truth เปรียบเทียบ Git กับ Cluster แล้ว Sync ให้ตรงกันอัตโนมัติ

Q: ApplicationSet คืออะไร

CRD สร้าง Application หลายตัวจาก Template เดียวเหมาะกับ Multi-cluster, Multi-service ลด YAML Duplication

Q: GitOps คืออะไร

ใช้ Git เป็น Source of Truth ทุกการเปลี่ยนแปลงผ่าน Git Commit → PR → Review → Merge → Auto Sync ไป Cluster

Q: ArgoCD ต่างจาก FluxCD อย่างไร

ArgoCD มี Web UI สวยแสดง Resource Tree/Diff ได้ | FluxCD เป็น CLI-first Lightweight กว่าเลือกตามความชอบของทีม

เนื้อหาเกี่ยวข้อง — ทำความเข้าใจ หูฟังin ear gaming — ทุกสิ่งที่ต้องรู้ในปี 2026

XM Legend · เทรดเดอร์ & ผู้สอน Forex 13 ปี

ผู้ก่อตั้ง SiamCafe ตั้งแต่ปี 1997 · เทรดเดอร์สาย Forex มากกว่า 13 ปี ได้รับการยกย่องเป็น XM Legend · แบ่งปันความรู้ Forex, ไอที, AI และการเทรด จากประสบการณ์จริงในตลาดจริง