This project demonstrates how to use Crossplane to provision and manage the required AWS IAM resources for a Karpenter installation, acting as a direct replacement for tools like Terraform.
Instead of managing multiple IAM resources manually, this demo creates a single, cluster-scoped Crossplane Composite Resource Definition (XRD) called karpenter.
When you create an instance of the karpenter custom resource, a Crossplane Composition (using function-patch-and-transform) will automatically provision the following four AWS resources:
Policy(IAM Policy)Role(IAM Role)RolePolicyAttachmentPodIdentityAssociation(for EKS)
Note: This demo is for provisioning new resources. While Crossplane does support importing and adopting existing resources, that functionality is not configured in this composition for simplicity.
Before running the demo, you will need the following tools installed on your local machine:
kubectlhelmkind
You must export your AWS credentials as environment variables. The run.sh script will use these to create the necessary Kubernetes secret for Crossplane.
# Replace with your actual AWS credentials
export AWS_ACCESS_KEY_ID="YOUR_AWS_ACCESS_KEY_ID"
export AWS_SECRET_ACCESS_KEY="YOUR_AWS_SECRET_ACCESS_KEY"Execute the run.sh script, which will perform all setup steps automatically:
./run.shThe run.sh script will automatically print the status of the newly created AWS resources at the end. You can also run this command manually to check the status:
kubectl get -A Policy,Role.iam.aws.m.upbound.io,RolePolicyAttachment,PodIdentityAssociationYou can also check the status of your main karpenter resource:
kubectl get karpenter karpenter -o yamlLook for the status.conditions to see if it's Synced: True.
The run.sh script automates the entire setup:
- Creates a local cluster.
- Installs Crossplane via Helm.
- Installs
aws-iamandaws-eksproviders. - Installs composition
patch-and-transformfunction, which is required by Composition. - Your exported AWS credentials are used to create the
aws-secretin thecrossplane-systemnamespace for providers to authenticate. - Applies
xrd.yaml(custom API) andcomposition.yaml(the implementation). - Finally,
karpenter.yamlis applied. This creates thekarpentercustom resource, which signals Crossplane to execute the composition and create the four AWS resources.
To delete all resources and the local cluster, simply run:
kubectl delete -f deploy/karpenter.yaml
kind delete cluster