Skip to content

cub cluster attach

cub cluster attach

Wire a cluster you already have into ConfigHub, via Argo CD, Sveltos or Flux

Synopsis

Attaches a cluster you already have — any cluster your kubeconfig can reach with cluster-admin — into ConfigHub. It is everything "cub cluster up" does after creating its kind cluster, and "cub cluster up" is built on it.

Attach never creates or destroys a cluster. The inverse, "cub cluster detach", removes the wiring and leaves the cluster running.

Its first part — the controller in the cluster, the cluster Space and its OCI target — is "cub cluster controller-install", and its second — the cluster's service account, with its key and pull token in the cluster — is "cub cluster svc-account-bootstrap". Either can be run on its own first, in that order. Its third — the apps Space and the root — is "cub cluster app-bootstrap", which finishes the attachment without k8sbot, and its last, k8sbot, is "cub cluster k8sbot-install", which installs it in a cluster attached with --no-k8sbot. Attach then picks the cluster up where they left it: it keeps the credentials, controller, Space, target and service account, takes the controller and Space from them, and ignores the flags of those parts (--provider and the credential flags, --controller-version, --no-install and --no-placeholder-gate).

Where the cluster's credentials come from is --provider:

kubeconfig (default) your kubeconfig — $KUBECONFIG or ~/.kube/config, or --kubeconfig — at its current context, or the one --kube-context names. eks the AWS CLI: "aws eks update-kubeconfig" for the cluster named by --cluster (defaults to the cluster name), honoring --aws-region and --aws-profile or the usual AWS environment. The kubeconfig authenticates through the CLI, so it stays good as long as your AWS credentials are. kind a kind cluster already on this machine, named by --cluster (defaults to the cluster name), through "kind get kubeconfig". "cub cluster up" is the command that creates one and attaches it.

A self-contained copy of the credentials is written to /clusters/.kubeconfig, beside a record of which ConfigHub server and organization the cluster is wired to, so "cub cluster list", "open" and "down" find it whichever cub context is current. A kubeconfig with a static token that expires, expires in the copy too.

An EKS cluster created by something other than you — an ACK controller, a pipeline role — grants its bootstrap admin access to that identity, and rejects you with a bare 401. Attach diagnoses that: if your AWS identity has no access entry on the cluster it prints the commands that add one, or runs them for you with --grant-access (an access entry with the AmazonEKSClusterAdminPolicy).

What it sets up, in the cluster:

Argo CD installed from the upstream manifest if the argocd namespace has no argocd-server; an existing Argo CD is left as found (--no-install fails instead of installing). Either way argocd-cm gets the ignoreDifferences block the self-referencing root Application needs, unless it already carries one. repo-creds Secret a long-lived token of the cluster's service account, so Argo CD can pull from ConfigHub's OCI registry. root Application bootstrapped once with kubectl; from then on Argo pulls everything else from ConfigHub. It never deletes an Application unless --prune is given (below). k8sbot unless --no-k8sbot: a bot that listens on a Channel and force-syncs the matching Argo Application the moment a deploy happens, instead of waiting for Argo's poll, and reports each Release's live status back.

And in ConfigHub:

the cluster Space: an OCI target that represents the cluster, and k8sbot's Channel. A pure namespace — it holds no config bundle. -argo-apps the apps Space: the root "app of apps" Application Unit and every child Argo Application Unit. Its release target is the OCI target in the cluster Space, so the apps Space is the config bundle Argo pulls. argo- a service account with no organization role, the cluster's identity: the target grants its user View, Edit, ViewChildren and EditChildren; Argo CD pulls with a token of it and k8sbot runs as it with a key.

The OCI target is gated: a "no-placeholders" Trigger in the cluster Space blocks publishing a Release that still contains an unfilled "confighubplaceholder" value, for every Space that releases to this cluster. Pass --no-placeholder-gate to skip the Trigger; the target is wired either way.

By default nothing cub wires into Argo CD deletes anything: a deployment whose Application Unit is removed from the apps Space keeps running, so a bad or empty Release can never take workloads down. --prune opts the cluster into removal: the root Application prunes an Application whose Unit is gone, and "cub variant create --target" gives each deployment's Application prune and Argo's resources finalizer, so removing the Unit removes what the deployment deployed. --prune is recorded on the OCI target, so it covers deployments created later; it does not change Applications that already exist.

