logo
1749107549281.jpeg

GitOps with ArgoCD: Declarative Deployment to Kubernetes

  • Author: Administrator
  • Published On: 15 Jul 2025
  • Category: CI/CD

GitOps with ArgoCD: Declarative Deployment to Kubernetes

In the modern software development world, rapid, reliable, and repeatable application deployments are of utmost importance. GitOps, combined with ArgoCD, provides a powerful approach to declaratively managing application deployments on Kubernetes. This article will explore the principles of GitOps, how ArgoCD implements them, and how it compares to traditional CI/CD processes.

What is GitOps?

GitOps is an operational model for Kubernetes and other cloud-native systems where Git acts as the single source of truth for the desired state of the system. Instead of using manual commands or scripts to deploy applications, you declare the desired state of the application (e.g., number of replicas, image versions, configurations) in a Git repository. An automated tool, such as ArgoCD, continuously monitors the repository and synchronizes the Kubernetes cluster to this declared state.

The core principles of GitOps include:

  • Declarative: The desired state of the system is defined using declarative code (e.g. YAML, JSON).
  • Version Control: The desired state is stored in a version control system such as Git.
  • Automated: Changes in Git are automatically applied to the system.
  • Continuously Reconciled: GitOps tools continuously ensure that the actual state of the system matches the desired state in Git.

About ArgoCD

ArgoCD is an open source Continuous Delivery (CD) tool built for Kubernetes, following GitOps principles. It allows you to manage and deploy Kubernetes applications declaratively by synchronizing Kubernetes resources defined in a Git repository with the target Kubernetes cluster. ArgoCD automatically detects changes in Git and applies them to the cluster, ensuring that your application always runs with the desired configuration.

ArgoCD Architecture

ArgoCD includes the following main components:

  • API Server: Provides an API interface for users to interact with ArgoCD.
  • Repository Server: Fetch Kubernetes manifests from Git repository.
  • Application Controller: Continuously monitors the state of the application, compares it to the desired state in Git, and takes necessary actions to synchronize them.
  • UI: Intuitive user interface for managing and monitoring applications.

Below is a simple diagram illustrating the architecture of ArgoCD:

Git Repository ArgoCD Kubernetes Cluster Manifests Resources

ArgoCD Setup

To start using ArgoCD, you need to install it on your Kubernetes cluster. You can use kubectl to apply the ArgoCD installation manifest:

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

Once installed, you can access the ArgoCD user interface using port forwarding:

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

The default password for the admin account is stored in a Kubernetes Secret. You can get it with the following command:

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

Deploy applications with ArgoCD

To deploy an application using ArgoCD, you need to create an Application resource. Application resource specifies a Git repository containing Kubernetes manifests, paths to the manifests, and the target Kubernetes cluster. For example, you might have a Git repository containing YAML files for your application's Deployment, Service, and Ingress.

Here is an example of Application resource:

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

In this example:

  • repoURL is the URL of the Git repository.
  • targetRevision is the branch or tag that ArgoCD will track.
  • path is the path to the Kubernetes manifests in the repository.
  • destination.server is the URL of the Kubernetes API server.
  • destination.namespace is the namespace into which the application will be deployed.
  • syncPolicy.automated.prune allows ArgoCD to automatically remove resources that no longer exist in Git.
  • syncPolicy.automated.selfHeal allows ArgoCD to automatically sync the Kubernetes cluster to the desired state in Git if there is a difference.
  • syncOptions allows to create the namespace if it does not exist yet.

Once you create Application resource, ArgoCD automatically synchronizes your application to the Kubernetes cluster.

Continuous Delivery Process with ArgoCD

ArgoCD integrates seamlessly with CI/CD pipelines. When a change is pushed to a Git repository, the CI system (e.g. Jenkins, GitLab CI, GitHub Actions) builds and tests the application, then updates the Kubernetes manifest in the Git repository. ArgoCD automatically detects these changes and deploys the new version of the application to the Kubernetes cluster.

For example, the process might be as follows:

  1. Developer commits code and pushes to Git.
  2. CI system builds, tests, and creates new Docker images.
  3. The CI system updates the Docker image's tag in the Deployment manifest file in the Git repository.
  4. ArgoCD detects changes in Git and deploys new Deployments to Kubernetes.

Rollback Strategy

One of the benefits of GitOps is the ability to rollback easily. If a new version of your application causes problems, you can simply revert the commit in your Git repository to a previous version. ArgoCD will automatically detect this revert and deploy the previous version of your application.

You can use Git tags to manage versions of your application. When you rollback, you can simply update targetRevision in Application resource to point to the tag of the desired version.

Observability Integration

Integrating observability into your GitOps pipeline is critical to monitoring application performance and health. You can use tools like Prometheus, Grafana, and the ELK stack to collect and analyze metrics, logs, and traces from your application.

ArgoCD provides hooks to integrate with observability tools. For example, you can configure ArgoCD to run a script after a successful or failed deployment to send notifications to your monitoring system.

Comparison with traditional CI/CD process

In traditional CI/CD pipelines, the CI system is typically responsible for deploying the application to the target environment. This means that the CI system needs access to the target environment, which can pose a security risk.

With GitOps and ArgoCD, the CI system is only responsible for building and testing the application, then updating the Git repository. ArgoCD is responsible for deploying the application to the Kubernetes cluster. This helps reduce security risks and increase compliance.

Here is a summary comparison table:

Features Traditional CI/CD GitOps with ArgoCD
Source of truth CI/CD System Git
Access to the target environment Request Not required
Deployment Push-based Pull-based
Rollback Complicated Simple (revert Git commit)
Security Higher risk Lower risk

Conclude

GitOps, combined with ArgoCD, provides a powerful approach to deploying Kubernetes applications declaratively, continuously, and automatically. It improves deployment speed, increases reliability, and reduces security risks. By using Git as the single source of truth and automatically synchronizing your Kubernetes cluster to the desired state in Git, you can manage your applications more efficiently and easily.

Hopefully this article has given you an overview of GitOps and ArgoCD. Give it a try and see how it can benefit your application development and deployment process.

  • Share On: