Deploy AWS Resources using Crossplane on Kubernetes
Deploy AWS resources using Crossplane. Step-by-step guide to configure the AWS provider and create a S3 bucket.
Deploy a Kubernetes Application that deploys its AWS resources using Crossplane manifests
This tutorial assumes you already followed the steps in part 1: Deploy AWS Resources using Crossplane on Kubernetes.
Also, this is the Github Repository we'll be using: https://github.com/MeteorOps/crossplane-aws-provider-bootstrap
In this article we'll cover a use-case that can benefit from Crossplane: full environment deployment.
This is a step-by-step guide with an example and a Git repository, so by the end of it you should be able to deploy a sample env.
You can technically walkthrough the entire thing by "copy-paste" the hell of it and everything should work.
But, diving into the explanations with an extra 5-10 minutes will leave you with longer-term value.
Hope you enjoy!
By the end of it you'll understand:
This article guides you through a simple application deployment, and not a full set of apps.
It also doesn't go into using Crossplane in conjunction with Helm, but does cover important principles regarding it.
But you already know that.
The tradition was this process: Build infrastructure, Deploy application on top.
How did Crossplane break this tradition?
The application deployment can now provision infrastructure required by the application.
By creating a namespace with all of the apps and the AWS resources required with Crossplane, the use-case of creating a full environment per Pull-Request as part of the CI becomes much easier.
That's a nice benefit of such setup for companies utilizing the feature-branch or Gitflow approaches.
To provision and deploy a full environment in the past, the process would generally look something like this:
To provision and deploy a full environment with Crossplane the process is similar (we still need a Kubernetes Cluster to start with for the initial environment):
When using Crossplane alongside Helm, the question arises:
Should Helm apply the Crossplane code? Or, should Crossplane apply the Helm Charts?
I'm glad you asked it - the answer is both, depends when.
Deploy the simple application alongside a S3 bucket using a Crossplane Composite Application.
Make sure you follow the steps in the 1st article (takes 3-minutes to just copy-paste the code snippets into your terminal and run the entire thing).
Run the following oneliner to create the Secret containing the AWS credentials in the right format as required by the Application (the application will simply run aws s3 ls
to show the bucket):
Make sure it was created as expected by fetching the secret:
Make sure the provider was created and is ready before proceeding to the next steps:
You should see something like this:
Deploy the Crossplane Kubernetes Provider Configuration using the k8s-provider-conf.yaml
file:
This is done separately as it needs to happen after the Provider resources were created.
This is where we tell the Crossplane Kubernetes Provider in which Kubernetes cluster it should operate when it's creating resources.
Here we do 3 things with 3 files:
composite-app-xrd
file:composite-app-composition
file:composite-app-example
file:composite-app-xrd
file
This defines a composite resource for a Kubernetes application, with bucketName
and bucketRegion
fields in the spec. Users can claim this resource as K8sApplication.
The K8sApplication CompositeResource (XRD) accepts the bucketName
& bucketRegion
fields and uses them to create a S3 Bucket, and to create a K8s Deployment of a mock "service" that simply runs aws s3 ls
to see the bucket.
Defines a Composition of resources that can be created by a CompositeResource.
This is where we define the Composition that creates a combo of a Kubernetes Deployment with the mock "service" that runs aws s3 ls
as well as the S3 bucket - The CompositeResource simply calls this resource.
Deploys the actual K8sApplication CompositeResource, and passes the details of the region in which the bucket should be created, and the name of the bucket (both are also passed to the Kubernetes Deployment as environment variables that helps it access the same bucket).
As mentioned above, the CompositeResource calls the Composition which creates the resources using the Crossplane providers.
Deploy the app by running the following command:
Fetch the K8sApplication resource you've just created by running the below command obsessively until it's marked as Healthy
:
You should get something like this:
Print the logs of the application and see it fetching the AWS S3 Bucket:
To briefly recap what you did here:
Hope you enjoyed this article, and if you are interested in another article about something related (or unrelated), please convince Michael it's a good idea at michael@meteorops.com
Disclaimer: In actual environments or production, it’s essential to fine-tune the permissions in the different manifests. Instead of using access keys and secret keys directly, consider implementing IAM Roles for Service Accounts (IRSA) to manage permissions more securely.