← Back to Blog

Gitops With Argocd

Gitops With Argocd GitOps is a set of practices that leverages Git as the single source of truth for declarative infrastructure and applications.

Gitops With Argocd

GitOps is a set of practices that leverages Git as the single source of truth for declarative infrastructure and applications. With ArgoCD, a popular continuous delivery tool for Kubernetes, you can implement GitOps to automatically sync your Kubernetes clusters with your desired state as defined in Git.

Here’s a simple example to demonstrate GitOps with ArgoCD:

Prerequisites

  • Kubernetes Cluster: You should have a running Kubernetes cluster.

  • ArgoCD Installed: Install ArgoCD in your Kubernetes cluster if not already installed.

  • Git Repository: A Git repository that contains the Kubernetes manifests or Helm charts.

Step-by-Step Example

1. Install ArgoCD

First, if you haven't installed ArgoCD, you can install it using the following commands:kubectl create namespace argocd kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml

2. Access ArgoCD UI

After installation, access the ArgoCD UI by port-forwarding the ArgoCD server:kubectl port-forward svc/argocd-server -n argocd 8080:443

Visit https://localhost:8080 and log in with the initial admin password, which you can retrieve with:kubectl get secret argocd-initial-admin-secret -n argocd -o jsonpath="{.data.password}" | base64 -d

3. Prepare Your Git Repository

Your Git repository should have a directory structure like this:├── argocd-apps/ │ └── my-app/ │ ├── deployment.yaml │ ├── service.yaml │ └── ...

In this example, my-app contains the Kubernetes manifests for your application.

4. Create an ArgoCD Application

You can create an ArgoCD application using the CLI or UI. Below is an example of using the CLI:argocd app create my-app \ --repo https://github.com/your-repo/your-app-config-repo.git \ --path argocd-apps/my-app \ --dest-server https://kubernetes.default.svc \ --dest-namespace default

Here’s what the flags mean:

  • --repo: The URL of your Git repository.

  • --path: The path within the repo where your manifests are located.

  • --dest-server: The address of the Kubernetes API server.

  • --dest-namespace: The namespace where your application will be deployed.

5. Sync Your Application

You can manually sync your application using the ArgoCD CLI or UI, or let ArgoCD automatically sync when it detects changes in the Git repository.

To sync manually:argocd app sync my-app

This will apply the Kubernetes manifests defined in your Git repository to your Kubernetes cluster.

6. Monitor and Manage

You can monitor the state of your application through the ArgoCD UI. ArgoCD will show you whether the deployed state in the cluster matches the desired state in the Git repository. If there are differences, you can choose to sync them.

7. Automated Syncing and Self-Healing

You can enable automated syncing and self-healing (to revert manual changes in the cluster that aren't reflected in Git):argocd app set my-app --sync-policy automated argocd app set my-app --self-heal

With these settings, ArgoCD will automatically apply changes when it detects updates in the Git repository and will revert any changes made directly in the cluster that deviate from the Git state.

Summary

  • ArgoCD is used to deploy applications to Kubernetes by syncing the desired state from a Git repository.

  • The Git repository is the single source of truth for application manifests.

  • ArgoCD automatically ensures that the live state in the Kubernetes cluster matches the desired state defined in Git.

This is a basic example, but ArgoCD supports more advanced use cases, such as managing multiple applications and clusters, using Helm charts, and integrating with CI/CD pipelines.


Imported from rifaterdemsahin.com · 2025