A cluster is wired to one ConfigHub at a time: attach refuses a cluster whose Argo CD already holds ConfigHub registry credentials, and a remote cluster against a ConfigHub on localhost, which Argo inside the cluster could never reach.

Argo CD is not exposed outside the cluster by attach. Reach its UI with "kubectl port-forward svc/argocd-server -n argocd 8080:80" against the kubeconfig attach wrote; the initial admin password is in argocd-initial-admin-secret. The exception is a kind cluster that "cub cluster create" made: its node carries the host port window create mapped, and when attach installs Argo CD or Sveltos it puts the UI on the window's first port, records the window on the cluster Space, and "cub cluster open" opens the UI there, as for "cub cluster up".

With --controller sveltos, Sveltos takes Argo CD's place: it is installed from the upstream manifest, with its dashboard, if the projectsveltos namespace has no addon-controller, and an existing Sveltos is left as found (--no-install fails instead of installing). The apps Space is -sveltos-apps, its root Unit a ClusterProfile that pulls the apps Space's own Release, and k8sbot comes from "k8sbot-sveltos-base". The dashboard is not exposed outside the cluster; reach it with "kubectl port-forward svc/dashboard -n projectsveltos 8080:80", and log in with a token from the platform-admin ServiceAccount. See "cub cluster up --help" for how the profiles, polling and --prune work.

With --controller flux, Flux takes Argo CD's place: it is installed from the upstream manifest if the flux-system namespace has no kustomize-controller, and an existing Flux is left as found (--no-install fails instead of installing). The apps Space is -flux-apps, its root Unit an OCIRepository and Kustomization, both named confighub-root, that pull and apply the apps Space's own Release, and k8sbot comes from "k8sbot-flux-base". Flux has no UI; "kubectl -n flux-system get ocirepository,kustomization" shows its state. See "cub cluster up --help" for how the Kustomizations, polling and --prune work.

A Sveltos or Flux cluster is refused, like an Argo CD one, when it already holds the registry credentials of an attachment: the confighub-gateway Secret in projectsveltos, or the confighub-oci Secret in flux-system.

Two Secrets hold ConfigHub credentials: the controller's registry credentials (above) and k8sbot's key, k8sbot-secrets in the k8sbot namespace, whose CONFIGHUB_AUTH_PRIVATE_KEY k8sbot authenticates with. Attach applies both. A cluster that takes credentials only from a secret store, through the External Secrets Operator, gets them with --secrets-dir

instead: each Secret's Kubernetes manifest, exactly what attach would apply, is written to //_.yaml and not applied. The values are in plain text, in the manifest's stringData, so the file is readable only by you; k8sbot's also holds the k8sbot Namespace, which attach applies itself. Load the values into the store, and have the store keep a Secret of that name in the cluster with the manifest's type, labels, annotations and keys. Until it is there the controller cannot pull and k8sbot cannot start; attach does not wait for it. The credentials belong to the service account attach creates, so they cannot be put in the store beforehand, and a failed attach removes the files along with the service account.

The Secrets Store CSI driver's secretObjects does not fit either flag on its own: it keeps a Secret only while a pod mounts the driver's volume, and neither k8sbot nor the controller mounts one. With it, run a pod that mounts the SecretProviderClass in each Secret's namespace.

With --existing-secrets, attach uses credentials already in the store instead. Before attaching, create the cluster's service account and its credentials:

cub serviceaccount create argo- cub serviceaccount token create argo- # the controller's pull token cub serviceaccount key add argo- --generate # k8sbot's key; unless --no-k8sbot

load them into the store, and have it keep these Secrets in the cluster:

argocd/confighub-oci-creds (Argo CD) label argocd.argoproj.io/secret-type: repo-creds; keys type: oci, url: the registry attach prints, username: token, password: the token, and with a plain-HTTP registry insecureOCIForceHttp: "true" projectsveltos/confighub-gateway (Sveltos) type addons.projectsveltos.io/cluster-profile; keys username: token, password: the token flux-system/confighub-oci (Flux) type kubernetes.io/dockerconfigjson; an auth for the registry's host:port with username token and the token as password k8sbot/k8sbot-secrets key CONFIGHUB_AUTH_PRIVATE_KEY: the private JWK the key add wrote

