Crossplane: The Next Big Thing for Infrastructure as Code | by Vaibhav Rajput | Jun, 2022

Getting began with Crossplane

Photograph by Philip Myrtorp on Unsplash

Infrastructure as Code has been on the market for fairly a while now.

It got here to unravel a problem and saved evolving with new options.

We’ve seen days of CFEngine. Went by means of Chef, Puppet, Ansible and reside within the Terraform and Pulumi period.

Crossplane is the following stage of this evolution. It’s bringing one thing new to the desk: the flexibility to detect and proper drifts.

Earlier than we transfer ahead to see the true talents of crossplane, let’s see how one can get began with it.

Step 1: Setup an preliminary cluster

Crossplane runs on a Kubernetes cluster, so for step one, you must create a cluster. This may be as small as minikube or variety since it would simply be offering the interface for Crossplane.

For this step, set up kubectl, helm and variety in your system. And run:

variety create cluster — picture kindest/node:v1.23.0 — wait 5m

Step 2: Set up crossplane

As all Kubernetes hosted functions must be, begin by making a separate namespace:

kubectl create namespace crossplane-system

Subsequent, set up the crossplane chart

helm repo add crossplane-stable
helm repo replace
helm set up crossplane --namespace crossplane-system crossplane-stable/crossplane

Use helm listing or kubectl get command within the crossplane-system namespace to test if the set up is profitable.

Step 3: Set up the crossplane cli

Crossplane is kind of a plugin/bundle for the kubectl CLI. Merely set up it utilizing:

curl -sL | sh

Now you need to use it like kubectl crossplane ... to put in any configuration bundle.

Step 4: Set up the configuration bundle to your desired supplier

On this instance, we’ll set up the AWS config bundle, utilizing the command:

kubectl crossplane set up configuration

This configuration makes use of the default VPC. In case you want to create a brand new VPC for the cluster, use .

Crossplane is cloud-agnostic, so you need to use or for GCP and Azure respectively.

Additional steps can be slightly totally different when you go for Azure or GCP, however you discover them here.

Step 5: Configure credentials

We’ve the crossplane prepared on our native system, now we simply have to go the credentials for our supplier of alternative in order that crossplane can speak to it.

For AWS, this may be achieved like:

AWS_PROFILE=default && echo -e "[default]naws_access_key_id = $(aws configure get aws_access_key_id --profile $AWS_PROFILE)naws_secret_access_key = $(aws configure get aws_secret_access_key --profile $AWS_PROFILE)" > creds.conf

Notice that this is identical form of configuration that you just get whereas performing AWS CLI login.

Subsequent, we’ll create a secret from this file like:

kubectl create secret generic aws-creds -n crossplane-system --from-file=creds=./creds.conf

And go it in our ProviderConfig

Upon getting the provisioners in place, simply apply this manifest:

and test its standing utilizing the command::

kubectl get postgresqlinstance my-db

Et voila! You could have a Postgres Occasion prepared, similar to that!

There are primarily two methods to create sources from this level, utilizing customized sources (CRs) or composite sources (XRs).

The customized useful resource methodology lets you create sources from the useful resource definitions offered contained in the AWS configuration bundle. That is the method that we simply noticed. You’ll be able to see the definition and syntax for them here.

Composite Assets however are designed to allow you to construct your personal platform with your personal opinionated ideas and APIs without having to jot down a Kubernetes controller from scratch.

As a substitute, you outline the schema of your XR and educate Crossplane which Managed Assets it ought to compose (i.e. create) when somebody creates the XR you outlined. You’ll be able to learn extra on it here.

AWS offers the blueprints for these XRs proper here. Let’s attempt an instance from the identical repo. Say you need to create your personal VPC, you need to use first apply the Composition by making use of the contents proven here by operating

kubectl apply -f compositions/aws-provider/vpc

After which making use of the XR:

That’s all good, we created a VPC utilizing infrastructure as code (IaC), similar to every other IaC device. What’s so particular about crossplane? Additionally, why does it want a kubernetes cluster to run within the first place, why not only a CLI like Pulumi or Terraform (at the very least the open-source variations)?

That’s as a result of crossplane isn’t simply creating the infrastructure, it would additionally keep it that method.

Let’s see the way it does that by creating one other useful resource. This time, an EKS cluster

Use the identical crossplane-aws-blueprints repository and run these instructions (you’ll need to replace just a few particulars like subnet-ids)

kubectl apply -f compositions/aws-provider/ekskubectl apply -f examples/aws-provider/composite-resources/eks/eks-claim.yaml

The configuration we’re deploying right here goes one thing like this

Right here the managed node group is about to have minimal of two nodes. Try to updating it to three from the AWS Console immediately.

You’ll see that it creates a 3rd node however quickly sufficient the configuration goes again to 2 and the third node will get terminated.

Crossplane wouldn’t enable any handbook modifications on the sources. If any change is made, it would deliver it again to authentic/desired configuration.

What if I mentioned that you would be able to set up another device on the cluster managing crossplane which is able to make your life rather more simpler?

Crossplane goes hand in hand with one other device which I talked about in certainly one of my earlier blogs

Mixing Crossplane (which retains your infrastructure updated with code) with a GitOps enabler like ArgoCD (which tracks your Git repo) would imply that any change you decide to your repository would mirror in your infrastructure.

Enjoyable Truth
There’s a crossplane supplier for putting in argocd as properly. Test it out here.

There are extra instruments that you would be able to plug into this structure. Take KubeVela for instance.

To summarize, KubeVela allows you to declare your deployment plan as workflow, run it routinely with any CI/CD or GitOps system, and prolong or re-program the workflow steps with CUE.

Although that is fairly an understatement for KubeVela’s functionality, however it must be begin.

As an ops member, you’ll be able to outline the provisioners for infrastructure utilizing Crossplane and setup the CI/CD course of utilizing KubeVela.

Lastly, you create a Git repository and an ArgoCD software that tracks it.

Now your dev members are enabled with the flexibility to provision infrastructure and deploy their functions on it, simply be doing a git push with virtually all of the elements abstracted.

They don’t have to know the way the IaC or Kubernetes works right here, they simply want to grasp the syntax of 1 single YAML file.

The explanation I added ArgoCD and KubeVela on this weblog is to easily enable you to perceive that crossplane doesn’t simply deliver drift detection and auto-sync to the desk.

In case you architect it properly and gel it up with different instruments out there on this panorama, you’ll perceive the true worth of Crossplane.

Crossplane is bringing a brand new evolution in IaC.

Potential to not simply create, however holding on to the infrastructure configuration was solely achieved by means of customized codes and in-house frameworks thus far.

Now, it’s out there for everybody and I hope will quickly change into the market normal that different IaC comply with too.

More Posts