Skip to main content

Overview

Composition lets you build custom APIs using function pipelines that create multiple external resources as a single object. Instead of manually creating Deployments, Services, ConfigMaps, and other resources individually, you can use a custom API to create all the necessary resources.

How compositions work

The composition workflow consists of three components:

  • Composite Resource Definitions (XRDs) - define the API schema for the custom API you need to create your resources.
  • Compositions - the pipeline of logic to declare how to create those resources
  • Composite Resources (XRs) - the resources created when users request them from your custom API.

These components work together to create your resources as a single Kubernetes object for the control plane to manage.

Operational workflow

  1. Platform team defines the API

The XRD is the schema for your custom API. If your custom API interacts with your cloud provider to create an Application deployment, your XRD can define:

  • The API name (kind:App)
  • Necessary fields and what fields can accept user input
  • Validation and default values

Once the platform team creates the XRD, they apply it to their Crossplane control plane.

  1. Platform team implements the API

The Composition defines what happens when someone uses your custom API. The functions (written in a standard programming language) in the composition:

  • Extract user input from the Composite Resource (XR)
  • Create the actual resources
  • Configure the relationships between resources

Once the platform team creates the Composition, they apply it to their Crossplane control plane.

  1. User applies the API

The Composite Resource (XR) is the request for the Composition to create the defined resources and any user input that may be required

  1. Control plane creates the resources

Crossplane constantly watches for new requests and when the user applies the XR, Crossplane takes action:

  • Crossplane finds the related Composition that matches the XR
  • Executes the functions in the Composition pipeline
  • Creates the generated resources

Example

Let's work from the XR to the XRD to understand what's happening.

The XR below is an example of what a user would need to create an App. The fields available to edit are fields that the platform team determines. In this case, the user can choose the namespace of the App, the name, and the image.

Namespacing resources is helpful to segment your infrastructure. The user can deploy to the default namespace and chose an nginx image to deploy.

apiVersion: example.crossplane.io/v1
kind: App
metadata:
namespace: default
name: my-app
spec:
image: nginx

Next steps

The next pages in this section go into detail about each of these components.