DevOps & Cloud

GitOps dengan ArgoCD

Tutorial lengkap GitOps dengan ArgoCD β€” prinsip fundamental, instalasi, konfigurasi aplikasi, sync, rollback, multi-cluster deployment, dan best practices untuk enterprise

1. Pengenalan GitOps

GitOps adalah paradigma operasional yang menggunakan Git sebagai single source of truth untuk mendefinisikan dan mengelola infrastruktur dan aplikasi. Konsep ini dipopulerkan oleh Weaveworks pada tahun 2017 dan kini menjadi standar industri untuk continuous delivery di Kubernetes.

Inti dari GitOps sederhana: semua perubahan pada infrastruktur dan aplikasi harus dinyatakan secara declarative dalam repository Git. Perubahan ini kemudian secara otomatis diterapkan ke cluster, dan agent di dalam cluster memastikan bahwa state aktual sesuai dengan state yang didefinisikan di Git.

GitOps vs Traditional CI/CD

Aspek Traditional CI/CD GitOps
Deployment TriggerPush dari pipeline ke clusterPull dari agent di cluster ke Git
Source of TruthPipeline script + database configGit repository
RollbackRun pipeline lama atau manualgit revert β†’ otomatis di-apply
Audit TrailCI/CD logs terpisahGit history (siapa, kapan, apa yang berubah)
Disaster RecoveryRestore dari backupRe-apply dari Git repository
Cluster AccessPipeline butuh credentials clusterHanya agent di cluster yang butuh credentials
Drift DetectionManual atau tidak adaOtomatis oleh GitOps agent

Manfaat GitOps

Manfaat Penjelasan
Increased ProductivityDeploy lebih cepat dan lebih sering dengan confidence
Enhanced Developer ExperienceDeveloper cukup push ke Git, tidak perlu akses cluster
Improved StabilityDrift detection dan auto-recovery mengurangi human error
Higher ReliabilityConsistency antara Git dan cluster, audit trail lengkap
Consistency & StandardizationSatu cara untuk manage semua environment
Stronger SecurityCluster tidak perlu diakses langsung dari CI/CD

2. 4 Prinsip GitOps

GitOps didasarkan pada empat prinsip fundamental yang menjadi fondasi untuk semua implementasi. Prinsip-prinsip ini berasal dari metodologi DevOps dan SRE yang sudah terbukti.

Prinsip 1: Declarative Configuration

Seluruh sistem yang di-deploy harus didefinisikan secara declarative, bukan imperatif. Ini berarti Anda mendeskripsikan apa yang diinginkan (desired state), bukan bagaimana cara mencapainya.

YAML β€” Declarative vs Imperative
# ❌ IMPERATIVE (cara lama β€” "how to do it")
# kubectl create deployment nginx --image=nginx:1.25 --replicas=3
# kubectl expose deployment nginx --port=80 --type=ClusterIP
# kubectl scale deployment nginx --replicas=5

# βœ… DECLARATIVE (GitOps β€” "what to have")
# deploy-nginx.yaml β€” committed di Git
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  namespace: production
  labels:
    app: nginx
    version: "1.25"
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - name: nginx
          image: nginx:1.25
          ports:
            - containerPort: 80
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 500m
              memory: 256Mi
          readinessProbe:
            httpGet:
              path: /
              port: 80
            initialDelaySeconds: 5
            periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
  namespace: production
spec:
  selector:
    app: nginx
  ports:
    - port: 80
      targetPort: 80
  type: ClusterIP

Prinsip 2: Versioned & Immutable

Seluruh desired state harus disimpan di Git yang mendukung versioning, immutability, dan history. Setiap perubahan tercatat dengan siapa, kapan, dan mengapa (commit message).

Prinsip 3: Pulled & Auto-Approved

Software agent di dalam cluster menarik (pull) desired state dari Git, bukan push dari CI/CD. Agent ini otomatis mendeteksi perubahan dan menerapkannya tanpa perlu approval manual (untuk environment tertentu).

Prinsip 4: Continuously Reconciled

Agent secara continuous membandingkan desired state (Git) dengan actual state (cluster). Jika ada drift (perbedaan), agent otomatis mengembalikan cluster ke desired state.

Diagram: 4 Prinsip GitOps dalam Aksi
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    GITOPS WORKFLOW                                β”‚
β”‚                                                                  β”‚
β”‚  1. Developer push kode ke app repo                             β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  2. CI Pipeline: build & test β†’ push image ke registry          β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  3. Update image tag di config repo (declarative)               β”‚
β”‚       β”‚                                                          β”‚
β”‚       β–Ό                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚              GIT REPOSITORY                   β”‚  ← Source     β”‚
β”‚  β”‚  (Versioned, Immutable, Auditable)            β”‚    of Truth   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚                      β”‚ Pull (continuous reconcile)              β”‚
β”‚                      β–Ό                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚         GITOPS AGENT (ArgoCD)                 β”‚               β”‚
β”‚  β”‚  β€’ Monitor Git repo for changes               β”‚               β”‚
β”‚  β”‚  β€’ Compare desired vs actual state            β”‚               β”‚
β”‚  β”‚  β€’ Auto-apply changes to cluster              β”‚               β”‚
β”‚  β”‚  β€’ Drift detection & auto-heal               β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚                      β”‚ Apply                                     β”‚
β”‚                      β–Ό                                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚          KUBERNETES CLUSTER                   β”‚               β”‚
β”‚  β”‚  (Always matches Git desired state)           β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β”‚                                                                  β”‚
β”‚  Ops: git revert β†’ cluster otomatis rollback!                   β”‚
β”‚  Audit: git log β†’ complete history of all changes               β”‚
β”‚  Recovery: git clone β†’ rebuild entire infra                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

3. Arsitektur GitOps

Arsitektur GitOps modern melibatkan beberapa komponen yang bekerja sama untuk menciptakan pipeline deployment yang otomatis, aman, dan terauditasi. Berikut gambaran arsitektur standar yang digunakan di banyak perusahaan.

Repo Structure: Monorepo vs Polyrepo

Aspek App Repo + Config Repo (Polyrepo) Monorepo (Satu Repo)
StrukturSource code di app repo, manifest di config repoSource code dan manifest dalam satu repo
KeamananTim infra manage config repo, developer manage app repoAkses tercampur, perlu CODEOWNERS
ReviewPR terpisah, clear ownershipPR tunggal, perlu careful review
Rekomendasiβœ… Direkomendasikan untuk tim besarCocok untuk tim kecil atau startup

Direktori Config Repository

File Structure β€” GitOps Config Repository
gitops-config/
β”œβ”€β”€ README.md
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api-service/
β”‚   β”‚   β”œβ”€β”€ base/                          # Base manifests
β”‚   β”‚   β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”‚   β”‚   β”œβ”€β”€ service.yaml
β”‚   β”‚   β”‚   β”œβ”€β”€ hpa.yaml
β”‚   β”‚   β”‚   └── kustomization.yaml
β”‚   β”‚   └── overlays/                      # Environment overrides
β”‚   β”‚       β”œβ”€β”€ staging/
β”‚   β”‚       β”‚   β”œβ”€β”€ kustomization.yaml
β”‚   β”‚       β”‚   └── patches-replicas.yaml
β”‚   β”‚       └── production/
β”‚   β”‚           β”œβ”€β”€ kustomization.yaml
β”‚   β”‚           β”œβ”€β”€ patches-replicas.yaml
β”‚   β”‚           └── patches-resources.yaml
β”‚   β”‚
β”‚   β”œβ”€β”€ web-frontend/
β”‚   β”‚   β”œβ”€β”€ base/
β”‚   β”‚   β”‚   β”œβ”€β”€ deployment.yaml
β”‚   β”‚   β”‚   β”œβ”€β”€ service.yaml
β”‚   β”‚   β”‚   β”œβ”€β”€ ingress.yaml
β”‚   β”‚   β”‚   └── kustomization.yaml
β”‚   β”‚   └── overlays/
β”‚   β”‚       β”œβ”€β”€ staging/
β”‚   β”‚       └── production/
β”‚   β”‚
β”‚   └── worker/
β”‚       β”œβ”€β”€ base/
β”‚       └── overlays/
β”‚
β”œβ”€β”€ infrastructure/                        # Infra-level resources
β”‚   β”œβ”€β”€ namespaces.yaml
β”‚   β”œβ”€β”€ network-policies.yaml
β”‚   β”œβ”€β”€ rbac.yaml
β”‚   β”œβ”€β”€ cert-manager/
β”‚   β”œβ”€β”€ ingress-nginx/
β”‚   └── monitoring/
β”‚
└── projects/                              # ArgoCD project definitions
    β”œβ”€β”€ default.yaml
    └── production.yaml

4. ArgoCD: Instalasi & Setup

ArgoCD adalah GitOps operator untuk Kubernetes yang implementasi yang powerful dan declarative. ArgoCD mengimplementasikan keempat prinsip GitOps dan menyediakan UI, CLI, dan API untuk mengelola deployment. ArgoCD adalah CNCF graduated project yang digunakan oleh ribuan perusahaan di seluruh dunia.

Instalasi ArgoCD

Bash β€” ArgoCD Installation
# Buat namespace
kubectl create namespace argocd

# Install ArgoCD (stable release)
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# Tunggu semua pods running
kubectl wait --for=condition=Ready pods --all -n argocd --timeout=300s

# Cek status pods
kubectl get pods -n argocd
# NAME                                  READY   STATUS    RESTARTS   AGE
# argocd-application-controller-xxx     1/1     Running   0          2m
# argocd-dex-server-xxx                 1/1     Running   0          2m
# argocd-redis-xxx                      1/1     Running   0          2m
# argocd-repo-server-xxx                1/1     Running   0          2m
# argocd-server-xxx                     1/1     Running   0          2m

# Expose ArgoCD server (LoadBalancer atau port-forward)
kubectl patch svc argocd-server -n argocd -p '{"spec": {"type": "LoadBalancer"}}'

# Atau port-forward untuk development
kubectl port-forward svc/argocd-server -n argocd 8080:443

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

# Login via CLI
argocd login localhost:8080 --username admin --password  --insecure

# Ganti password default
argocd account update-password

# Install ArgoCD 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/

Akses ArgoCD

πŸ’‘ Akses ArgoCD UI

Setelah instalasi, ArgoCD bisa diakses melalui:

  • Web UI: https://localhost:8080 (atau IP LoadBalancer)
  • CLI: argocd command
  • REST API: https://argocd-server/api/v1/
  • gRPC API: Untuk integrasi dengan tool lain

5. Membuat & Mengelola Aplikasi

ArgoCD mengelola Application β€” yang merupakan custom resource (CRD) yang mendefinisikan hubungan antara Git repository dan target cluster/namespace. Setiap application merepresentasikan satu unit deployment yang bisa di-manage secara independen.

Membuat Aplikasi via CLI

Bash β€” ArgoCD Application Creation
# Tambahkan cluster target (jika multi-cluster)
argocd cluster add staging-cluster-context

# Buat aplikasi via CLI
argocd app create api-service \
  --repo https://github.com/myorg/gitops-config.git \
  --path apps/api-service/overlays/production \
  --dest-server https://kubernetes.default.svc \
  --dest-namespace production \
  --sync-policy automated \
  --auto-prune \
  --self-heal \
  --revision main

# Lihat status aplikasi
argocd app get api-service

# Sync manual
argocd app sync api-service

# Lihat diff sebelum sync (dry-run)
argocd app diff api-service

Membuat Aplikasi via YAML Manifest

YAML β€” ArgoCD Application CRD
# argocd-app-api-service.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: api-service
  namespace: argocd
  finalizers:
    - resources-finalizer.argocd.argoproj.io
spec:
  project: default

  source:
    repoURL: https://github.com/myorg/gitops-config.git
    targetRevision: main
    path: apps/api-service/overlays/production

    # Kustomize options
    kustomize:
      images:
        - myregistry.io/api-service:v1.2.3

  destination:
    server: https://kubernetes.default.svc
    namespace: production

  syncPolicy:
    automated:
      prune: true         # Hapus resource yang tidak ada di Git
      selfHeal: true      # Auto-revert manual changes
      allowEmpty: false    # Jangan sync jika tidak ada resource
    syncOptions:
      - CreateNamespace=true
      - PruneLast=true     # Hapus resource lama terakhir
      - ApplyOutOfSyncOnly=true
      - ServerSideApply=true
    retry:
      limit: 5
      backoff:
        duration: 5s
        factor: 2
        maxDuration: 3m

  # Health monitoring
  ignoreDifferences:
    - group: apps
      kind: Deployment
      jsonPointers:
        - /spec/replicas    # Ignore autoscaler replica changes

# Terapkan manifest
kubectl apply -f argocd-app-api-service.yaml

Kustomize Overlay untuk Environment

YAML β€” Kustomize Overlay Production
# apps/api-service/overlays/production/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: production
resources:
  - ../../base
patchesStrategicMerge:
  - patches-replicas.yaml
  - patches-resources.yaml
  - patches-env.yaml

# apps/api-service/overlays/production/patches-replicas.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-service
spec:
  replicas: 5    # Production: 5 replicas

