An introductory example to Crossplane and Compositions using provider-nop. This enables provisioning of several different fake resource types for testing and educational purposes.
This repository contains a reference configuration for Crossplane. This configuration uses provider-nop, a Crossplane provider that simulates the creation of external resources.
The configuration offers an API for setting up a mock database resource. This configuration also demonstrates the power of Crossplane to build abstractions called compositions
, which assemble multiple basic resources into a more complex resource.
Learn more about Composite Resources in the Crossplane Docs.
graph LR;
MyApp(My App)---MyDatabase(XRC: database1);
MyDatabase---XRD1(XRD: XMockDatabase);
subgraph Configuration;
XRD1---Composition(XMockDatabase composition);
end
subgraph Provider
Composition---MockDatabse.MRs(MRs: NopResource);
end
style MyApp color:#000,fill:#e6e6e6,stroke:#000,stroke-width:2px
style MyDatabase color:#000,fill:#D68A82,stroke:#000,stroke-width:2px
style Configuration fill:#f1d16d,opacity:0.3
style Provider fill:#81CABB,opacity:0.3
style XRD1 color:#000,fill:#f1d16d,stroke:#000,stroke-width:2px,stroke-dasharray: 5 5
style Composition color:#000,fill:#f1d16d,stroke:#000,stroke-width:2px
style MockDatabse.MRs color:#000,fill:#81CABB,stroke:#000,stroke-width:2px
Before you can install the Configuration, you should install the crossplane
CLI. This is a utility that makes following this quickstart guide easier. Everything described here can also be done in a declarative approach - which we highly recommend for any production type use-case.
To install crossplane
run this install script:
curl -sL "https://raw.githubusercontent.com/crossplane/crossplane/main/install.sh" | sh
See crossplane CLI docs for additional information.
You need a running Crossplane control plane to install the Configuration into. Ensure that your kubectl context points to the correct Kubernetes cluster or create a new kind cluster:
kind create cluster
Enable the Crossplane Helm Chart repository:
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
Install the Crossplane components using helm install:
helm install crossplane \
crossplane-stable/crossplane \
--namespace crossplane-system \
--create-namespace
Now you can install this configuration. It's packaged as a Crossplane configuration package so there is a single command to install it:
crossplane xpkg install configuration xpkg.crossplane.io/crossplane-contrib/configuration-quickstart:v0.1.0
Validate the install by inspecting the provider and configuration packages:
kubectl get providers,providerrevision
kubectl get configurations,configurationrevisions
🎉 Congratulations. You have just installed your first Crossplane-powered platform.
You can now use the control plane to request resources which will simulate getting provisioned in an external cloud service. You do this by creating "claims" against the APIs available on your control plane. Following the example below, create the claims directly:
Create a mock database:
kubectl apply -f examples/XMockDatabase/example.yaml
You can verify the status by inspecting the claims, composites and managed resources:
kubectl get claim,composite,managed
Additionally, you can render out the tree of resources, starting from the claim:
crossplane beta trace mockdatabase.quickstart.crossplane.io/database1
NAME SYNCED READY STATUS
MockDatabase/database1 (default) True True Available
└─ XMockDatabase/database1-v9l9t True True Available
└─ NopResource/database1-v9l9t True True
To delete the provisioned resources, delete the claims:
kubectl delete -f examples/XMockDatabase/example.yaml
To uninstall the package and all dependencies:
kubectl delete configurations.pkg.crossplane.io configuration-quickstart
For any questions, thoughts and comments get involved in the Crossplane community or drop by slack.crossplane.io and introduce yourself.