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
- 1Install and configure Kubernetes cluster.
- 2Install kubectl and ensure connectivity.
- 3Install ArgoCD in the cluster.
- 4
bash
kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
Access ArgoCD UI
- 1Expose ArgoCD server via port-forward.
- 2Login with initial admin password.
- 3
bash
kubectl 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
- 1Create Git repository with Kubernetes manifests.
- 2Organize manifests under apps/myapp directory.
Configure ArgoCD Application
- 1Create ArgoCD Application manifest pointing to Git repo.
- 2
yaml
apiVersion: 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
- 1Enable syncPolicy.automated for continuous reconciliation.
- 2ArgoCD detects Git changes and applies them automatically.
Rollback
- 1Use ArgoCD UI or CLI to rollback to previous revision.
- 2
bash
argocd app rollback myapp <REVISION>
Validation
- 1Commit changes to Git and verify ArgoCD sync.
- 2Check Kubernetes pods updated.
- 3Test rollback by reverting to earlier commit.
Tool Stack Used
- πArgoCD
- βKubernetes
- π§Git
- π§kubectl