Skip to content

Commit

Permalink
added crossplane compositions
Browse files Browse the repository at this point in the history
  • Loading branch information
aghilish committed Feb 5, 2024
1 parent 6fb777c commit 2e88411
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- [Kustomize](./templating/kustomize.md)
- [Terraform](./templating/terraform.md)
- [Crossplane](./templating/crossplane.md)
- [Crossplane Compositions](./templating/crossplane-compositions.md)

# Helm

Expand Down
161 changes: 161 additions & 0 deletions src/templating/crossplane-compositions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
# Crossplane Compositions

## Links

* [Video By Shahrooz Aghili](https://www.youtube.com/watch?v)
* [Crossplane](https://crossplane.io/)
* [Docs](https://docs.crossplane.io/)

Highlights and Intro:
> **Crossplane** is an advanced tool for managing infrastructure in the cloud-native ecosystem.
> Just like terraform encourages using modules for bundling related resources, crossplane offers compositions.
> `Platform engineers` can define their compositions and provide the `Devs` a simple claim api.
> `Devs` claim their resources and the composition takes care of the rest.

### start minikube
```
minikube start
```

### install crossplane
```
helm repo add crossplane-stable \
https://charts.crossplane.io/stable
helm repo update
helm upgrade --install \
crossplane crossplane-stable/crossplane \
--namespace crossplane-system \
--create-namespace \
--wait
```


### create GCP credentials secret for crossplane

```
export SA_NAME="YOUR-SA-NAME"
export SA="${SA_NAME}@${PROJECT_ID}.iam.gserviceaccount.com"
gcloud iam service-accounts \
create $SA_NAME \
--project $PROJECT_ID
export ROLE=roles/admin
gcloud projects add-iam-policy-binding \
--role $ROLE $PROJECT_ID \
--member serviceAccount:$SA
gcloud iam service-accounts keys \
create gcp-creds.json \
--project $PROJECT_ID \
--iam-account $SA
kubectl --namespace crossplane-system \
create secret generic gcp-creds \
--from-file creds=./gcp-creds.json
```

### install GCP provider
```
cat <<EOF | kubectl create -f -
apiVersion: pkg.crossplane.io/v1
kind: Provider
metadata:
name: provider-gcp-container
spec:
package: xpkg.upbound.io/upbound/provider-gcp-container:v0.41.1
EOF
```

### configure provider
```
PROJECT_ID=$(gcloud config get-value project)
echo "apiVersion: gcp.upbound.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
projectID: $PROJECT_ID
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: gcp-creds
key: creds" \
| kubectl apply --filename -
```

### apply XRD
```
kubectl apply --filename xrd.yaml
```

### apply composition
```
kubectl apply --filename composition.yaml
```


### create infra namespace
```
kubectl create ns infra
```


### apply claim

```
kubectl apply --filename a-team-gke/claim.yaml -n infra
```

### verify resources

```
kubectl describe composition cluster-google
```

```
kubectl explain CompositeCluster --recursive
```

```
kubectl get compositeclusters
```

```
kubectl describe CompositeCluster a-team-gke
```

```
kubectl get clusters,nodepools
```

### access the GKE cluster
```
kubectl --namespace infra \
get secret a-team-gke-cluster \
--output jsonpath="{.data.kubeconfig}" \
| base64 -d \
| tee kubeconfig.yaml
export KUBECONFIG=$PWD/kubeconfig.yaml
kubectl get nodes
kubectl get namespaces
```

### destroy infrastructure

```
unset KUBECONFIG
kubectl delete -n infra --filename a-team-gke/claim.yaml
```

0 comments on commit 2e88411

Please sign in to comment.