DEV Community

Cover image for ๐Ÿš€ GitOps Made Simple: Automating Deployments with ArgoCD & Helm
Romulo Franca
Romulo Franca

Posted on

๐Ÿš€ GitOps Made Simple: Automating Deployments with ArgoCD & Helm

๐Ÿ˜‚ Introduction: Why GitOps? Because CI/CD Needed a Makeover

Picture this: Your team is manually deploying apps to Kubernetes. The YAMLs are scattered, and no one knows which version is running in production. Jenkins jobs fail randomly, and rollback is a prayer-based process. Sound familiar?

Enter GitOpsโ€”the DevOps methodology that treats Git as the single source of truth for your infrastructure and applications. Instead of manually applying changes, you commit them to Git, and a tool like ArgoCD ensures your cluster stays in sync. Pair this with Helm to manage Kubernetes manifests like a pro, and you've got a rock-solid deployment strategy.

By the end of this guide, you'll:

โœ… Understand the core principles of GitOps

โœ… Set up ArgoCD for automated Kubernetes deployments

โœ… Use Helm to simplify and manage Kubernetes applications

โœ… Implement CI/CD pipelines to build, test, and scan container images

โœ… Learn how to separate application and infrastructure repositories for better modularity

So, grab your coffee โ˜•, and letโ€™s dive into automated deployments with ArgoCD, Helm, and CI/CD pipelines!


๐Ÿ” What is GitOps? (And Why You Should Care)

๐Ÿ“Œ GitOps in a Nutshell

GitOps is a developer-centric approach to managing infrastructure and applications using Git. Itโ€™s based on these core principles:

1๏ธโƒฃ Declarative Configuration โ€“ Everything (infra, apps) is defined as code.

2๏ธโƒฃ Versioned & Immutable โ€“ Git acts as the source of truth. Rollbacks are as easy as git revert.

3๏ธโƒฃ Automated Syncing โ€“ A tool (like ArgoCD) ensures the actual state in Kubernetes matches the desired state in Git.

4๏ธโƒฃ Continuous Reconciliation โ€“ If someone accidentally applies a change outside Git, GitOps automatically fixes it.

๐ŸŽฏ Why ArgoCD?

ArgoCD is a lightweight, Kubernetes-native GitOps tool that continuously monitors Git repositories and applies the desired state to your cluster.

โœ… Self-healing โ€“ If someone changes something manually, ArgoCD will fix it.

โœ… Multi-cluster support โ€“ Manage multiple clusters from a single dashboard.

โœ… Easy Rollbacks โ€“ Revert to a previous commit and ArgoCD will handle the rest.

โœ… RBAC & SSO support โ€“ Secure your deployments with fine-grained access control.


๐Ÿ”ง Setting Up ArgoCD in Kubernetes

Before we automate anything, letโ€™s get ArgoCD installed on our Kubernetes cluster.

๐Ÿ”น Step 1: Install ArgoCD

ArgoCD runs inside Kubernetes, and installing it is as simple as:

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

Verify the installation:

kubectl get pods -n argocd
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”น Step 2: Expose the ArgoCD API Server

By default, ArgoCD runs internally. To access the UI, expose it via kubectl port-forward:

kubectl port-forward svc/argocd-server -n argocd 8080:443
Enter fullscreen mode Exit fullscreen mode

Now, open your browser and navigate to https://localhost:8080. ๐ŸŽ‰

๐Ÿ”น Step 3: Login to ArgoCD

Get the initial admin password:

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

Login using the CLI:

argocd login localhost:8080 --username admin --password <your-password>
Enter fullscreen mode Exit fullscreen mode

๐Ÿ›  Deploying an Application with ArgoCD and Helm

Now that we have ArgoCD running, letโ€™s deploy a sample application using Helm.

๐Ÿ“Œ What is Helm?