# apps/api-service/overlays/production/patches-resources.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: api-service
spec:
  template:
    spec:
      containers:
        - name: api-service
          resources:
            requests:
              cpu: 500m
              memory: 512Mi
            limits:
              cpu: "2"
              memory: 2Gi

6. Sync, Rollback & Health

Sync adalah proses menerapkan desired state dari Git ke cluster. ArgoCD mendukung berbagai mode sync, monitoring health status, dan mekanisme rollback yang sangat powerful.

Sync States

Status Penjelasan Aksi
SyncedCluster sesuai dengan GitTidak perlu aksi
OutOfSyncAda perbedaan antara Git dan clusterAuto-sync atau manual sync
SyncingSedang dalam proses syncTunggu selesai
Sync FailedProses sync gagalCek error, fix, retry

Health Status

Health Penjelasan
Healthy 🟒Semua resource berjalan normal sesuai expected
Progressing πŸ”΅Resource sedang dalam proses (deploying, scaling)
Degraded 🟑Ada masalah partial β€” beberapa pod crash atau error
Suspended βšͺResource di-suspend (misalnya deployment replicas=0)
Missing ⚫Resource yang diharapkan tidak ditemukan di cluster
Unknown ❓Health tidak bisa ditentukan

Rollback dengan GitOps

Salah satu keunggulan terbesar GitOps adalah rollback yang sederhana dan terpercaya. Karena semua state ada di Git, rollback hanya perlu git revert.

Bash β€” Rollback Workflow
# === ROLLBACK ===

# Lihat history deploy
argocd app history api-service
# ID  DATE                           REVISION
# 5   2026-06-25 14:30 +0700        main (abc1234)
# 4   2026-06-25 10:00 +0700        main (def5678)
# 3   2026-06-24 16:00 +0700        main (ghi9012)

# Opsi 1: Rollback ke revision tertentu
argocd app rollback api-service 4

# Opsi 2: Git revert (lebih "GitOps way")
cd gitops-config
git revert HEAD
git push origin main
# ArgoCD otomatis mendeteksi dan sync ke state sebelumnya

# Opsi 3: Lihat dan apply manifest tertentu
argocd app manifests api-service --revision def5678

# Cek status setelah rollback
argocd app get api-service
⚠️ Perbedaan Rollback ArgoCD vs Git Revert
  • argocd app rollback: Menggunakan cached manifest dari history, cepat tapi tidak tercatat di Git
  • git revert: Membuat commit baru yang mengembalikan perubahan, tercatat di Git history, recommended
  • Untuk produksi, selalu gunakan git revert agar audit trail lengkap dan semua orang tahu apa yang terjadi

7. Multi-Cluster Deployment

Salah satu keunggulan ArgoCD adalah kemampuan mengelola multiple cluster dari satu control plane. Ini sangat berguna untuk organisasi yang memiliki staging, production, dan environment regional yang tersebar di berbagai cloud provider.

Menambah Cluster ke ArgoCD

Bash β€” Multi-Cluster Setup
# Tambah cluster baru ke ArgoCD
# Metode 1: Via kubectl context
argocd cluster add staging-context --name staging
argocd cluster add production-us-east --name us-east
argocd cluster add production-eu-west --name eu-west

# Metode 2: Via kubeconfig file
argocd cluster add --kubeconfig /path/to/kubeconfig --name production-asia

# Lihat semua cluster yang terdaftar
argocd cluster list
# SERVER                          NAME        STATUS
# https://kubernetes.default.svc  in-cluster  Successful
# https://staging.example.com     staging     Successful
# https://us-east.example.com     us-east     Successful
# https://eu-west.example.com     eu-west     Successful

# Test koneksi ke cluster
argocd cluster get us-east

Deploy ke Multi-Cluster

YAML β€” Multi-Cluster Application
# Deploy ke cluster staging
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: api-service-staging
  namespace: argocd
spec:
  project: staging
  source:
    repoURL: https://github.com/myorg/gitops-config.git
    targetRevision: main
    path: apps/api-service/overlays/staging
  destination:
    server: https://staging.example.com    # Cluster staging
    namespace: default
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
---
# Deploy ke cluster production US
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: api-service-us-east
  namespace: argocd
spec:
  project: production
  source:
    repoURL: https://github.com/myorg/gitops-config.git
    targetRevision: release/v1.2    # Pin ke release branch
    path: apps/api-service/overlays/production
  destination:
    server: https://us-east.example.com
    namespace: production
  syncPolicy:
    automated:
      selfHeal: true     # Self-heal saja, manual sync
  # Production: TIDAK auto-prune, manual approval dulu
