liveBook · Manning

Composite resource definition

As explained in Platform Engineering on Kubernetes

A Crossplane Composite Resource Definition is an API definition that exposes a composite resource type, its schema, and the interface that compositions implement.

A Crossplane Composite Resource Definition (XRD) defines a Kubernetes resource type that application teams can request. It is the interface; a Composition implements that interface by specifying the resources to create and wire together. Platform teams can therefore expose a simple database request without requiring application teams to configure its networking, security, or cloud-provider resources. section 5.2.2 section 5.3

To expose a resource for the Conference application:

  • Install Crossplane in a Kubernetes cluster and configure the providers that will create the underlying resources. Cloud-provider implementations also need the relevant APIs enabled and sufficient account permissions. section 5.2.3
  • Define an XRD for each interface teams need. The example defines Database and MessageBroker; the Database XRD declares the resource name and a schema with size and mockData parameters. section 5.3
  • Create one or more Compositions referencing the defined type. Each Composition supplies resource manifests; labels let a request select an implementation, such as a local development database or a Google Cloud SQL database. section 5.3

Request a database without specifying its deployment

The Database XRD uses apiVersion apiextensions.crossplane.io/v1 and kind CompositeResourceDefinition to expose salaboy.com/v1alpha1 Database. A team requests kind Database with size: small and mockData: false, then selects a Composition through spec.compositionSelector.matchLabels. Changing the labels from provider: local, kind: sql to provider: gcp, kind: sql changes the selected implementation while retaining the Database interface. section 5.3

Listing 5.6 Database Composite Resource Definition
apiVersion: apiextensions.crossplane.io/v1
kind: CompositeResourceDefinition
metadata:
  name: databases.salaboy.com              #1
spec:
  group: salaboy.com                       #2
  names:
    kind: Database                         #3
    plural: databases
    shortNames:
      - "db"
      - "dbs"
  versions:
  - additionalPrinterColumns:
    - jsonPath: .spec.parameters.size
      name: SIZE
      type: string
    - jsonPath: .spec.parameters.mockData
      name: MOCKDATA
      type: boolean  
    - jsonPath: .spec.compositionSelector.matchLabels.kind
      name: KIND
      type: string
    name: v1alpha1
    served: true
    referenceable: true
    schema: 
      openAPIV3Schema:
        type: object
        properties:
          spec:
            type: object
            properties:
              parameters:                  #4
                type: object
                properties:
                  size:
                    type: string 
                  mockData: 
                    type: boolean
                required:   
                - size
            required:                      #5
            - parameters

Inspect the Database XRD manifest for the API group, kind, version, schema, and printer columns exposed to teams. section 5.3

The same pattern can expose development environments: an environment request selects a Composition that provisions a Kubernetes Namespace or a cluster. XRDs reduce the choices visible to consumers, but operating Crossplane still requires Kubernetes expertise and provider configuration. section 6.3 section 5.4

How Platform Engineering on Kubernetes covers it

How deep it goes
Works through a Database XRD manifest, request parameters, matching labels, and compositions; does not detail Crossplane controller internals.
Examples
Uses Conference application Database and MessageBroker interfaces, plus local Redis, local PostgreSQL, and Google Cloud SQL database requests.
What it assumes
Assumes Kubernetes cluster operation and provider permissions; introduces how XRDs and Compositions divide the interface from provisioning.
What you can do after
Build it from scratch: define an XRD, implement it with Compositions, and request infrastructure by selecting an implementation.
How it connects
Connects Crossplane Compositions, composite resources, Kubernetes APIs, provider configuration, and label selectors.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Platform Engineering on Kubernetes. The section links point to the parts of the book it draws on.