Helm is a package manager for Kubernetes that simplifies deploying applications by using charts. Instead of managing hundreds of YAML files, you define parameters in values.yaml, and Helm takes care of the rest.

๐Ÿ”น Step 1: Separate Your Repositories

To follow GitOps best practices, separate your repositories into:

โœ… Application Repository โ€“ Contains your app code, Dockerfile, and CI/CD pipeline for building images.

โœ… Infrastructure Repository โ€“ Contains your Helm charts, ArgoCD configurations, and Kubernetes manifests.

๐Ÿ“‚ app-repo/
  โ”œโ”€โ”€ src/
  โ”œโ”€โ”€ Dockerfile
  โ”œโ”€โ”€ .github/workflows/build-and-push.yaml  # CI/CD pipeline
  โ”œโ”€โ”€ README.md

๐Ÿ“‚ infra-repo/
  โ”œโ”€โ”€ charts/
  โ”œโ”€โ”€ values.yaml
  โ”œโ”€โ”€ applications/
  โ”œโ”€โ”€ argocd.yaml
  โ”œโ”€โ”€ README.md
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”น Step 2: CI/CD Pipeline for Building, Testing, and Scanning

Use GitHub Actions, GitLab CI, or Jenkins to:

1๏ธโƒฃ Build the container image

2๏ธโƒฃ Scan for vulnerabilities (Trivy, Snyk, or Clair)

3๏ธโƒฃ Run tests (Unit tests, integration tests)

4๏ธโƒฃ Push the image to a container registry

Example GitHub Actions Workflow (build-and-push.yaml):

name: Build and Push Docker Image

on:
  push:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Login to DockerHub
        run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin

      - name: Build and tag Docker image
        run: |
          docker build -t my-app:latest .
          docker tag my-app:latest my-dockerhub/my-app:${{ github.sha }}

      - name: Scan image for vulnerabilities
        uses: aquasecurity/trivy-action@master
        with:
          image-ref: 'my-dockerhub/my-app:${{ github.sha }}'
          format: 'table'

      - name: Push Docker image
        run: |
          docker push my-dockerhub/my-app:${{ github.sha }}
Enter fullscreen mode Exit fullscreen mode

๐Ÿ”น Step 3: Configure ArgoCD to Watch Helm Chart Repo

Now, create an ArgoCD application that points to your Helm chart repository:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-helm-app
  namespace: argocd
spec:
  destination:
    namespace: default
    server: https://kubernetes.default.svc
  project: default
  source:
    chart: my-app
    repoURL: https://github.com/example/infra-repo
    targetRevision: main
    helm:
      values: |
        image:
          repository: my-dockerhub/my-app
          tag: latest
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
Enter fullscreen mode Exit fullscreen mode

Apply the application manifest:

kubectl apply -f my-app.yaml
Enter fullscreen mode Exit fullscreen mode

๐Ÿ” Best Practices for GitOps with ArgoCD and Helm

โœ… Separate Application & Infrastructure Repositories โ€“ Keep your app code and deployment configs independent.

โœ… Use CI/CD Pipelines โ€“ Automate image building, scanning, and testing.

โœ… Enable RBAC in ArgoCD โ€“ Restrict who can apply changes.

โœ… Use Helm Secrets or SOPS โ€“ Never store plaintext secrets in Git.

โœ… Monitor with Prometheus & Grafana โ€“ Use ArgoCD metrics for insights.

โœ… Automate Image Updates โ€“ Use ArgoCD Image Updater to pull new images.


๐Ÿ“ข Conclusion: GitOps FTW! ๐Ÿš€

By combining ArgoCD, Helm, and CI/CD pipelines, you get:

โœ” Automated deployments

โœ” Self-healing applications

โœ” Secure & scalable pipelines

๐Ÿ”ฅ Try deploying your own apps using GitOps and let me know how it goes! ๐Ÿš€

๐Ÿ‘‰ Next Steps:

Happy GitOps-ing! ๐ŸŽ‰

Top comments (0)