
In this blog rather than going into details and thearotical part about crossplane , will look how to start with crossplane and cretae infrastructure with the help of it. The very first step we need to do is to install crossplane to use it.
Installation of Crossplane
Let’s take a look at how Crossplane allows us to provision cloud resources. We are creating resources on the cloud AWS.
Prerequisites
- Get a Kubernetes Cluster or Kind Cluster or Minikube v0.28+
- Helm, minimum version v3.0.0+.
Once you have created your k8 cluster or minikube one. Install crossplane on the cluster with the help of below commands
Installing Crossplane
Use Helm 3 to install the latest official stable release of Crossplane.
# kubectl create namespace crossplane
# helm repo add crossplane-stable https://charts.crossplane.io/stable
# helm repo update
# helm install crossplane --namespace crossplane crossplane-stable/crossplane
Check Crossplane Status.
# helm list -n crossplane
# kubectl get all -n crossplane
Use the following command to install crossplane CLI
# curl -sL https://raw.githubusercontent.com/crossplane/crossplane/release-1.5/install.sh | sh
Move executable to path /usr/local/bin
# mv kubectl-crossplane /usr/local/bin
Verify the installation.
# kubectl-crossplane --version
Once the Crossplane is installed successfully on cluster, and created a crossplane namespace. Let install the provider now which you wanted . I am installing AWS provider with the help of below manifest file.
aws-provider.yaml
--------------------------------------------------------
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: aws-provider
spec:
package: crossplane/provider-aws:alpha
kubectl apply -f aws-provider.yaml
Execute the command : kubectl apply -f aws-provider.yaml you will get below output
knoldus@INL-F9ZYN93:~/crossplane-aws$ kubectl apply -f aws-provider.yaml
provider.pkg.crossplane.io/aws-provider created
###Once you install the Provider, wait for the Provider to be healthy by executing kubectl get provider.pkg
knoldus@INL-F9ZYN93:~/crossplane-aws$ kubectl get provider.pkg
NAME INSTALLED HEALTHY PACKAGE AGE
aws-provider True True crossplane/provider-aws:alpha 5m25s
Once the Provider is healthy let us now configure the Provider to communicate with AWS by creating a ProviderConfig definition. Make sure that you have already configured your credentials using AWS configure
###Generate the configuration files with the AWS Credentials.
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
###Create a Kubernetes secret with the configuration file generated.
kubectl create secret generic aws-secret-creds -n crossplane-system --from-file=creds=./creds.conf
###Once the secret is created let us now create the Provider config for our AWS account.
kubectl apply -f provider-config.yaml
apiVersion: aws.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
name: awsconfig
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane
name: aws-secret-creds
key: creds
Upon successful creation, your local cluster should now be able to communicate with AWS.
Now lets create VPC , Subnet and route table on AWS
- Let us create a VPC in the us-east-1 region with the below-mentioned spec.
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: VPC
metadata:
name: production-vpc
spec:
forProvider:
region: us-east-1
cidrBlock: 192.168.0.0/16
enableDnsSupport: true
enableDnsHostNames: true
tags:
- key: Environment
value: Production
- key: Owner
value: Sakshi
- key: Name
value: production-vpc
instanceTenancy: default
providerConfigRef:
name: awsconfig
kubectl apply -f aws-vpc.yaml
###Let us check the status of the VPC
kubectl get vpc
knoldus@INL-F9ZYN93:~/crossplane-aws$ kubectl get vpc
NAME READY SYNCED ID CIDR AGE
production-vpc True true vpc-004c2d1ba7394b3d6 192.168.0.0/16 46s
2. Once our VPC is successfully created let us create 2 subnets
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: Subnet
metadata:
name: prod-subnet-1
spec:
forProvider:
region: us-east-1
availabilityZone: us-east-1a
cidrBlock: 192.168.1.0/24
vpcIdRef:
name: production-vpc
tags:
- key: Environment
value: Production
- key: Name
value: prod-subnet-1
- key: Owner
value: Sakshi
mapPublicIPOnLaunch: true
providerConfigRef:
name: awsconfig
---
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: Subnet
metadata:
name: prod-subnet-2
spec:
forProvider:
region: us-east-1
availabilityZone: us-east-1b
cidrBlock: 192.168.2.0/24
vpcIdRef:
name: production-vpc
tags:
- key: Environment
value: Production
- key: Name
value: prod-subnet-2
- key: Owner
value: Sakshi
mapPublicIPOnLaunch: true
providerConfigRef:
name: awsconfig
kubectl apply -f aws-subnet.yaml
###Let us check the status of the subnets.
kubectl get subnets
3. Let us now create the corresponding Internet gateway and Route table.
apiVersion: ec2.aws.crossplane.io/v1beta1
kind: InternetGateway
metadata:
name: production-internetgateway
spec:
forProvider:
region: us-east-1
vpcIdRef:
name: production-vpc
providerConfigRef:
name: awsconfig
---
apiVersion: ec2.aws.crossplane.io/v1alpha4
kind: RouteTable
metadata:
name: production-routetable
spec:
forProvider:
region: us-east-1
routes:
- destinationCidrBlock: 0.0.0.0/0
gatewayIdRef:
name: production-internetgateway
associations:
- subnetIdRef:
name: prod-subnet-2
- subnetIdRef:
name: prod-subnet-1
vpcIdRef:
name: production-vpc
providerConfigRef:
name: awsconfig
kubectl apply -f aws-igwrt.yaml
###Let us check the status of the Route table and Internet Gateway
kubectl get InternetGateway,RouteTable
In this way you can create the infrastructure using crossplane. You can create many more resources you required . I just shown some of the example.
For the reference you can refer https://docs.crossplane.io/v1.13/getting-started/provider-aws/
Proudly powered by WordPress