FALVARIX
FALVARIX
devops --real --no-hype

GitOps in Production with ArgoCD and Kubernetes: A Real

GitOps in Production with ArgoCD and Kubernetes: A Real

GitOps in Production with ArgoCD and Kubernetes: A Real Guide

It’s 6:47 p.m. on a Friday and someone runs kubectl apply from their laptop to “quickly fix something.” The service comes back up, but nobody knows what changed, and by Monday the cluster no longer matches what’s in the repo. Anyone who has run Kubernetes for real knows this scene, and it’s exactly the one GitOps is meant to kill.

In this guide you’ll see how to set up GitOps in production with ArgoCD: which architecture to use, how to structure your repositories, how to get automated deploys without nasty surprises, and how to roll back in seconds. No empty theory: just the decisions that matter when real traffic is on the line.

What GitOps Is and Why It Changes the Rules in Production

GitOps is an operating model in which Git is the single source of truth for the desired state of your infrastructure and applications. An agent inside the cluster continuously compares that state with the real one and corrects any drift. CNCF projects have boiled it down to four principles: declarative configuration, versioned and immutable, applied automatically, and continuously reconciled.

The difference from a traditional CI/CD pipeline is the direction of the flow:

  • Push model: the pipeline holds cluster credentials and runs kubectl or helm from the outside.
  • Pull model (GitOps): the agent lives inside the cluster, reads Git and applies changes. CI never touches production.

This shrinks your attack surface (no production kubeconfig on your CI server), gives you a full audit trail by default (every change is a commit with an author and a review), and makes disaster recovery as simple as pointing a new cluster at the same repository.

How ArgoCD Works Under the Hood

ArgoCD is a declarative continuous delivery controller for Kubernetes, graduated in the CNCF. Its main pieces are:

  • API Server: exposes the UI, the CLI and the API, and handles authentication.
  • Repo Server: clones repositories and renders manifests (Helm, Kustomize, plain YAML).
  • Application Controller: compares the rendered state with the live state in the cluster and syncs.

The unit of work is the Application resource, which links a source in Git with a destination in a cluster. ArgoCD marks each application as Synced or OutOfSync and as Healthy, Progressing or Degraded. That double signal is gold in production: you know not only whether the manifest was applied, but whether the service actually works.

A Repository Structure That Scales

The most common mistake when adopting GitOps isn’t technical, it’s organizational. Decide on the structure before you create your first application.

Keep code and config separate

Keep one repository for your application code and another for your deployment manifests. The reason is practical: not every code commit should trigger a reconciliation, and config changes (replicas, limits, image version) need their own history and their own reviewers.

The flow looks like this: CI builds the image, publishes it with an immutable tag (the commit SHA, never latest), and opens a pull request in the config repository updating that tag. Once it’s merged, ArgoCD does the rest.

Kustomize per environment

A simple, solid structure:

platform-config/
├── apps/
│   └── pagos/
│       ├── base/
│       └── overlays/
│           ├── staging/
│           └── production/
└── clusters/
    └── production/
        └── apps.yaml

The base folder holds the common bits and each overlay only describes the differences. To manage dozens of services, use the app of apps pattern or an ApplicationSet, which generates applications automatically from directories or from a list of clusters.

Automated Deploys: Getting the Application Right

Here’s the manifest for an application with automatic sync and the safeguards I recommend in production:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: pagos-production
  namespace: argocd
spec:
  project: produccion
  source:
    repoURL: https://git.ejemplo.com/platform-config.git
    targetRevision: main
    path: apps/pagos/overlays/production
  destination:
    server: https://kubernetes.default.svc
    namespace: pagos
  syncPolicy:
    automated:
      prune: true
      selfHeal: true
    syncOptions:
      - CreateNamespace=true
      - PruneLast=true
    retry:
      limit: 3
      backoff:
        duration: 10s
        factor: 2

Three options deserve attention:

  • prune: true removes from the cluster whatever no longer exists in Git. Without it, orphaned resources pile up.
  • selfHeal: true reverts any manual change. It’s the tool that puts an end to the Friday-afternoon kubectl edit.
  • retry absorbs transient failures, like an admission webhook that’s slow to start.

