Installation¶
This page covers installing the CAPTF provider into a management cluster with clusterctl: what to have ready first, how to register the provider, what the install creates, how the runner image is set, the optional components, and how to confirm the install worked. It is for whoever administers the management cluster, not for cluster tenants.
Before you begin
- A management cluster and a
kubectlcontext pointing at it. On a fresh cluster,clusterctl init --infrastructure terraformalso installs Cluster API’s core, bootstrap (kubeadm) and control-plane providers (see the Quick start). On a cluster where Cluster API is already initialized, it adds only CAPTF. clusterctl, matching the version documented for the Cluster API release you run.cert-manager, with thecert-manager.io/v1API available.clusterctl initinstalls a compatiblecert-managerrelease itself when one is not already present, so a separate install step is only needed to pin a specificcert-managerversion or to install it ahead of time.- Cluster API installed at a release that implements the same contract CAPTF does. CAPTF’s own
metadata.yamllists one release series so far, contractv1beta2; CAPTF is built and tested against Cluster API v1.14.2.
Register the provider¶
CAPTF is not one of clusterctl’s built-in providers, so clusterctl needs a config file that registers it. captf.io publishes one at https://captf.io/clusterctl.yaml; pass its URL with --config, and clusterctl downloads it each time it runs. It holds a single entry, the provider terraform:
providers:
- name: terraform
type: InfrastructureProvider
url: https://github.com/captf-io/cluster-api-provider-terraform/releases/latest/infrastructure-components.yaml
The latest in url sets only the default version. clusterctl lists the repository’s releases itself, so terraform:vX.Y.Z installs any tagged release, and terraform alone installs the newest stable release for the Cluster API contract (v1beta2), never a pre-release.
Pass the config to every clusterctl command that fetches from the provider’s releases: init, upgrade plan, upgrade apply and generate cluster --infrastructure terraform. Commands that work from what is installed in the management cluster, such as delete, move and describe, do not need it.
When you have your own clusterctl config
--config replaces clusterctl’s config rather than adding to it: with the hosted file, clusterctl does not read your own providers, variables or image overrides. If you have a config of your own, copy the terraform entry above into it instead. In the default location, ~/.config/cluster-api/clusterctl.yaml, clusterctl reads it without --config. Do the same where the management cluster’s network cannot reach captf.io, with a file:// url into a local repository built from a release’s assets; see Installing from a local repository.
Pin a version
Without a version, init installs the newest release. For anything you keep, pin one: clusterctl init --config https://captf.io/clusterctl.yaml --infrastructure terraform:v0.2.0.
Install with clusterctl init¶
clusterctl init --infrastructure terraform:vX.Y.Z pins a specific released version instead of the newest one clusterctl can see.
On a fresh cluster this also installs the Cluster API core and kubeadm providers. If you plan to use the ClusterClass flavor, enable the ClusterTopology feature gate before running init — it is alpha in Cluster API and off by default:
CLUSTER_TOPOLOGY=true clusterctl init --config https://captf.io/clusterctl.yaml --infrastructure terraform
CLUSTER_TOPOLOGY=true only takes effect when this init installs the core provider. If Cluster API’s core is already installed, the variable changes nothing: enable the ClusterTopology feature gate on the core controller (capi-controller-manager) instead.
What gets installed¶
Everything below lands in one namespace, captf-system, which the install creates as a Namespace object; clusterctl init also installs cert-manager itself when it is missing, in its own namespace.
- CRDs for the eight kinds:
TerraformCluster,TerraformClusterTemplate,TerraformMachine,TerraformMachineTemplate,TerraformMachinePool,TerraformMachinePoolTemplate,TerraformClusterIdentityandTerraformPlan(TerraformClusterIdentityis cluster-scoped; the rest are namespaced). See The Kinds for what each one does, and Custom Resources for every field. - The manager, a two-replica
Deploymentnamedcaptf-controller-manager, running as a non-root user, with aServiceAccountof the same name. Leader election is on: the leader reconciles, and both replicas serve the webhooks. APodDisruptionBudget(maxUnavailable: 1) keeps one replica serving during a node drain. It serves its webhooks on:9443, its metrics on:8443, and its health and readiness probes on:9440. - The admission webhook: a
ValidatingWebhookConfigurationnamedcaptf-validating-webhook-configuration, one rule per kind, backed by thecaptf-webhook-serviceService. Its serving certificate is acert-managerCertificate(captf-serving-cert, issued by the self-signedIssuercaptf-selfsigned-issuer). cert-manager writes it to the Secretcaptf-webhook-service-cert, which the manager pod mounts read-only at/tmp/k8s-webhook-server/serving-certs; CA injection keeps the webhook configuration’s CA current. The pod cannot start until that Secret exists. - RBAC for the manager itself: the
ClusterRolecaptf-manager-roleand itsClusterRoleBinding, plus a leader-electionRoleandRoleBindingscoped tocaptf-system. The manager also creates a runnerServiceAccountandRoleBindingin each tenant namespace at first use, from the staticClusterRolecaptf-runner. See RBAC for what each role grants and for the per-namespace runner setup. - User-facing ClusterRoles:
captf-viewer-role(read every CAPTF kind, aggregated into the built-inview,editandadmin),captf-editor-role(write the six workload kinds, aggregated intoeditandadmin) andcaptf-plan-approver-role(approve plans, aggregated nowhere: bind it with aRoleBindingin the plan’s namespace). No aggregated role grants write access toTerraformClusterIdentityorTerraformPlan.
The manager pod tolerates the node-role.kubernetes.io/control-plane:NoSchedule taint, and has liveness (/healthz) and readiness (/readyz) probes on the healthz port. The replicas prefer separate nodes (a ScheduleAnyway topology spread on the hostname), so a single-node cluster still schedules both. The container has a preStop sleep of 5 seconds, which needs Kubernetes 1.30 or later, where the sleep lifecycle action is on by default. For what to tune for production, see Production Readiness.
None of this installs a TerraformClusterIdentity or any Terraform* object: those come from templates you apply afterward, covered in Identities and Credentials and Templates and ClusterClass.
The manager image and the runner image¶
clusterctl init sets the manager container’s image to the release’s image, pinned by digest: ghcr.io/captf-io/cluster-api-provider-terraform@sha256:<digest>. The same reference is also set as the CAPTF_MANAGER_IMAGE environment variable on that container: it is the default of --runner-image, the image the manager runs as the init container that injects the runner binary into every Job it creates. Point --runner-image at a different reference (for example a registry mirror the tenant namespaces’ Jobs can reach, or a build carrying a patched runner binary) when the manager’s own image is not the one you want Jobs to pull; see --runner-image for the flag and Job Environment for how the init container uses it. spec.source.image on a Terraform* object is unrelated: it names the role image the Job actually runs, never the runner.
A custom deployment, or an overlay that replaces the manager’s env, must keep POD_NAMESPACE and SERVICE_ACCOUNT_NAME, set from metadata.namespace and spec.serviceAccountName through the downward API. See Manager environment.
The manager image is signed with keyless cosign and carries provenance and SBOM attestations, and the release assets carry provenance attestations. To verify them before installing, see Supply chain.
Optional components¶
config/prometheus and config/network-policy are kustomize components: neither is part of infrastructure-components.yaml, so clusterctl init never installs them and clusterctl upgrade never touches them, and neither is a release asset — get them from a checkout of the tag you installed (see Register the provider), not from the release URL. A kustomize Component builds standalone: point a bare kustomization at one with no resources: of your own, and it emits only that component’s own objects, carrying the captf-/captf-system names config/default produces:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
components:
- <path-to-checkout>/config/prometheus
- Prometheus (
config/prometheus): a metricsService, aServiceMonitor, the alerting rules, and the RBAC Prometheus needs to scrape the manager’s authenticated metrics endpoint. See Enabling the Prometheus component for what it adds and how to wire it up, and how a later upgrade affects it. - Network policy (
config/network-policy): aNetworkPolicythat restricts the manager pod to webhook, metrics and health-probe traffic inbound, and DNS, the API server and container registries outbound. It only has an effect on a CNI that enforcesNetworkPolicy, and it covers only the manager pod, not runner Jobs;config/network-policy/job-egress-sample.yamlis a separate starting point to copy into each tenant namespace for its Job pods. See Network exposure for why the manager’s and a Job’s exposure differ.
Building both at once needs both under components: in the same kustomization. Building either on top of a from-source install of config/default (rather than the one clusterctl init already installed) also works, but is unnecessary for these two components: each one’s objects stand alone and never depend on config/default’s own resources being built alongside them.
Verifying the install¶
kubectl -n captf-system rollout status deployment/captf-controller-manager
kubectl get crds -l cluster.x-k8s.io/provider=infrastructure-terraform
kubectl get validatingwebhookconfigurations captf-validating-webhook-configuration
kubectl -n captf-system get certificate captf-serving-cert
kubectl -n captf-system get secret captf-webhook-service-cert
The rollout command returns once the manager pod is ready. The CRD list should show all eight kinds. The webhook configuration and the certificate must both exist and the certificate must report Ready=True, cert-manager was able to issue the webhook’s serving certificate: without it, webhook calls from the API server fail closed (failurePolicy: Fail on create and update) and every Terraform* create or update is rejected. Every webhook entry has timeoutSeconds: 10. The deletes of TerraformMachine and TerraformClusterIdentity are separate entries (delete.validation.<kind>.infrastructure.cluster.x-k8s.io) with failurePolicy: Ignore.
If the manager pod sits in ContainerCreating, check the last command first: the pod mounts that Secret, and it does not exist until cert-manager has issued the certificate. kubectl -n captf-system describe certificate captf-serving-cert shows why issuance is stuck.
If you installed the Prometheus component, confirm who is allowed to scrape the metrics endpoint:
The subjects list should name your Prometheus ServiceAccount (the shipped default is monitoring/prometheus-k8s).
clusterctl init itself prints the components it installed; clusterctl describe cluster (once you have created one) reports whether CAPTF’s objects are ready.
Uninstalling¶
Delete the workloads first (the Cluster objects, and with them every Terraform* object, so each destroy Job can run), then the provider with clusterctl delete. Deleting the provider first leaves objects with finalizers and nothing to remove them. The delete guards on TerraformMachine and TerraformClusterIdentity do not block when the webhook is down (they fail open), so a namespace or the provider can always be removed; if you do remove the provider with objects still present, retain or clean up their state by hand as in Stuck destroy.