LATEST 🚀 Welcome to Upgradix by Shrash Studio – Your destination for free technology learning and career growth.
🕘 Updated:
Kubernetes

GitOps Continuous Delivery with Argo CD

Deploying applications to Kubernetes manually using kubectl apply works fine when you are learning on your laptop. In real production environments, however, manual deployments lead to configuration drift, broken releases, and security risks.

GitOps Continuous Delivery with Argo CD

Deploying applications to Kubernetes manually using kubectl apply works fine when you are learning on your laptop. In real production environments, however, manual deployments lead to configuration drift, broken releases, and security risks.

GitOps solves this problem by making your Git repository the single source of truth for your entire Kubernetes cluster. In this guide, you will learn how to install open-source Argo CD, connect your Git manifest repository, and automate your cluster state so it always matches your code.

What you will learn
  • Why traditional push-based CI/CD struggles with Kubernetes and how GitOps fixes it.
  • How to install open-source Argo CD inside your Kubernetes cluster.
  • How to connect a Git repository using an Argo CD Application manifest.
  • How automated sync, self-healing, and pruning prevent configuration drift.
  • Real-world architecture trade-offs and senior-level interview questions on Argo CD.

1. What Is GitOps and Why Argo CD?

In a traditional CI/CD pipeline (like Jenkins or GitHub Actions), the pipeline builds your code and then pushes changes directly into your Kubernetes cluster using cluster admin credentials. If someone manually edits a deployment inside the cluster, your pipeline has no idea that the live cluster no longer matches your Git repo.

GitOps flips this model to a pull-based approach. Instead of an external tool pushing changes, an agent running inside your Kubernetes cluster—Argo CD—constantly watches your Git repository. Whenever you push a new YAML file or update an image tag in Git, Argo CD pulls the change and updates the cluster automatically.

Feature Traditional Push CI/CD GitOps Pull (Argo CD)
Cluster Credentials Stored externally in CI tool (higher security risk) Stays strictly inside the Kubernetes cluster
Drift Detection None. Manual kubectl edit goes unnoticed Continuous. Argo CD detects drift in seconds
Self-Healing Manual re-run of pipeline required Automatic. Reverts unauthorized manual changes
Rollbacks Complex pipeline re-triggers Simple git revert restores previous cluster state

2. Installing Open-Source Argo CD

Argo CD runs natively inside Kubernetes as a set of pods and Custom Resource Definitions (CRDs). You can install it on any free local cluster (like Minikube, Kind, or k3s) or a cloud cluster in just two commands.

Step 1: Create the namespace and apply the official manifest

Example 1: Installing Argo CD via kubectl

# Create a dedicated namespace for Argo CD
kubectl create namespace argocd

# Install the latest stable open-source Argo CD manifests
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

# Wait until all Argo CD pods are running
kubectl get pods -n argocd -w

Expected output

NAME                                                READY   STATUS    RESTARTS   AGE
argocd-application-controller-0                     1/1     Running   0          45s
argocd-dex-server-7b5f8c9b4-x9k2p                   1/1     Running   0          45s
argocd-redis-6d7f8c9b4-m4n8q                        1/1     Running   0          45s
argocd-repo-server-5c8f9d6b7-p2r5t                  1/1     Running   0          45s
argocd-server-8d4f6c7b5-v7w1z                       1/1     Running   0          45s

Step 2: Access the Argo CD Web UI and get the initial password

Argo CD comes with a clean, built-in web dashboard. Use port-forwarding to access it locally without setting up an Ingress controller first.

Example 2: Port-forwarding and retrieving the admin password

# Forward local port 8080 to the Argo CD server
kubectl port-forward svc/argocd-server -n argocd 8080:443

# In a new terminal, extract the initial admin password
kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d; echo
Important: Open https://localhost:8080 in your browser. Log in with the username admin and the password printed above. Remember to change this password and delete the initial secret in production environments.

3. Connecting Your Git Repository (Declarative Setup)

While you can click around in the Argo CD UI to add an application, the true GitOps way is to define your Argo CD Application using YAML. This tells Argo CD which Git repo to watch, which folder holds your Kubernetes manifests, and how to handle automatic syncing.

Example 3: Declarative Argo CD Application manifest (app-config.yaml)

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-webapp
  namespace: argocd
spec:
  project: default
  source:
    repoURL: 'https://github.com/your-username/k8s-manifests.git'
    targetRevision: HEAD
    path: manifests/production
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: production
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true

Apply this manifest to your cluster using kubectl apply -f app-config.yaml. Argo CD immediately clones the repository, reads the YAML files inside manifests/production, creates the production namespace, and deploys your application.

4. The GitOps Reconciliation Loop Visualized

The real power of Argo CD is its continuous reconciliation loop. Every 3 minutes (or immediately via a Git webhook), Argo CD compares the Desired State in Git with the Live State in Kubernetes.

Argo CD Automated Sync & Self-Healing Workflow

