MHRubel
HomeAboutProjectsSkillsExperienceBlogContact
MHRubel

Senior Software Engineer crafting high-performance web applications and SaaS platforms.

Navigation

  • Home
  • About
  • Projects
  • Skills
  • Experience
  • Blog
  • Contact

Get in Touch

Available for senior/lead roles and consulting.

bd.mhrubel@gmail.comHire Me

© 2026 Mahamudul Hasan Rubel. All rights reserved.

Built with using Next.js 16 & Tailwind v4

Back to Blog
Software EngineeringTechnologyJune 18, 20267 min read

Argo CD: Mastering GitOps for Kubernetes

Master GitOps with Argo CD! Learn how this powerful tool enables declarative continuous delivery for your Kubernetes applications, streamlining deployments and improving reliability.

DevOpsLinuxServer

Hey everyone, Mahamudul Hasan Rubel here. Today, I want to talk about something that's fundamentally changed how I manage Kubernetes deployments: GitOps, specifically with Argo CD. If you're tired of the manual toil, the "oops, I forgot to update that manifest" moments, then stick around. We're going to build a robust, declarative Continuous Delivery pipeline.

What Exactly is GitOps?

At its core, GitOps is a way to do Continuous Delivery (CD) for cloud-native applications. It leverages Git as the single source of truth for your entire infrastructure and application state. Think about it: instead of manually applying YAML files or clicking buttons, you declare the desired state of your system in Git. GitOps tools then ensure that your live environment matches that declared state.

The key principles are:

  1. Declarative Configuration: Your system's desired state is described declaratively (e.g., in Kubernetes YAML).
  2. Versioned and Immutable: The declarative configuration is stored in Git, providing a version history and audit trail.
  3. Automated Pull: Approved changes to Git are automatically applied to your live environment.
  4. Continuous Reconciliation: Software agents continuously observe the live environment and compare it against the desired state in Git, correcting any drift.

Why Argo CD?

There are a few GitOps tools out there, but Argo CD has become my go-to for Kubernetes. It's an open-source, declarative, GitOps continuous delivery tool specifically designed for Kubernetes. It's powerful, flexible, and has a fantastic UI that makes understanding your deployment status a breeze.

Argo CD operates on the "pull" model. It runs inside your Kubernetes cluster, watches your Git repositories, and pulls down the desired state. Then, it compares that state with what's actually running in your cluster and applies any necessary changes. This is a huge improvement over "push" models where an external CI system pushes changes into the cluster, which can be a security concern and harder to manage.

Setting Up Argo CD

Let's get our hands dirty. We'll assume you have a Kubernetes cluster up and running. If not, minikube start or kind create cluster are your friends for local development.

First, we need to install Argo CD into our cluster. The easiest way is using kubectl:

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

This command creates the argocd namespace and applies the official installation manifest. It deploys all the necessary components: the API server, the repo server, the application controller, and the UI.

Once installed, you'll need to access the Argo CD UI. By default, it's not exposed externally. For local testing, we can port-forward the service:

Bash
kubectl port-forward svc/argocd-server -n argocd 8080:443

Now you can access the Argo CD UI at https://localhost:8080.

The initial admin password is the same as the Argo CD service name in the argocd namespace, encoded in base64.

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

You can then log in using admin as the username and the decoded password. It's a good idea to change this default password immediately after logging in via the UI or argocd account update-password.

Connecting Your Git Repository

Argo CD needs access to your Git repository where your Kubernetes manifests live. You can configure this through the UI or the CLI. Let's use the CLI for this example.

First, ensure you have the Argo CD CLI installed. You can find instructions on the Argo CD website.

Log in to your Argo CD instance:

Bash
argocd login localhost:8080 --username admin --password <your-admin-password> --insecure

