Kahibaro
Discord Login Register

GitOps with Argo CD

Core GitOps Concepts in the Context of Argo CD

GitOps in OpenShift means that Git is the source of truth for application and (often) cluster configuration, and Argo CD is the controller that continuously reconciles the cluster to match what is in Git.

Specific to Argo CD, this implies:

Argo CD Architecture on OpenShift

Argo CD is typically installed into a dedicated namespace (commonly openshift-gitops when using Red Hat’s OpenShift GitOps Operator). Key components to understand:

On OpenShift, the OpenShift GitOps Operator:

Defining Applications with Argo CD

The central object in Argo CD is the Application custom resource. It links where to get configuration (Git, path, revision) and where to deploy it (cluster and namespace).

Basic `Application` Structure

Typical fields in an Application manifest:

Example: Minimal `Application` for OpenShift

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: my-sample-app
  namespace: openshift-gitops           # Argo CD instance namespace
spec:
  project: default
  source:
    repoURL: 'https://github.com/example-org/my-sample-app-config.git'
    targetRevision: main
    path: overlays/production
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: my-sample-app
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

Key points specific to OpenShift:

Managing Multiple Environments with GitOps

With Argo CD, environment separation is modeled in Git and Argo CD configuration, rather than hard-coded in CI scripts.

Common Environment Patterns

  1. Separate directories in a single repo

Example structure:

   config-repo/
     base/
       deployment.yaml
       service.yaml
     overlays/
       dev/
         kustomization.yaml
         patch-resources.yaml
       staging/
         kustomization.yaml
         patch-resources.yaml
       prod/
         kustomization.yaml
         patch-resources.yaml
  1. Separate repos per environment
    • my-app-config-dev.git, my-app-config-prod.git, etc.
    • Sometimes used in highly regulated environments to separate access.
  2. App-of-Apps pattern
    • A “root” or “umbrella” Application points at a repo that defines many child Applications.
    • Used to bootstrap entire environments (namespaces, operators, apps) from one Git entry point.

Example: App-of-Apps for an OpenShift Environment

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: env-prod-root
  namespace: openshift-gitops
spec:
  project: default
  source:
    repoURL: 'https://github.com/example-org/cluster-config.git'
    targetRevision: main
    path: environments/prod
  destination:
    server: 'https://kubernetes.default.svc'
    namespace: openshift-gitops
  syncPolicy:
    automated:
      prune: true
      selfHeal: true

The environments/prod directory typically contains YAML definitions of child Applications (e.g. apps, logging stack, monitoring, etc.).

Integrating Argo CD into OpenShift-Based CI/CD

In the broader CI/CD pipeline, Argo CD focuses on the CD part. The CI system (e.g. OpenShift Pipelines, Jenkins, GitHub Actions) and Argo CD collaborate via Git:

  1. CI builds an image
    • CI builds and pushes container images into a registry (e.g. ImageStream in OpenShift, external registries).
    • CI updates configuration in a Git repo (e.g., update image tag in a Helm values.yaml or Kustomize patch).
  2. Git commit triggers reconciliation
    • The CI pipeline creates a pull request with the new image tag.
    • Once the PR is reviewed and merged, the target Git branch updates.
  3. Argo CD detects the Git change
    • Argo CD notices the new commit.
    • If auto-sync is enabled, it applies new manifests to the target environment; otherwise, a manual sync is triggered.
  4. Status flows back
    • Argo CD shows sync/health status in its UI and via its API/CLI.
    • CI or other tools may query Argo CD to confirm that deployment succeeded.

Typical interactions with OpenShift features:

Security and Access Control with Argo CD on OpenShift

With Argo CD integrated into OpenShift, security and RBAC should be designed to align with both Git and cluster permissions.

Authentication and SSO

Authorization and RBAC

There are two layers:

  1. Argo CD RBAC (application-level)
    • Controls who can:
      • Create/edit/delete Applications.
      • Sync or rollback applications.
    • Configuration is typically done via the Argo CD ConfigMap (argocd-rbac-cm) or via the GitOps Operator’s custom resource.
  2. OpenShift RBAC (cluster-level)
    • Controls what the service account used by Argo CD can do in each namespace.
    • A common pattern:
      • Platform team grants Argo CD service accounts edit or similar roles in selected namespaces.
      • Argo CD is not given cluster-admin; permissions are scoped appropriately.

Git Credentials and Repositories

Application Health, Sync Status, and Drift Detection

Argo CD provides two key status dimensions for each application:

Drift detection is especially relevant in OpenShift:

Handling OpenShift-Specific Resources with GitOps

Argo CD can manage any Kubernetes-style resource, including those specific to OpenShift. Typical categories:

Typical Workflows for Teams Using Argo CD on OpenShift

Developer Workflow

  1. Modify application code and configuration (usually in separate repos).
  2. Commit code -> CI pipeline runs, builds new image.
  3. CI updates config repo (image tag, environment parameters) via pull request.
  4. After review and merge, Argo CD syncs changes into the target OpenShift namespace.
  5. Developer verifies the deployment via:
    • Argo CD UI (sync/health status).
    • OpenShift console (Pods, Routes, logs).
    • Application tests.

Platform / SRE Workflow

  1. Define cluster configuration (logging, monitoring, security baselines) in Git.
  2. Represent these as Argo CD applications (often using the App-of-Apps pattern).
  3. Use Argo CD to bootstrap new OpenShift clusters:
    • Install core operators.
    • Create shared namespaces and quotas.
    • Apply default NetworkPolicy, LimitRange, etc.
  4. Manage upgrades by updating Git definitions and allowing Argo CD to roll changes out.

Best Practices for Using Argo CD in OpenShift Environments

By combining Git as the single source of truth, Argo CD as the reconciliation engine, and OpenShift as the runtime platform, teams get a consistent, auditable, and automated path from configuration changes in Git to running applications and platform services in the cluster.

Views: 16

Comments

Please login to add a comment.

Don't have an account? Register now!