Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Created July 29, 2021 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vfarcic/1637882722d0d6539430bd9bfd516d84 to your computer and use it in GitHub Desktop.
Save vfarcic/1637882722d0d6539430bd9bfd516d84 to your computer and use it in GitHub Desktop.
# Source: TODO:
##############################################################################
# TODO: #
##############################################################################
# Referenced videos:
# - Flux TODO:
# - Upbound TODO:
# - Crossplane TODO:
# - K3d TODO:
#########
# Setup #
#########
git clone \
https://github.com/$GITHUB_ORG/crossplane-flux-infra
cd crossplane-flux-infra
ls -1 kustomize
# Replace `[...]` with the GitHub organization or user
export GITHUB_ORG=[...]
# Replace `[...]` with the GitHub token
export GITHUB_TOKEN=[...]
# Replace `[...]` with `true` if it is a personal account, or with `false` if it is an GitHub organization
export GITHUB_PERSONAL=[...]
# Replace `[...]` with your access key ID`
export AWS_ACCESS_KEY_ID=[...]
# Replace `[...]` with your secret access key
export AWS_SECRET_ACCESS_KEY=[...]
# Please watch https://youtu.be/mCesuGk-Fks if you are not familiar with k3d
# Feel free to use any other Kubernetes platform
k3d cluster create --config k3d.yaml
cat kustomize/definition.yaml
cat kustomize/cluster-aws.yaml
# TODO: Switch from Crossplane to UXP (https://charts.upbound.io/)
cd ..
# https://fluxcd.io/docs/get-started/#install-the-flux-cli
flux bootstrap github \
--owner $GITHUB_ORG \
--repository crossplane-flux \
--branch main \
--path infra \
--personal $GITHUB_PERSONAL
git clone \
https://github.com/$GITHUB_ORG/crossplane-flux
cd crossplane-flux
ls -1 infra
ls -1 infra/flux-system
flux create source helm crossplane \
--interval 1h \
--url https://charts.crossplane.io/stable \
--export \
| tee infra/crossplane-source.yaml
flux create helmrelease crossplane \
--interval 1h \
--release-name crossplane \
--target-namespace crossplane-system \
--create-target-namespace \
--source HelmRepository/crossplane \
--chart crossplane \
--crds CreateReplace \
--export \
| tee infra/crossplane-release.yaml
flux create source git infra \
--url https://github.com/vfarcic/crossplane-flux-infra \
--branch main \
--interval 30s \
--export \
| tee infra/infra-source.yaml
flux create kustomization infra \
--source infra \
--path kustomize \
--prune true \
--validation client \
--interval 1m \
--export \
| tee -a infra/infra-kustomization.yaml
git add .
git commit -m "Infra"
git push
echo "[default]
aws_access_key_id = $AWS_ACCESS_KEY_ID
aws_secret_access_key = $AWS_SECRET_ACCESS_KEY
" | tee aws-creds.conf
kubectl --namespace crossplane-system \
create secret generic aws-creds \
--from-file creds=./aws-creds.conf \
--output json \
--dry-run=client \
| kubeseal --format yaml \
| tee infra/aws-creds.yaml
echo "apiVersion: aws.crossplane.io/v1beta1
kind: ProviderConfig
metadata:
name: default
spec:
credentials:
source: Secret
secretRef:
namespace: crossplane-system
name: aws-creds
key: creds" \
| tee infra/aws-provider-config.yaml
git add .
git commit -m "AWS"
git push
flux get kustomizations
flux get helmreleases
# Switch to claim
echo "apiVersion: devopstoolkitseries.com/v1alpha1
kind: CompositeCluster
metadata:
name: my-cluster
spec:
id: team-a
compositionRef:
name: cluster-aws
parameters:
nodeSize: small" \
| tee infra/my-cluster.yaml
git add .
git commit -m "My cluster"
git push
kubectl get managed
# Wait until all the resources are created
# Show in Upbound Cloud
# Show in AWS Console
rm infra/my-cluster.yaml
git add .
git commit -m "Removed my cluster"
git push
kubectl get managed
# Wait until all the resources are removed
gh repo view --web
# Remove the repo
k3d cluster delete devops-toolkit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment