All guides

Argo CD: Git as the record of what runs in the cluster

Argo CD is a Kubernetes controller that compares what runs in a cluster with what a Git repository says should run. With automated sync, a pipeline deploys by committing to Git and needs no direct access to the Argo CD API server.

Hands typing on a laptop that shows code

The pull model

The OpenGitOps principles, version 1.0.0, say that software agents automatically pull the desired state declarations from the source.

Argo CD's documentation describes the tool as following GitOps: a Git repository holds the desired state of each application and is treated as the source of truth. It is implemented as a Kubernetes controller that continuously monitors running applications and compares the live state with the target state in Git. Argo CD marks an application OutOfSync when its live state differs from the target state.

One documented benefit of automated sync: A CI/CD pipeline then has no further need to reach the Argo CD API server directly. The pipeline makes a commit and a push to the Git repository that holds the manifests.

Install Argo CD

Shell

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

--server-side is required because some Argo CD custom resource definitions exceed the size limit of a client-side kubectl apply.

The documentation recommends a pinned version for production. Its installation page lists install.yaml as not recommended for production use and recommends the high-availability manifest, ha/install.yaml.

The password of the admin account is generated and stored in a Secret named argocd-initial-admin-secret. Read it with the CLI, then reach the API server at https://localhost:8080 through a port-forward:

Shell

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

A first Application

An Application is a custom resource with a source in Git (repository, revision, path) and a destination (cluster and namespace).

YAML

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

The repository address, the main revision, the path and the my-app names are values to replace with your own. Apply the file with kubectl apply -n argocd -f application.yaml. The namespace of the Application must match the namespace of your Argo CD instance.

https://kubernetes.default.svc is the address to use when Argo CD deploys to the cluster it runs in. CreateNamespace=true makes sure the destination namespace exists.

The path can hold plain manifests, a Kustomize application, a Helm chart or Jsonnet files.

Automated sync, prune and self-heal

A new application starts as OutOfSync. With no automated block you sync it yourself, with argocd app sync my-app or the Sync button in the UI. With the block, Argo CD syncs when it detects a difference between Git and the live state. Two options are off by default:

  • prune. As a safety mechanism, automated sync does not delete a resource that is no longer defined in Git. prune: true turns that deletion on.
  • selfHeal. Changes made to the live cluster do not trigger an automated sync. selfHeal: true syncs when the live state deviates from Git.

The sync interval comes from timeout.reconciliation in the argocd-cm ConfigMap. It defaults to 120s with 60s of added jitter, a maximum of three minutes.

One documented rule to know: an application that has automated sync enabled cannot be rolled back.

Sync status and health

Argo CD reports two separate statuses.

  • Sync status is whether the live state matches the target state. The documentation shows Synced and OutOfSync.
  • Health is assessed for each resource. The documentation lists Healthy, Progressing, Degraded, Suspended, Missing and Unknown.

For a Deployment, the observed generation must equal the desired generation, and the number of updated replicas must equal the number of desired replicas.

The health of an application is the worst health of its immediate child resources. argocd app get my-app prints both statuses for the application and for each resource.

Projects and single sign-on

Every application belongs to a single project. With none named, it belongs to the default project, which permits deployments from any source repository, to any cluster, and all resource kinds. The documentation calls that project useful for initial testing and recommends dedicated projects with explicit source, destination and resource permissions:

YAML

apiVersion: argoproj.io/v1alpha1
kind: AppProject
metadata:
  name: team-a
  namespace: argocd
spec:
  sourceRepos:
    - https://github.com/my-org/my-app-config.git
  destinations:
    - server: https://kubernetes.default.svc
      namespace: my-app

The name team-a, the repository and the namespace are yours to choose. Cluster-scoped resources are restricted through an allow list, the clusterResourceWhitelist field. Project roles are bound to OIDC groups or JWT tokens.

After installation Argo CD has one built-in admin user with full access. The documentation recommends it for initial configuration only. It describes two ways to configure single sign-on, both in the argocd-cm ConfigMap:

  • an existing OIDC provider, under the oidc.config key, when you already manage users in one;
  • the bundled Dex, under dex.config, when your provider does not support OIDC, for example SAML or LDAP.

Once other users exist, the documentation recommends admin.enabled: "false". An authenticated user is granted the role named in policy.default of the argocd-rbac-cm ConfigMap. The RBAC page recommends a default role with the minimum set of permissions.

Checks after the first sync

  1. The deletion finalizer. Deleting an Application does not delete the resources it manages unless metadata.finalizers holds resources-finalizer.argocd.argoproj.io. Add it if a delete should cascade.
  2. The initial password. Change it with argocd account update-password, then delete the argocd-initial-admin-secret Secret.
  3. Exposure. By default Argo CD is not exposed outside the cluster. The documented ways in are a LoadBalancer Service, an ingress and the port-forward. Configure single sign-on and the RBAC policy before you use either of the first two.

Sources

Want a second pair of eyes on yours? We do this work for a living.

Book a call

More guides