Week 18 - IaC From Within K8s: Crossplane and Terraform¶
18.1 Conceptual Core¶
- Crossplane flips IaC inside out: cloud resources are Kubernetes resources (CRDs), reconciled by Crossplane's providers (
provider-aws,provider-gcp,provider-azure,provider-helm,provider-kubernetes). You manage cloud infra withkubectl apply. - Compositions let you bundle low-level primitives into domain-specific abstractions: define a
XPostgresInstancethat, when applied, creates a VPC subnet, an RDS instance, IAM bindings, and aServiceMonitor. Platform teams ship Compositions; app teams consume them. - Terraform alternative: run Terraform Cloud / Atlantis externally; treat the cluster as a deploy target only. Simpler in some shops; doesn't unify the control plane.
18.2 Mechanical Detail¶
- Provider = a controller image that knows how to talk to one external system. Install via
ProviderCRD. ProviderConfig= credentials + connection details for the provider.- Managed Resource (MR) = the K8s representation of a cloud resource (
Bucket,Database,IAMRole). - Composition = a YAML transform: "given this
XPostgresInstanceclaim, produce these MRs with these field mappings." - Composite Resource Definition (XRD) = the schema for the abstract type; the platform-team-facing equivalent of CRD.
18.3 Lab-"Self-Service Database"¶
- Install Crossplane. Install
provider-aws(orprovider-gcp). - Configure provider credentials.
- Define an XRD
XDatabasewith parameters:size,engine,version,region. - Define a Composition that materializes an RDS instance + a Secret with credentials.
- As an "app team" persona, create a
Databaseclaim. Watch it become a real RDS instance. Delete; watch it be torn down.
18.4 Hardening Drill¶
- Restrict Composition
selectorsandcompositionRefso app teams cannot select unintended Compositions. Use OPA/Gatekeeper to enforce naming, region, size limits.
18.5 Operations Slice¶
- Compositions are platform contracts. Version them. Provide migration paths. Treat as you would a public API: SLAs, deprecation windows, changelogs.