ConfigHub · Durable config for coding agents
Docs / docs/gitops-over-oci.md Source on GitHub →

GitOps over OCI: Flux and Argo CD deploying from ConfigHub

This page is for a platform team that runs Flux or Argo CD, and whose agents now propose changes to what those tools deploy. It shows how to make the cluster deploy only changes a named person has approved, with the reason for each value kept. To move an app that Argo CD or Flux already deploys from your Git, and hand it back, see an app that Argo CD or Flux deploys.

The walkthroughs a Kustomize app that Argo CD deploys and a Kustomize app that Flux deploys do this on a kind cluster with a starter, with every command and what it prints.

What "deploying from the hub over OCI" means

Today, your cluster's Flux or Argo CD deploys whatever reaches the Git branch it watches. A person has to read every agent's diff to know whether it should ship. Nothing in Git says why a value is what it is.

With this setup, your cluster's Flux or Argo CD pulls the approved configuration from ConfigHub instead of from Git:

  1. An agent proposes a change in ConfigHub. The change waits.
  2. A person you name approves it.
  3. ConfigHub publishes the approved configuration as a release.
  4. Flux or Argo CD pulls the release from ConfigHub and applies it.

A change someone makes by hand on the cluster is put back. Going back to an earlier value is an approved change like any other. For every release, ConfigHub shows what the cluster reported about it.

You can keep writing and reviewing changes in Git. What the cluster runs is what was approved in ConfigHub. Flux calls this Gitless GitOps.

From Git to the hub, one step at a time, and back

You do not have to move delivery off Git to get anything on this page. Each step below is reversible, and you can stop at any of them.

StepWhat changesWhat you getTo go back
1. The Claude pluginthe record in agent sessions; the review on pull requestsevery configuration value a pull request changes, per cluster, and why; the next agent told before it undoes an earlier change; Git still deliversuninstall the Claude plugin
2. A hub beside Gitcub local copy --from-git takes the repository's rendered configuration into a hub, which keeps each value's reason and protects the ones you choose; the hub's approval appears on each pull request as a status, and your branch rule requires that statusapprovals of exact values; values kept through a chart's next version; Git still delivers. The branch rule requiring the status is what makes the approval one that Git cannot bypassstop the hub; Git is untouched
3. The hub as the source for one appthat app's Flux source or Argo CD Application is pointed at the hub's OCI gateway instead of the Git path; Git keeps everything elsethe hub's approval is the only way a change reaches that app; an agent's kubectl change is set back by the next sync, and the hub says what differedcub local copy --to-dir writes plain files and a CHANGES.md; commit them, point the source back at Git, stop the hub
4. The hub as the source for everythingthe clusters deploy from the hub; Git holds rendered files written back for people to read and diffone source, with Git still legibleas step 3, app by app

Steps 1 to 3 have run; the rest of this page is step 3. Step 4's write-back to Git is not built. Nothing on this page is a migration: a GitOps team meets the hub as the source for one app, beside its Git, and goes back by committing files.

The words on this page, such as hub, base and change order, are explained in the glossary.

What you need

The steps below set this up on the local hub and a local kind cluster. Then they show the four things a GitOps team asks about: a change that waits for a person's approval, self-heal, going back, and the cluster's status in ConfigHub.

The cub mini commands on this page are plain cub with the rest of the request filled in (which commands). For your own cluster with a shared hub on confighub.com, further down, the same is shown with cub alone.

The example follows Dan's platform team, which runs Flux and Argo CD with self-heal on.

Step 1: Make the cluster, with Flux and k8sbot

  1. Make the cluster:
    cub cluster up shop --controller flux

    This makes a kind cluster named shop, installs Flux in it, and connects it to the hub. It adds:

    • an OCIRepository and a Kustomization, which pull the cluster's apps from ConfigHub;
    • k8sbot.

    To install Argo CD in place of Flux, use --controller argo (With Argo CD).

  2. Point your shell at the cluster:
    source ~/.confighub/clusters/shop.env

    This sets KUBECONFIG, and the cub context for the cluster.

On OrbStack, put gitops/docker first on your PATH for this step. Otherwise cub points the cluster at an address that does not reach a hub listening on 127.0.0.1. With Docker Desktop you do not need this.