---
# Deploy ke cluster production EU
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: api-service-eu-west
  namespace: argocd
spec:
  project: production
  source:
    repoURL: https://github.com/myorg/gitops-config.git
    targetRevision: release/v1.2
    path: apps/api-service/overlays/production
  destination:
    server: https://eu-west.example.com
    namespace: production
  syncPolicy:
    automated:
      selfHeal: true

Arsitektur Multi-Cluster

Diagram: ArgoCD Multi-Cluster Architecture
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                ARGOCD CONTROL PLANE                               β”‚
β”‚                (Central Cluster)                                  β”‚
β”‚                                                                  β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚                   ArgoCD Server                           β”‚    β”‚
β”‚  β”‚  β€’ Web UI (Single Pane of Glass)                         β”‚    β”‚
β”‚  β”‚  β€’ Application Controller                                 β”‚    β”‚
β”‚  β”‚  β€’ Repo Server                                            β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                          β”‚                                        β”‚
β”‚         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”‚
β”‚         β”‚                β”‚                β”‚                      β”‚
β”‚         β–Ό                β–Ό                β–Ό                      β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 β”‚
β”‚  β”‚  Staging   β”‚  β”‚ Prod US    β”‚  β”‚ Prod EU    β”‚                 β”‚
β”‚  β”‚  Cluster   β”‚  β”‚  Cluster   β”‚  β”‚  Cluster   β”‚                 β”‚
β”‚  β”‚            β”‚  β”‚            β”‚  β”‚            β”‚                 β”‚
β”‚  β”‚ Auto-sync  β”‚  β”‚ Manual     β”‚  β”‚ Manual     β”‚                 β”‚
β”‚  β”‚ Auto-prune β”‚  β”‚ sync       β”‚  β”‚ sync       β”‚                 β”‚
β”‚  β”‚ main branchβ”‚  β”‚ release/   β”‚  β”‚ release/   β”‚                 β”‚
β”‚  β”‚            β”‚  β”‚ v1.2       β”‚  β”‚ v1.2       β”‚                 β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

8. GitOps Best Practices

Setelah memahami konsep dan implementasi dasar, berikut best practices yang harus diterapkan untuk GitOps yang sukses di production.

Repository & Structure

πŸ’‘ Best Practice: Repository
  • Pisahkan app repo dan config repo β€” Source code terpisah dari manifest deployment
  • Gunakan Kustomize atau Helm β€” Hindari raw YAML yang redundan antar environment
  • Gunakan branch strategy yang jelas β€” Contoh: main β†’ staging, release/* β†’ production
  • CODEOWNERS di config repo β€” Tim infra men-review perubahan manifest
  • Semua perubahan via Pull Request β€” Tidak ada commit langsung ke main/release branch

Security & RBAC

YAML β€” ArgoCD RBAC Policy
# argocd-rbac-cm ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
  name: argocd-rbac-cm
  namespace: argocd
data:
  # Default policy: read-only
  policy.default: role:readonly

  policy.csv: |
    # Admin bisa melakukan semua aksi
    p, role:admin, *, *, */*, allow

    # Developer bisa sync aplikasi tertentu
    p, role:developer, applications, get, staging/*, allow
    p, role:developer, applications, sync, staging/*, allow
    p, role:developer, applications, action/*, staging/*, allow

    # Production hanya bisa di-read, sync butuh approval
    p, role:developer, applications, get, production/*, allow

    # SRE team bisa manage semua
    p, role:sre, applications, *, */*, allow
    p, role:sre, clusters, *, *, allow

    # Assign user ke roles
    g, alice, role:admin
    g, bob, role:developer
    g, carol, role:sre

  # Scopes: match groups dari SSO
  scopes: "[groups]"

Arsitektur Deployment Pipeline yang Disarankan