If your organization isn’t quite ready for full automation, start with manual sync in production and automatic in staging. Switch to automatic once your test coverage and health checks give you confidence.

Deployment Order with Sync Waves

For database migrations or dependencies, use argocd.argoproj.io/sync-wave annotations and PreSync hooks. That way the migration runs and completes before the new pods start, with no homegrown scripts.

Instant Rollbacks: The Real Acid Test

This is where GitOps proves its worth. When a deploy fails, you have two paths, and it’s worth understanding when to use each.

Rollback via Git (the recommended one). Run git revert on the problematic commit and push. ArgoCD detects the change and returns the cluster to its previous state in under a minute, or in seconds if you use webhooks instead of polling. The history stays clean, audited and reproducible: the rollback is just another commit, not a ghost event.

Rollback from ArgoCD. With argocd app rollback pagos-production <ID> or from the UI, you go back to a previous revision immediately. It’s the fast lane during a serious incident, but there’s a catch: with automatic sync enabled, ArgoCD will re-apply main and undo your rollback. To use it, turn off automatic sync for that application first. Then get Git back into the right state so repository and cluster match again.

A practical rule: if users are affected right now, roll back from ArgoCD to stop the bleeding and git revert immediately afterwards to make it stick.

Cut Your Detection Time

An instant rollback is worth little if it takes you 20 minutes to notice the problem. Connect ArgoCD Notifications to Slack or your on-call system, watch the Degraded status, and require readinessProbe and livenessProbe on all workloads, because ArgoCD evaluates health based on them.

Progressive Delivery with Argo Rollouts

The cheapest rollback is the one you never need. Argo Rollouts extends Deployment with canary and blue-green strategies: send 5% of traffic to the new version, analyze Prometheus metrics (error rate, latency) and promote or abort automatically.

The result is a cycle where a bad release affects a tiny slice of users and gets reverted with no human intervention. Combined with ArgoCD, the whole flow is declared in Git: version, rollout strategy and success criteria.

Security: Secrets, Access and Permissions

GitOps raises an uncomfortable question: if everything’s in Git, where do the credentials go? Never in plain text. You have two solid approaches: encrypt secrets before committing them or, better, keep them out of Git and reference them from an external manager. If you want to go deeper, I walk through it in secret management with OpenBao, no .env in Git, and if you’re coming from HashiCorp Vault, migrating Vault to OpenBao in production will save you a few stumbles.

For human access, don’t hand out the ArgoCD admin account. Integrate SSO via OIDC and assign roles per team; a guide to Keycloak SSO for microservices covers deploying the identity provider. Round it out with:

  • AppProjects that limit which repositories, clusters and namespaces each team can touch.
  • RBAC with read-only for most and sync permissions only for those who need them.
  • Signed commits and protected branches in the config repository, with mandatory review. In GitOps, whoever can merge into main can deploy to production.

Common Mistakes When Taking GitOps to Production

  • Using mutable tags like latest: you lose reproducibility and rollbacks stop being reliable.
  • Mixing HPA with fixed replicas in Git: ArgoCD and the autoscaler fight each other. Use ignoreDifferences on spec.replicas.
  • One giant repository with no clear ownership: conflicts and bottlenecks show up fast.
  • Not backing up ArgoCD: even though state lives in Git, export its own configuration (projects, clusters, credentials) or manage ArgoCD with ArgoCD itself.
  • Ignoring drift alerts: if OutOfSync status becomes background noise, the system loses its value.

How to Start Without Breaking Anything

A realistic plan for the next few weeks:

  1. Install ArgoCD on a staging cluster and migrate one simple application.
  2. Define the repository structure and pull request rules.
  3. Enable selfHeal and confirm nobody needs to touch the cluster by hand anymore.
  4. Rehearse a rollback with git revert and time it.
  5. Roll out to production with manual sync, then automatic.
  6. Add Argo Rollouts on your critical services.

Conclusion

GitOps with ArgoCD turns deployments into a boring process, and that’s exactly what you want in production. Every change gets reviewed, every state is reproducible, and every mistake is undone with a commit. The upfront investment is discipline: tidy repositories, immutable images and zero manual changes. In return, you get a cluster that explains itself and a team that no longer dreads Fridays.

Keep Reading