GitOps with ArgoCD

Description

Implement GitOps workflow using ArgoCD for Kubernetes deployments with automated sync and rollback.

Objective

Enable declarative, Git-driven Kubernetes deployments with automated reconciliation and rollback.

Solution

Environment Setup

  1. 1Install and configure Kubernetes cluster.
  2. 2Install kubectl and ensure connectivity.
  3. 3Install ArgoCD in the cluster.
  4. 4
    bashkubectl create namespace argocd
    kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

Access ArgoCD UI

  1. 1Expose ArgoCD server via port-forward.
  2. 2Login with initial admin password.
  3. 3
    bashkubectl port-forward svc/argocd-server -n argocd 8080:443
    kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d

GitOps Repository Setup

  1. 1Create Git repository with Kubernetes manifests.
  2. 2Organize manifests under apps/myapp directory.

Configure ArgoCD Application

  1. 1Create ArgoCD Application manifest pointing to Git repo.
  2. 2
    yamlapiVersion: argoproj.io/v1alpha1
    kind: Application
    metadata:
      name: myapp
      namespace: argocd
    spec:
      project: default
      source:
        repoURL: https://github.com/myorg/myrepo.git
        targetRevision: main
        path: apps/myapp
      destination:
        server: https://kubernetes.default.svc
        namespace: myapp
      syncPolicy:
        automated:
          prune: true
          selfHeal: true

Automated Sync

  1. 1Enable syncPolicy.automated for continuous reconciliation.
  2. 2ArgoCD detects Git changes and applies them automatically.

Rollback

  1. 1Use ArgoCD UI or CLI to rollback to previous revision.
  2. 2
    bashargocd app rollback myapp <REVISION>

Validation

  1. 1Commit changes to Git and verify ArgoCD sync.
  2. 2Check Kubernetes pods updated.
  3. 3Test rollback by reverting to earlier commit.

Tool Stack Used

  • πŸ”ArgoCD
  • ⎈Kubernetes
  • πŸ”§Git
  • πŸ”§kubectl