TExcelTAD
Home › Platform Engineering: Internal Developer Platforms › Crossplane: Infrastructure through Kubernetes

Crossplane: Infrastructure through Kubernetes

Crossplane (a CNCF graduated project) turns a Kubernetes cluster into a control plane for infrastructure. Cloud resources become Kubernetes objects: you kubectl apply an RDS instance, and a controller creates it in AWS and keeps it matching the spec forever, correcting drift the way Argo CD corrects a Deployment. On top of that, platform teams define their own APIs (kind: Database with size: s) and compose them out of lower-level resources. That second part is why platform teams care.

The building blocks

Concept What it is
Provider a package that installs CRDs and a controller for one API: AWS (one provider per service family, e.g. provider-aws-rds), GCP, Azure, Kubernetes, Helm, and many more
Managed resource (MR) one external resource as a Kubernetes object, e.g. an RDS Instance. In Crossplane v2 MRs are namespaced, with API groups containing .m. (rds.aws.m.upbound.io)
ProviderConfig credentials and settings a provider uses (an IRSA/Workload Identity role, a secret); namespaced ProviderConfig or cluster-wide ClusterProviderConfig
CompositeResourceDefinition (XRD) defines your own API: a new kind with a schema (Database: size, tier)
Composite resource (XR) an instance of your API, e.g. the shortlinks Database in namespace team-growth. In v2 XRs are namespaced by default
Composition how an XR is implemented: a pipeline of composition functions that produce the composed resources
Function a package (container) that runs a step of a composition: patch-and-transform, Go templates, KCL, Python, or your own
text
team applies:   Database "shortlinks" (namespace team-growth, size: s)          <- your API (XRD)
                     |  Composition "database-cnpg": pipeline of functions
                     v
Crossplane creates: CloudNativePG Cluster, NetworkPolicy, ...     (local track)
               or:  RDS Instance, SubnetGroup, SecurityGroup ...  (cloud track, managed resources)
                     |  providers / operators
                     v
               the real database

What changed in Crossplane v2

Crossplane v2 (2025) reshaped the model; older tutorials show the v1 style, so it helps to recognise both:

v1 v2
XRs are cluster-scoped; teams create namespaced claims that bind to them XRs are namespaced and created directly by teams; no claims for new XRDs (the LegacyCluster scope keeps v1 behaviour)
MRs are cluster-scoped MRs are namespaced, with .m. API groups; cluster-scoped MRs are legacy
compositions compose MRs compositions can compose any Kubernetes resource in the XR's namespace (Deployments, CloudNativePG Clusters…), given RBAC for it
native patch-and-transform in the Composition removed; use the function-patch-and-transform function in a pipeline
XR fields such as compositionRef at the top of spec Crossplane's own fields move under spec.crossplane

Crossplane v2 also added Operations (alpha) for one-off and scheduled function pipelines, and managed resource definitions that let you activate only the provider resources you use. Check docs.crossplane.io for the version you install; crossplane beta upgrade check scans a v1 control plane before upgrading.

A managed resource

The lowest level: one RDS instance as a Kubernetes object. This is a sample, as it needs a cluster with Crossplane and the AWS RDS provider; check the provider's API reference for the exact fields of the version you install:

yaml
apiVersion: rds.aws.m.upbound.io/v1beta1
kind: Instance
metadata:
  name: shortlinks
  namespace: team-growth
spec:
  forProvider:
    region: eu-west-1
    engine: postgres
    engineVersion: "17"
    instanceClass: db.t4g.small
    allocatedStorage: 20
    storageEncrypted: true
    username: shortlinks
    autoGeneratePassword: true
    passwordSecretRef: {name: shortlinks-db-password, key: password}
    skipFinalSnapshot: false
  providerConfigRef:
    kind: ClusterProviderConfig
    name: aws
  writeConnectionSecretToRef:
    name: shortlinks-db-conn

And the lifecycle a team (or Argo CD) would see:

bash
$ kubectl apply -f instance.yaml
instance.rds.aws.m.upbound.io/shortlinks created
$ kubectl get instance.rds.aws.m.upbound.io -n team-growth      # sample output
NAME         SYNCED   READY   EXTERNAL-NAME   AGE
shortlinks   True     False   shortlinks      2m
$ kubectl get instance.rds.aws.m.upbound.io -n team-growth      # a few minutes later
NAME         SYNCED   READY   EXTERNAL-NAME   AGE
shortlinks   True     True    shortlinks      9m

SYNCED means the last reconcile with the AWS API succeeded; READY means the resource is available. Change allocatedStorage in Git, and the provider updates the instance; change it in the AWS console, and the provider changes it back.

Teams should rarely write MRs like this: 20 fields, half of them company standards. That's what the next lesson's XRD and Composition hide.

The reconcile loop, modelled

Every Crossplane controller runs the same loop as a GitOps agent (GitOps: the reconcile loop): observe the external resource, compare it with the spec, create/update/delete, report conditions. A compact model of an MR controller, including drift correction and the managementPolicies field that limits what Crossplane may do:

python · try it yourself
cloud = {}   # the "AWS API": external name -> attributes

def reconcile(mr):
    spec, name = mr["forProvider"], mr["name"]
    policies = mr.get("managementPolicies", ["*"])
    allowed = lambda p: "*" in policies or p in policies
    actual = cloud.get(name)
    if actual is None:
        if not allowed("Create"):
            return "SYNCED=False (not found, Create not allowed)"
        cloud[name] = dict(spec)
        return "created"
    drift = {k: (actual.get(k), v) for k, v in spec.items() if actual.get(k) != v}
    if not drift:
        return "up to date, READY=True"
    if not allowed("Update"):
        return f"drift {drift} observed, Update not allowed"
    actual.update(spec)
    return f"updated {drift}"

mr = {"name": "shortlinks", "forProvider": {"instanceClass": "db.t4g.small", "allocatedStorage": 20}}
print("1:", reconcile(mr))
print("2:", reconcile(mr))
cloud["shortlinks"]["allocatedStorage"] = 50          # someone resizes it in the console
print("3:", reconcile(mr))
mr["forProvider"]["instanceClass"] = "db.t4g.medium"  # a team changes the spec in Git
print("4:", reconcile(mr))
observe_only = {"name": "legacy-db", "forProvider": {"instanceClass": "db.r6g.large"},
                "managementPolicies": ["Observe"]}
print("5:", reconcile(observe_only))
cloud["legacy-db"] = {"instanceClass": "db.r6g.xlarge"}
print("6:", reconcile(observe_only))
1: created
2: up to date, READY=True
3: updated {'allocatedStorage': (50, 20)}
4: updated {'instanceClass': ('db.t4g.small', 'db.t4g.medium')}
5: SYNCED=False (not found, Create not allowed)
6: drift {'instanceClass': ('db.r6g.xlarge', 'db.r6g.large')} observed, Update not allowed

Step 3 is the property that makes Crossplane different from a terraform apply in CI: console changes are reverted within the poll interval, not at the next pipeline run. Steps 5 and 6 show managementPolicies: ["Observe"], used to import existing resources and watch them without letting Crossplane change anything, a safe first step when adopting Crossplane for infrastructure Terraform created.

Test yourself

In Crossplane v2, how does a team request an instance of the platform's Database API?

  1. Through a cluster-scoped claim
  2. By creating a namespaced composite resource (XR) of kind Database in its namespace
  3. By editing the Composition
  4. By writing a managed resource for every part

What does READY=False, SYNCED=True on a managed resource usually mean?

  1. The spec is invalid
  2. The last API call succeeded, but the external resource isn't available yet (still creating)
  3. The provider is missing
  4. Drift was found

What is managementPolicies: ["Observe"] good for?

  1. Faster creation
  2. Watching existing resources (e.g. created by Terraform) without letting Crossplane change or delete them
  3. Deleting resources
  4. Encrypting secrets