(Note: --insecure is for local testing with self-signed certificates. In production, you'd want to configure proper TLS.)

Now, let's add a Git repository. For this example, imagine you have a repository like this:

my-app-repo/
├── app/
│   ├── deployment.yaml
│   └── service.yaml
└── argocd-app.yaml  # Argo CD Application definition

The argocd-app.yaml is a special manifest that tells Argo CD how to deploy your application. Here's a simplified example:

YAML
# argocd-app.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-app
  namespace: argocd # The namespace where Argo CD lives
spec:
  project: default
  source:
    repoURL: <your-git-repo-url> # e.g., https://github.com/yourusername/my-app-repo.git
    targetRevision: HEAD # Or a specific branch like 'main' or a tag
    path: app # The directory within the repo containing your K8s manifests
  destination:
    server: https://kubernetes.default.svc # The target Kubernetes cluster API server
    namespace: my-app # The namespace where the app will be deployed
  syncPolicy:
    automated:
      prune: true # Automatically delete resources removed from Git
      selfHeal: true # Automatically correct drift from the desired state

To add this repository to Argo CD, you'd typically commit this argocd-app.yaml file to a separate Git repository that Argo CD can access, or directly apply it to the Argo CD namespace. For simplicity in a demo, let's apply it directly:

Bash
kubectl apply -f argocd-app.yaml -n argocd

Argo CD will detect this new Application resource and start its sync process.

Understanding Applications and Sync Status

In Argo CD, an "Application" is a Kubernetes Custom Resource Definition (CRD) that defines how a set of Kubernetes resources should be deployed from a Git repository to a target cluster.

You can see your application listed in the Argo CD UI. It will show the sync status:

  • OutOfSync: The live state doesn't match the state in Git.
  • Synced: The live state matches the state in Git.
  • Degraded: The application is running but has issues (e.g., pods failing health checks).

When Argo CD detects an OutOfSync state, it will attempt to reconcile it based on your syncPolicy. If selfHeal is enabled, it will automatically apply the changes. If prune is enabled, it will also remove any resources in the cluster that are no longer defined in Git.

Manual Sync vs. Automated Sync

The syncPolicy in the Application CRD is crucial.

  • Manual Sync: If you don't configure automated sync, you'll need to manually trigger a sync from the UI or CLI whenever you want to apply changes from Git. This gives you an extra layer of control, allowing for manual approval before deployment.

    Bash
    argocd app sync my-app
  • Automated Sync: With automated: { prune: true, selfHeal: true }, Argo CD will automatically sync changes and correct drift. This is the true power of GitOps for Continuous Delivery. Changes merged to your designated branch in Git are automatically reflected in your cluster.

Best Practices for Automated Sync

While automated sync is powerful, it's not a "set it and forget it" solution. Here are some best practices:

  • Branching Strategy: Use a clear branching strategy. For example, have a develop branch for staging and a main or production branch for production environments. Argo CD Applications can target specific branches or tags.
  • Review Process: Implement a robust Pull Request (PR) review process for all changes going into your Git repository. This is your gatekeeper for production deployments.
  • Separate Environments: Use separate Git repositories or distinct paths within a single repository for different environments (dev, staging, prod). Each environment should have its own Argo CD Application resource.
  • Health Checks: Ensure your Kubernetes Deployments, StatefulSets, etc., have proper readiness and liveness probes configured. Argo CD relies on Kubernetes to report the health of your workloads.
  • Rollback Strategy: While GitOps inherently supports rollbacks (just revert the commit in Git and let Argo CD sync), plan your rollback strategy. Understand how Argo CD handles reverting changes.

Advanced Argo CD Features

Argo CD offers much more than basic deployment.

Application Sets

As your number of applications and environments grows, managing individual Application CRDs can become cumbersome. Argo CD ApplicationSets allow you to generate multiple Application resources from a template based on various generators (like Git directories, lists, or even cluster discovery). This is fantastic for managing fleets of applications across multiple clusters or environments.

For example, you could have an ApplicationSet that generates an Application for my-app in dev, staging, and prod environments, all from a single template.

Multi-Cluster Deployments

Argo CD excels at managing applications across multiple Kubernetes clusters. You

Back to Blog