Step 2: Deploy an app from the hub

  1. Make a folder for the app, with its Namespace:
    mkdir api
    cat > api/namespace.yaml <<'EOF2'
    apiVersion: v1
    kind: Namespace
    metadata: {name: shop}
    EOF2

    The Namespace belongs with the app, since Flux creates nothing it is not given.

  2. Add the Deployment:
    cat > api/api.yaml <<'EOF2'
    apiVersion: apps/v1
    kind: Deployment
    metadata: {name: api, namespace: shop}
    spec:
      replicas: 2
      selector: {matchLabels: {app: api}}
      template:
        metadata: {labels: {app: api}}
        spec:
          containers:
          - {name: api, image: registry.k8s.io/pause:3.10}
    EOF2
  3. Put the app in the hub, as the Component api with a live copy:
    cub repo upload api --variant live --namespace shop --yes

Flux now runs 2 replicas of api, pulled from the hub.

This is what Flux pulls from, as cub cluster up and cub repo upload set it up:

apiVersion: source.toolkit.fluxcd.io/v1
kind: OCIRepository
metadata: {name: api-live, namespace: flux-system}
spec:
  url: oci://host.docker.internal:PORT/space/api-live   # the hub's OCI registry, one repository per Space
  ref: {tag: latest}
  secretRef: {name: confighub-oci}                      # the cluster's own key to the hub
  interval: 10m
---
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata: {name: api-live, namespace: flux-system}
spec:
  sourceRef: {kind: OCIRepository, name: api-live}
  path: .
  interval: 10m
  prune: false
  wait: true

Step 3: A change that waits for a person

  1. Require approval for the live copy, and make an agent named bot:
    cub agent require-approval api --variant live --agent bot

    --agent bot gives the agent a key of its own, in a cub configuration of its own, ~/.confighub-agent-bot. The next two commands run cub as the agent, by pointing CUB_CONFIG and CUB_CONTEXT at that configuration.

  2. As the agent, change the base to 4 replicas:
    CUB_CONFIG=~/.confighub-agent-bot CUB_CONTEXT=bot cub function set --space api-base --unit api --change-desc "Four for the sale" set-replicas 4
  3. As the agent, ask for the change to reach the live copy, with a change order:
    CUB_CONFIG=~/.confighub-agent-bot CUB_CONTEXT=bot cub changeorder create --space api-base sale-4 --component api --change-workflow workflows/api-live-approval --description "Four for the sale"

    The agent's change waits. Nothing is released, and the cluster still runs 2 replicas.

  4. As yourself, approve the change and promote it to the live copy:
    cub inbox approve api-live --note "Checked: four is right for the sale"

    It shows the change and asks first. ConfigHub releases the change, and k8sbot asks Flux to deploy it. Shortly after, the cluster runs 4 replicas.

Step 4: Self-heal

  1. Change the cluster by hand:
    kubectl -n shop scale deploy api --replicas=7
  2. Ask Flux to apply the release again now:
    flux reconcile kustomization api-live -n flux-system --with-source

    Flux applies the approved release again, and the cluster is back at 4 replicas.

Without the flux reconcile, Flux does the same at its next interval, which is 10 minutes here. Argo CD, with self-heal on as cub cluster up sets it, put the approved value back by itself.

Step 5: Go back

Going back is a change like any other, so it waits for an approval too.

  1. Change the base back to 2 replicas:
    cub function set --space api-base --unit api --change-desc "The sale is over" set-replicas 2
  2. Ask for it with a change order:
    cub changeorder create --space api-base back-to-2 --component api --change-workflow workflows/api-live-approval --description "The sale is over"
  3. Approve and promote it:
    cub inbox approve api-base/back-to-2 --note "Back to two"

    Shortly after, the cluster runs 2 replicas again.

cub variant demote restores the earlier revision in the hub, but it is not the way back here. Where approval is required, ConfigHub releases only what an approved change order covers. So the way back is a change order, as above.

Step 6: See what runs, in ConfigHub

$ cub release list --space api-live
NUM    TAG                              CHANGEORDER           PUBLISHED    SYNC         HEALTH
3      api-base/back-to-2-co-publish    api-base/back-to-2    true         Synced       Healthy
2      api-base/sale-4-co-publish       api-base/sale-4       true         OutOfSync    Unknown
1      release-1                                              true         OutOfSync    Unknown

Each line is one release. It shows the change order that made the release, and what k8sbot last reported from the cluster. Only the release running now reads Synced. Earlier releases read OutOfSync once a later one has replaced them.

With Argo CD

