Crossplane - What is it?
Have you ever heard about Crossplane and want to know more? Stay tuned and embrace the knowledge.
But first, lets start with IaC.
IaC - Infrastructure as Code
Maybe you already know what is IaC, and work with it daily, builduing terraform or cloudformation projects, or another/similar IaC software. If this is the case, you can pass to the next chapter :)
IaC is the practice of managing and provisioning infrastructure using code, in a way that can be version-controlled, tested and reused. Lets explore each one.
- Version-controlled: IaC are composed by files declaring the desired infrastructure, normally saved in a git repository. So the repo is under all the controls and features that the git controller has;
- Tested: Remember when you have to create virtual machines, and have to test all the process again to validate it? It's a painful and long running task, right? With IaC everything is faster. Once the infra is declared you must say that you want to create, or destroy. Making the tests and validation process repeatable, that leads to the next point;
- Re-used: How about a group of resources that is going to be used many times? Like in software development, where the dev create a function/procedure that does a repeatable code, the IaC can do the same. Can be named as modules, packages, compositions. Depends on the tool that you are using.
Take all these points and we can achieve the following results: Improve Efficiency, Reduce Errors, and deliver faster resources, as a consequence deliver solutions faster (Hey, Happy ITIL).
The most common tools used is terraform, ansible, chef, and more recently Crossplane.
Erg... Crossplane, one more tool? Why?
First, what is crossplane?
Crossplane (CP) is a open-source (Apache 2.0 license) kubernetes controller, developed by Upbound. As a IaC tool crossplane is responsible for creating and managing the resources in the cloud. When the word "resource" is being used you can think like a EC2 in AWS, or a Compute Machine in GCP, or any of the resources of the public provider.
In the time of the writing of this blog the version of the CP is 1.11. Looking in the github you can see that it is a very active project, with new features at each new release.
With this little (and very fast) introduction: Why?
CP has some key features that make a step forward in the kubernetes and cloud-native:
- Self-healing: CP actively check the cloud resource and validates with the declared state, the IaC code. If something is different CP automatically correct drift. Its similar to "terrraform apply", but its automatic. Like Magic.
- State: the state is the declared resource (an yaml file), that is saved in a repo git, and in the kubernetes cluster. You dont need to bother anymore with statefiles, permissions for statefiles, buckets, lockfiles. Want a additional layer to save your files? Use velero to make a backup of your kubernetes cluster.
- Declarative Configuration: No need to learn a new language, its just YAML. The Learning Curve is High, i.e. is fast to dominate the creation of resources.
- Object in kubernetes: The resources declared are kubernetes objects. Its easy to observe the resource using kubectl get.
Personally, being self-healing is the most atractive feature. If you manage a infrastructure you probably already understand me =)
Where to begin?
Lets install the Crossplane via helm, and install a provider (if you know terraform, think the crossplane provider is like a provider in the terrraform). Later lets create a VPC in AWS, and see the magic works.
Installing by helm
1. Add the official helm charthelm repo add crossplane-stable https://charts.crossplane.io/stable
2. Update the local repo cachehelm repo update
3. Install the crossplane controllerhelm upgrade -i --create-namespace --namespace crossplane-system crossplane crossplane-stable/crossplane
After this process the kubernetes spins 2 pods in the crossplane-system namespace, like this:

AWS Provider
Now we need to create a provider. It's simple like this yaml:
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-aws
spec:
package: xpkg.upbound.io/crossplane-contrib/provider-aws:v0.38
Save to a file (say provider-aws.yaml) and apply using kubectl:kubectl apply -f provider-aws.yaml
Lets check our provider in kubernetes:
Up and running. Lets make something cool now.
AWS Resources
Credentials configuration
We need first to create a credential in kubernetes that contais the data to access the cloud. You need to create a user in the AWS portal and create a programmatic access key. Lets add it to kubernetes
Create a file aws-credentials, and save this content inside it:
[default]
aws_access_key_id = <aws_access_key>
aws_secret_access_key = <aws_secret_access>
Change the values according to your values. And create a secret, with:
kubectl create secret \
generic aws-secret \
-n crossplane-system \
--from-file=creds=./aws-credentials
Based on the secret lets create a ProviderConfig for the aws provider:
cat <<EOF | kubectl apply -f -
apiVersion: aws.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: aws-secret
key: creds
EOF
Now we are ready.
Resources creation
Save the following to a file (say cp-vpc.yaml), and apply to the kubernetes:
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: VPC
metadata:
# [Managed] Resources are cluster-wide
name: vpc-training
spec:
# Delete (default) or Orphan
deletionPolicy: Delete
# The name of the providerconfig previsouly created
providerConfigRef:
name: aws-cred
# Configuration of the VPC
forProvider:
cidrBlock: 10.10.10.0/24
enableDnsHostNames: true
enableDnsSupport: true
region: us-east-1
tags:
- key: Name
value: vpc-test
kubectl apply -f cp-vpc.yaml
Check in your cloud and the VPC will be there. Go on and make a test, delete it, just for CP create it again. It's not magic, its crossplane.
Now lets create a subnet:
Save the following to a file (say vpc-subnet.yaml), and apply it:
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: Subnet
metadata:
name: subnet-vpc-test
spec:
providerConfigRef:
name: aws-cred
forProvider:
availabilityZone: us-east-1a
cidrBlock: 10.10.10.0/26
mapPublicIPOnLaunch: true
region: us-east-1
# The Name of the VPC that I belong to
vpcIdRef:
name: vpc-test
tags:
- key: Name
value: subnet-vpc-test
kubectl apply -f vpc-subnet.yaml
Where to find the definitions? https://doc.crds.dev/github.com/crossplane-contrib/provider-aws
There is a lot more in crossplane, but doesnt not fit in just one article. Further we going to talk about Composition, Composition Functions and more.
I hope this is a very good starting point for you.
See you. Happy Crossplan-ing.