Diagram: Enterprise GitOps Pipeline
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚               ENTERPRISE GITOPS PIPELINE                         β”‚
β”‚                                                                  β”‚
β”‚  Developer                                                      β”‚
β”‚    β”‚ 1. Push kode ke app repo                                   β”‚
β”‚    β–Ό                                                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
β”‚  β”‚  CI Pipeline β”‚ ← Build, Test, Security Scan, Image Push      β”‚
β”‚  β”‚  (GitHub     β”‚   β€’ Unit test + integration test              β”‚
β”‚  β”‚   Actions)   β”‚   β€’ Container scanning (Trivy/Snyk)           β”‚
β”‚  β”‚              β”‚   β€’ Push image ke registry                    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
β”‚         β”‚ 2. Update image tag di config repo                    β”‚
β”‚         β–Ό                                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
β”‚  β”‚ Config Repo  β”‚ ← Kustomize/Helm manifests                   β”‚
β”‚  β”‚ (Git)        β”‚                                               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
β”‚         β”‚ 3. PR review & merge                                  β”‚
β”‚         β–Ό                                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                               β”‚
β”‚  β”‚   ArgoCD     β”‚ ← Automated sync to staging                   β”‚
β”‚  β”‚              β”‚                                               β”‚
β”‚  β”‚ Staging      β”‚ β†’ Auto-sync, auto-prune, run tests           β”‚
β”‚  β”‚              β”‚                                               β”‚
β”‚  β”‚ Production   β”‚ β†’ Manual sync (gate) + auto-heal              β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                                               β”‚
β”‚         β”‚                                                       β”‚
β”‚         β–Ό                                                       β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”               β”‚
β”‚  β”‚         KUBERNETES CLUSTERS                   β”‚               β”‚
β”‚  β”‚  β€’ Always matches Git                         β”‚               β”‚
β”‚  β”‚  β€’ Auto-heal drift                            β”‚               β”‚
β”‚  β”‚  β€’ Complete audit trail                       β”‚               β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Checklist GitOps Implementation

No. Checklist Item Prioritas
1Gunakan Git sebagai single source of truthπŸ”΄ Wajib
2Semua perubahan via Pull RequestπŸ”΄ Wajib
3Aktifkan automated sync untuk stagingπŸ”΄ Wajib
4Aktifkan self-heal untuk semua environmentπŸ”΄ Wajib
5Gunakan Kustomize/Helm untuk menghindari YAML duplikat🟑 Penting
6Pisahkan app repo dan config repo🟑 Penting
7Implementasi RBAC dan SSO di ArgoCD🟑 Penting
8Setup notification (Slack/email) untuk sync events🟑 Penting
9Gunakan ArgoCD ApplicationSet untuk multi-cluster🟒 Recommended
10Monitor ArgoCD health dan metrics🟒 Recommended
⚠️ Common Pitfalls
  • Jangan commit secrets ke Git β€” Gunakan Sealed Secrets, External Secrets, atau SOPS
  • Jangan auto-prune di production β€” Butuh approval manual untuk menghapus resource
  • Jangan lupa monitoring β€” Monitor ArgoCD metrics dan notification
  • Jangan satu config repo untuk semua team β€” Gunakan ArgoCD Projects untuk isolasi
  • Jangan update langsung ke cluster β€” Selalu lewat Git, jangan bypass ArgoCD

9. Quiz: Uji Pemahamanmu!

Setelah membaca tutorial di atas, jawablah 5 pertanyaan berikut untuk menguji pemahamanmu tentang GitOps dan ArgoCD:

Pertanyaan 1: Apa yang menjadi "single source of truth" dalam GitOps?

a) Kubernetes cluster
b) CI/CD pipeline configuration
c) Git repository
d) Docker registry

Pertanyaan 2: Apa yang dilakukan ArgoCD saat terjadi "drift" (perbedaan) antara Git dan cluster?

a) Mengirim email notifikasi dan menunggu manual approval
b) Mengabaikan perbedaan tersebut
c) Jika self-heal aktif, otomatis mengembalikan cluster ke state di Git
d) Meng-update Git repository agar sesuai dengan cluster

Pertanyaan 3: Perintah apa yang digunakan untuk rollback deployment di GitOps way?

a) kubectl rollout undo
b) argocd app rollback
c) git revert
d) helm rollback

Pertanyaan 4: Mengapa CI/CD pipeline dalam GitOps tidak perlu memiliki akses langsung ke Kubernetes cluster?

a) Karena Kubernetes tidak mendukung API access dari CI/CD
b) Karena pipeline hanya perlu push image ke registry
c) Karena GitOps agent di dalam cluster yang menarik (pull) perubahan dari Git
d) Karena pipeline menggunakan webhook untuk deploy

Pertanyaan 5: Apa perbedaan antara "automated sync" dan "manual sync" di ArgoCD?

a) Automated sync menghapus resource lama, manual sync tidak
b) Automated sync otomatis menerapkan perubahan saat Git berubah, manual sync memerlukan persetujuan atau trigger manusia
c) Automated sync hanya untuk staging, manual sync hanya untuk production
d) Tidak ada perbedaan, keduanya berjalan otomatis