cub cluster up shop --controller argo installs Argo CD in place of Flux. Each deployment is an Argo CD Application that reads the hub's OCI registry, with auto-sync and self-heal on:

apiVersion: argoproj.io/v1alpha1
kind: Application
metadata: {name: api-live, namespace: argocd}
spec:
  project: default
  source:
    repoURL: oci://host.docker.internal:PORT/space/api-live
    targetRevision: latest
    path: .
  destination: {server: https://kubernetes.default.svc}
  syncPolicy:
    automated: {selfHeal: true, allowEmpty: true}

The other steps are the same, except that step 4 needs no flux reconcile. Argo CD's UI is at the address cub cluster up prints.

With Argo CD, the approved change runs a few seconds after the promotion, and so does going back. Every release reads Synced and Healthy.

Your own cluster, with hosted ConfigHub

The same works with a cluster you already have and a shared hub on confighub.com, or a ConfigHub server of your own.

  1. Sign in to ConfigHub with cub auth login, and point kubectl at your cluster.
  2. Connect the cluster to ConfigHub:
    cub cluster attach my-cluster

    cub cluster attach connects the cluster your kubeconfig points at to ConfigHub. It creates no cluster. It adds:

    • a credential Argo CD pulls with: a token of a service account made for the cluster;
    • a root Application;
    • k8sbot.

    An Argo CD already in the argocd namespace is left as it is. Otherwise Argo CD is installed. You need Argo CD v3.1 or later, for oci:// sources.

    For Flux, run cub cluster attach my-cluster --controller flux instead. A Flux already in flux-system is left as it is.

  3. Put the app in ConfigHub, make its live copy aimed at the cluster, and publish its first release:
    cub component create api
    cub space create api-base --component api --variant base
    cub unit create --space api-base namespace api/namespace.yaml
    cub unit create --space api-base api api/api.yaml
    cub variant create live api-base --target my-cluster/target
    cub release publish api-live

    Argo CD pulls the release from oci://oci.hub.confighub.com:443/space/api-live.

  4. Set up the approval gate with cub alone, as in approvals.
  5. After the approval, promote the change and release it, by its change order:
    cub variant approve api-base --change-order api-base/sale-4 --note "Checked: four is right for the sale"
    cub variant promote api-live --change-order api-base/sale-4
    cub release publish api-live --revision ChangeOrder:api-base/sale-4

What you see with Argo CD already on the cluster, here v3.1.9:

What you see with Flux already on the cluster (flux install):

To remove it:

A change made in Git

Dan's team still reviews some changes as pull requests. The hub's copy can live in a Git repository of its own, written by the hub. A change merged there comes back into the hub, with the pull request's reason.

  1. Write the hub's copy to the root of a new folder. You do this once:
    cub local copy api --variant live --to-dir shop-config     # once: the hub's copy, at the root of a new repository
  2. Make the folder a Git repository:
    cd shop-config && git init -b main && git add -A && git commit -m "The hub's copy" && cd ..
  3. A pull request changes shop-config/api-live/api.yaml, is reviewed, and is merged.
  4. Bring the merged change into the hub:
    cub local copy --from-git shop-config --variant live --since FIRST-COMMIT

    The value is kept in the hub. Its reason is the commit's message, the commit, and its author. The cluster then runs it.

Replace FIRST-COMMIT with the hash of the commit made in step 2, "The hub's copy" (right after step 2, git -C shop-config log --format=%h -1 prints it). --since takes in every change committed after it. The commit taken in is recorded on the copy, so you need --since only the first time.

Each top-level folder of the repository is a Space. So the copy must be at the root of the repository, not in a subfolder.

For example, with Flux and no approval required for live, a merged change from 2 to 3 replicas is kept in the hub as "Three for the launch, reviewed in a pull request (Git, commit bb2beb3, by Dan)", and the cluster runs 3 replicas a few seconds later.

When the hub is down

What runs keeps running. The controller holds the last release it pulled.

With Flux, while the hub is stopped:

We haven't tried this with Argo CD yet.

What k8sbot may do in your cluster

k8sbot reads, and makes one kind of write.

On the cluster cub cluster up --controller flux makes, k8sbot's service account has two ClusterRoles:

With Argo CD, k8sbot patches an Application's refresh annotation instead, as its own README describes.

Remove the cluster

cub cluster down shop --delete-config

This deletes the cluster, and its setup in the hub.