Developer Updates YAML git push Git Repository Desired State Poll / Webhook Argo CD Controller Reconciliation Engine Auto-Sync Apply Kubernetes Cluster Live State (Pods/Svc) Watch State Drift Detection Synced / OutOfSync? If OutOfSync -> Self-Heal

Argo CD continuously compares Git (Desired State) against Kubernetes (Live State). If someone manually alters a pod or service, Drift Detection flags it as OutOfSync and Self-Heal restores the Git version.

5. Step-by-Step Breakdown of Sync Policies

Understanding the syncPolicy block in your Application YAML is critical for production stability:

Step 1 — Automated Sync: When automated is enabled, Argo CD automatically applies new Git commits to your cluster without waiting for a human to click "Sync" in the dashboard.
Step 2 — Prune (prune: true): If you delete a Deployment or ConfigMap file from your Git repository, Argo CD will also delete that resource from Kubernetes. Without pruning, deleted files leave behind orphaned resources in your cluster.
Step 3 — Self-Heal (selfHeal: true): If a developer runs kubectl scale deployment my-app --replicas=10 manually in production, Argo CD immediately detects that Git says replicas: 2 and scales it right back down to 2.
Watch out: Never store plain-text secrets (database passwords, API keys) in your Git repository! Use open-source tools like Sealed Secrets or External Secrets Operator so your Git repo only holds encrypted data or secret references.

6. Architecture & Real-World Trade-offs

When scaling Argo CD across enterprise microservices, keep these architectural best practices in mind:

  • Separate Application Code from Manifests: Do not put your Kubernetes YAML files in the same Git repository as your application source code. If you do, every CI build that updates an image tag will trigger an infinite CI loop. Keep a dedicated k8s-manifests repository.
  • The "App of Apps" Pattern & ApplicationSets: Managing 50 microservices by manually applying 50 Argo CD Application YAMLs does not scale. Use an ApplicationSet controller to automatically generate Argo CD Applications for every folder in your Git repo or every cluster in your fleet.
  • Performance & Polling: By default, Argo CD polls Git every 3 minutes. For large organizations with hundreds of apps, configure Git webhooks so Argo CD only refreshes when a commit actually happens, saving CPU and Git API rate limits.

7. Hands-On Practice

Beginner Exercise 1: Test Self-Healing

Deploy a simple NGINX Deployment using Argo CD with selfHeal: true. Once it is running, manually delete the NGINX Service using kubectl delete svc and watch the Argo CD UI.

Hint: Within seconds, Argo CD will detect the missing service and recreate it automatically.

Intermediate Exercise 2: Perform a GitOps Rollback

Change the NGINX container image tag in your Git repo to a broken tag like nginx:does-not-exist and push. Watch the pod enter ImagePullBackOff, then fix production using only Git.

Expected result: Running git revert HEAD && git push will automatically restore your healthy pods without touching kubectl.

Advanced Exercise 3: Multi-Environment with Kustomize

Structure your Git repo with a base/ folder and two overlays (overlays/dev and overlays/prod). Point two separate Argo CD Applications to those paths.

Hint: Argo CD natively supports Kustomize and Helm out of the box—no extra plugins required.

8. Argo CD & GitOps – Interview Questions

Q1. What is the difference between CI and CD in a GitOps workflow?

Answer: Continuous Integration (CI) handles building code, running unit tests, and pushing a Docker image to a registry, then updating the image tag in the Git manifest repo. Continuous Delivery (CD)—handled by Argo CD—watches that Git repo and syncs the updated manifests into the Kubernetes cluster.

Q2. What happens if someone manually edits a deployment in Kubernetes when Argo CD is managing it?

Answer: Argo CD immediately flags the application status as OutOfSync. If selfHeal: true is enabled in the sync policy, Argo CD automatically reverts the manual change to match the Git repository. If self-heal is off, it alerts the team until someone manually triggers a sync.

Q3. How do you handle Kubernetes Secrets securely in GitOps?

Answer: You never commit raw Base64 Kubernetes Secrets to Git. Instead, you use tools like Bitnami Sealed Secrets (which encrypts secrets using a cluster-only public key so they are safe to store in Git) or External Secrets Operator (which pulls secrets dynamically at runtime from AWS Secrets Manager or HashiCorp Vault).

Conclusion

GitOps with Argo CD transforms Kubernetes deployments from stressful, error-prone manual tasks into a predictable, auditable workflow. By treating Git as your single source of truth, you gain instant rollbacks, automatic drift detection, and tighter cluster security.

Start by connecting a single non-production service to Argo CD. Once your team experiences the peace of mind of automated self-healing and Git-driven rollbacks, you can scale out to your entire microservices architecture.

Official Documentation

Upgradix by Shrash Studio – Learn Technology. Build Your Future.

Comments & Ratings (0)

Log in or create a student account to comment and rate this article.

Be the first to comment on this article.