The service account takes no organization role; attach grants it the target. Attach skips the check for an earlier attachment's credentials, applies the k8sbot namespace (unless --no-k8sbot), waits for each Secret up to --existing-secrets-timeout (default 5m), since a store can only create one once its namespace is there and attach may be what installs the controller, and then checks it: the controller's by its shape and by authenticating with its token, k8sbot's by authenticating with its key, each as argo-. Neither the service account nor the Secrets are removed when attach fails, and "cub cluster detach" leaves the Secrets, and the k8sbot namespace, in place.

Examples: # Attach whatever your current kube context points at cub cluster attach staging

# Attach a named context from a specific kubeconfig cub cluster attach prod-eu --kubeconfig ~/.kube/eu.yaml --kube-context prod-eu

# Attach a cluster that already runs Argo CD, without k8sbot cub cluster attach shared --no-install --no-k8sbot

# Attach a cluster through Flux, using the Flux it already runs cub cluster attach staging --controller flux --no-install

# Attach an EKS cluster of the same name, granting yourself cluster-admin first cub cluster attach inference-demo --provider eks \ --aws-region us-west-2 --aws-profile cubdev --grant-access

# Attach a kind cluster you created by hand cub cluster attach lab --provider kind

cub cluster attach <name> [flags]

Options

      --aws-profile string                  --provider eks: the AWS CLI profile (defaults to AWS_PROFILE)
      --aws-region string                   --provider eks: the cluster's AWS region (defaults to the AWS CLI's: AWS_REGION or the profile's)
      --cluster string                      the cluster's name at the provider (--provider eks or kind; defaults to the cluster name)
      --controller string                   controller to wire to ConfigHub: argo (Argo CD), sveltos (Sveltos) or flux (Flux) (default argo, or the one 'cub cluster controller-install' installed)
      --controller-version string           controller release to install when absent (default: argo stable, sveltos v1.16.0, flux v2.9.2; Argo CD must be v3.1 or later, which oci:// sources need)
      --existing-secrets                    use the service account argo-<name> and the credentials Secrets a secret store keeps in the cluster, checking each, instead of creating the service account and applying new credentials
      --existing-secrets-timeout duration   --existing-secrets: how long to wait for each Secret to be in the cluster (default 5m0s)
      --grant-access                        --provider eks: if your AWS identity has no access entry on the cluster, add one with cluster-admin
  -h, --help                                help for attach
      --k8sbot-base string                  what to do with k8sbot's shared base Space when it already exists: update (install k8sbot's newest release over it, then clone it) or clone (clone it as it is); asked when stdin is a terminal, otherwise update
      --kube-context string                 --provider kubeconfig: the kube context to attach (defaults to the kubeconfig's current context)
      --kubeconfig string                   --provider kubeconfig: the kubeconfig to read the cluster from (defaults to $KUBECONFIG or ~/.kube/config)
      --no-install                          never install the controller; fail if the cluster has none
      --no-k8sbot                           skip installing k8sbot (the event-driven Argo CD sync, Sveltos redeploy, or Flux reconciliation, bot); 'cub cluster k8sbot-install' installs it later
      --no-placeholder-gate                 skip the default vet-placeholders Trigger, allowing Releases with unfilled confighubplaceholder values to be published to this cluster
      --provider string                     where the cluster's credentials come from: kubeconfig, eks or kind (default "kubeconfig")
      --prune                               let the controller delete what a removed deployment deployed: the root prunes deployments whose Units leave the apps space (Sveltos's always does), and deployments created later prune what they deployed
      --registry string                     where to pull k8sbot's installer package and image from: ghcr, gcr, or a mirror prefix holding <prefix>/packages/k8sbot and <prefix>/k8sbot (default ghcr)
      --secrets-dir string                  write the Secrets holding ConfigHub credentials (k8sbot's key, the controller's pull token) to this directory as Kubernetes Secret manifests instead of applying them, for a secret store, such as the External Secrets Operator, to put in the cluster
      --space string                        ConfigHub space slug for the cluster's target and k8sbot channel (the "target prefix"); the apps space is this slug + "-argo-apps", + "-sveltos-apps" with --controller sveltos, or + "-flux-apps" with --controller flux (defaults to <name>)

Options inherited from parent commands

      --context string   The context to use for this command
      --debug            Debug output

SEE ALSO

  • cub cluster - Manage clusters wired into ConfigHub via Argo CD, Sveltos or Flux