Automating Infrastructure with Crossplane
Crossplane Architecture
Four key components of Crossplane:
Managed resources
Providers
Composite resources
The Crossplane core
Managed Resources (MR)
MR connects a CRD and respective custom controller to represent a single external infrastructure resource
MRs are in 1-to-1 mapping with infrastructure resources
Example, CloudSQLInstance is an MR representing
Google Cloud SQL
img.png
Crossplane Resource Model (XRM)
Is an open standard used when developing an MR
XRM is an opinionated extension of the
Kubernetes Resource Model (KRM)The best practise is to compose a higher-level API above an MR to consume
MR example
Late Initialization: Reconciliation control loop of Crossplane controllers will fill default values assigned by the infrastructure API for the features not provided in the configuration YAML.
Providers
Providers are a group of related MRs packaged together as bundle
Each cloud vendor, other infrastructure services or software tools such as Helm have a provider package
Format of these packages is nothing, but a container image
Installing of a provider can be done either with a configuration YAMl or using a Helm package
If requires a
ProviderConfigconfiguration
ProviderConfig
Helps in setting up the infrastructure vendor credentials

Provider View
Composite Resources
Composing is a way to build our custom infrastructure APIs above one or more MR APIs
These APIs are called
Composite Resources (XRs)CompositionandComposite Resource Definition(XRD)are the configurations that we use to compose a higher-levelXR API.Composition is the configuration that provides a mapping between the new CRD schema and the existing MRs
One the new
XRresource is available, we can start provisioning the infrastructure recipes using aResource Claim objectThe
ClaimAPI is something that gets created when we add a new XR API, provided we have asked for it in theXRDconfigurationThe Claim and XR APIs are almost the same with minor differences

A composite resource
The composing layer is for platform teams to build such abstraction

Product and platform team interaction
Crossplane core

All the pieces of Crossplane
CRDstands forCustom Resource Definition, a way to extend the Kubernetes API to support new resource types.CRsare the resources defined with the CRD.CRstands for Custom Resource.XRMstands forCrossplane Resource Model, an extension of theKubernetes Resource Model. It is a set of rules set by Crossplane on how to build an XR or MR.MRsare nothing butManaged Resources, a combination of a CRD and custom controllers in a one-to-one mapping with external infrastructure resources.XRDstands forComposite Resource Definition, a definition for building a custom infrastructure API above Crossplane.XRstands forComposite Resource, which represents a custom infrastructure API built with Crossplane.
Installing Crossplane
Installing and configuring providers
Prerequisites:
GCP account
Installing gcloud cli - https://cloud.google.com/sdk/docs/install
Creating project in GCP by name
crossplanegcloud initEnable the required services
Next, will have to create service account and extract the credentials required to set up the GCP Crossplane provider
Get the project ID:
Create Service Account and enable the required roles on the SA
Extract service account file
Create Kubernetes Secret using the Service Account
Installing a Provider
Let's install the GCP Crossplane provider.
We have 2 options
Will install GCP Provider with container image version
alpha
Configuring Provider
Next step is to set up provider configuration for authentication using the
ProviderConfigCrossplane API.Credentials can be different for each provider, depending on the construct for authentication by infrastructure vendor.
GCP, uses
Service Account, in Azure itsService Principle,IAMin AWS etc.
Multiple Provider configuration
Multiple
ProviderConfigcan be configured against a provider.Which is like having multiple credentials or cloud accounts to access the cloud platform and choosing the appropriate credentials based on the given context
When provisioning MR or XR, we specify
providerConfigRefto determine whichProviderConfigto useIf
providerConfigRefis not provided in Mr or XR, Crossplane refers to theProviderConfignameddefault

Multiple Provider Configuration

Cleanup
Tip:
Last updated