Introduction to Crossplane

Crossplane your infra API

Crossplane is an open-source Kubernetes add-on that extends Kubernetes' capabilities to manage cloud infrastructure and other external resources across any cloud. It empowers organizations to provision and manage infrastructure resources like databases, storage volumes, virtual machines, and more through Kubernetes APIs, simplifying the adoption and management of cloud-native applications.

Key features and components of Crossplane include:

  1. Providers
  2. Composite Resources
  3. Composite Resource Definitions

Crossplane streamlines the management of infrastructure resources in a Kubernetes environment, fostering a consistent and declarative approach for provisioning and maintaining infrastructure alongside application workloads. This integration of infrastructure and application management facilitates more efficient, agile, and cost-effective IT operations.

Providers

Crossplane supports various cloud providers and infrastructure services known as "providers." These providers offer controllers and APIs to interact with specific cloud platforms, enabling users to provision and manage resources across multiple clouds and on-premises environments.

For instance the s3 AWS provider can be used to provision a bucket in Amazon.

1apiVersion: s3.aws.upbound.io/v1beta1
2kind: Bucket
3metadata:
4  annotations:
5  name: bucket-name
6spec:
7  forProvider:
8    region: us-west-1

Creating a bucket involves applying the resource Bucket. An operator familiar with Kubernetes can easily create as many buckets as needed using the kubectl apply command. Similarly, resources can be updated and deleted using the corresponding apply and delete kubectl commands.

The resources created by the Crossplane provider are referred to as Managed Resources.

Managed Resources

Composite Resources

Crossplane introduces the concept of composite resources, allowing users to define and compose complex infrastructure resources from simpler building blocks.

Since developers often require multiple Managed resources simultaneously, Crossplane introduces the concept of Composite Resources, which allows multiple managed resources to be configured as a group. The creator of the composite resource can provide default options to pass to the provider and define which settings developers are allowed to override.

 1apiVersion: apiextensions.crossplane.io/v1
 2kind: Composition
 3metadata:
 4  name: bucket-composition
 5spec:
 6  compositeTypeRef:
 7    apiVersion: ellin.net/v1alpha1
 8    kind: XBucketBrigade
 9  resources:
10    - name: StorageBucketA
11      base:
12        apiVersion: s3.aws.upbound.io/v1beta1
13        kind: Bucket
14        spec:
15          forProvider:
16            region: us-east-1
17          providerConfigRef:
18            name: aws-provider-266463974589
19     - name: StorageBucketB
20      base:
21        apiVersion: s3.aws.upbound.io/v1beta1
22        kind: Bucket
23        spec:
24          forProvider:
25            region: us-east-1
26          providerConfigRef:
27            name: aws-provider-266463974589
28        ...

In the example above, the composite resource provisions two buckets, StorageBucketA and StorageBucketB.

You may notice that the above resource does not provide the metadata.name field for each bucket. This is because the operator who created this composition has chosen to allow the developer to choose those names. To populate the Bucket object correctly at creation time, a series of patches will be needed.

1      patches:
2        - fromFieldPath: "spec.bucketAName"
3          toFieldPath: "metadata.name"
4          policy:
5            fromFieldPath: Required
1      patches:
2        - fromFieldPath: "spec.bucketBName"
3          toFieldPath: "metadata.name"
4          policy:
5            fromFieldPath: Required

The instance of the object used to invoke the creation of the composition is as follows:

1apiVersion: ellin.net/v1alpha1
2kind: XBucketBrigade
3metadata:
4  name: brigade
5spec:
6  bucketAName: foo
7  bucketBName: bar

The inputs from XBucketBrigade are used to create the managed resources in the composition.

Composite Resource Definitions

To formalize a given composite resource, a Kubernetes CRD is required to define the schema of the resource.

Crossplane defines Composite Resource Definitions (XRDs) for scaffolding a CRD, allowing consumers of the composition to declare and manage these resources in a Kubernetes-native way.

 1apiVersion: apiextensions.crossplane.io/v1
 2kind: CompositeResourceDefinition
 3metadata: 
 4  name: xbucketbrigades.ellin.net
 5spec:
 6  group: ellin.net
 7  names:
 8    kind: XBucketBrigade
 9    plural: xbucketbrigades
10  versions:
11  - name: v1alpha1
12    served: true
13    referenceable: true
14    schema:
15      openAPIV3Schema:
16        type: object
17        properties:
18          spec:
19            type: object
20            properties:
21              bucketAName:
22                type: string
23              bucketBName:
24                type: string

Publishing Connection Details.

Next up we will discuss the methods in which crossplane can publish connection information such as usernames and passwords to the developers who provisioned them. We will also see how to pass these crewdentials easily using the Kubernetes Service binding specification.

Posts in this Series

comments powered by Disqus