Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active August 18, 2022 23:04
Show Gist options
  • Select an option

  • Save vfarcic/2e67c67a36a2e782422ebefb4a0a2612 to your computer and use it in GitHub Desktop.

Select an option

Save vfarcic/2e67c67a36a2e782422ebefb4a0a2612 to your computer and use it in GitHub Desktop.

Revisions

  1. vfarcic revised this gist Aug 18, 2022. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions 999-crossplane-terrajet.sh
    Original file line number Diff line number Diff line change
    @@ -95,10 +95,10 @@ kubectl get pkgrev
    # Demo #
    ########

    cat examples/azure-aks.yaml
    cat examples/k8s/azure-aks.yaml

    kubectl apply \
    --filename examples/azure-aks.yaml
    --filename examples/k8s/azure-aks.yaml

    kubectl get managed,objects

    @@ -109,7 +109,7 @@ cat packages/k8s/aks.yaml
    ###########

    kubectl delete \
    --filename examples/azure-aks.yaml
    --filename examples/k8s/azure-aks.yaml

    kubectl get azurejet

  2. vfarcic revised this gist Jan 21, 2022. 1 changed file with 38 additions and 35 deletions.
    73 changes: 38 additions & 35 deletions 999-crossplane-terrajet.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,19 @@
    # Source: https://gist.github.com/2e67c67a36a2e782422ebefb4a0a2612

    ############################################################################
    # How To Use Terrajet Providers With 100% Coverage for AWS, GCP, And Azure #
    # https://youtu.be/QSwF3Y4ViKQ #
    ############################################################################

    # Additional Info:
    # - Terrajet: https://github.com/crossplane/terrajet
    # - How To Shift Left Infrastructure Management Using Crossplane Compositions: https://youtu.be/AtbS1u2j7po
    # - Crossplane - GitOps-based Infrastructure as Code through Kubernetes API: https://youtu.be/n8KjVmuHm7A

    #########
    # Setup #
    #########

    git clone https://github.com/vfarcic/devops-toolkit-crossplane

    cd devops-toolkit-crossplane
    @@ -6,9 +22,9 @@ cd devops-toolkit-crossplane

    kubectl create namespace crossplane-system

    #########
    # Azure #
    #########
    ###############
    # Setup Azure #
    ###############

    az ad sp create-for-rbac \
    --sdk-auth \
    @@ -42,9 +58,9 @@ kubectl --namespace crossplane-system \
    create secret generic azure-creds \
    --from-file creds=./azure-creds.json

    ##############
    # Crossplane #
    ##############
    ####################
    # Setup Crossplane #
    ####################

    helm repo add crossplane-stable \
    https://charts.crossplane.io/stable
    @@ -60,56 +76,43 @@ helm upgrade --install \
    kubectl apply \
    --filename crossplane-config/provider-azure.yaml

    kubectl apply \
    --filename crossplane-config/provider-kubernetes.yaml

    kubectl apply \
    --filename crossplane-config/provider-config-azure.yaml

    # Please re-run the previous command if the output is `unable to recognize ...`

    #######
    # AKS #
    #######

    cat crossplane-config/config-k8s.yaml

    kubectl apply \
    --filename crossplane-config/config-k8s.yaml

    cat examples/azure-aks.yaml
    kubectl get pkgrev

    kubectl apply \
    --filename examples/azure-aks.yaml
    # Wait until all the packages are healthy

    kubectl get managed
    ########
    # Demo #
    ########

    # Set `spec.parameters.nodeSize` to `5` in `examples/azure-aks.yaml`
    cat examples/azure-aks.yaml

    kubectl apply \
    --filename examples/azure-aks.yaml

    kubectl get managed

    export KUBECONFIG=$PWD/kubeconfig.yaml

    # TODO: Get KubeConfig from the secret
    # TODO: https://github.com/crossplane-contrib/provider-tf-azure/issues/80
    kubectl get managed,objects

    kubectl get nodes

    # TODO: Show that Prometheus is running

    unset KUBECONFIG

    kubectl get compositeclusters
    cat packages/k8s/aks.yaml

    ###########
    # Destroy #
    ###########

    kubectl delete \
    --filename examples/azure-aks-no-claim.yaml
    --filename examples/azure-aks.yaml

    kubectl get azurejet

    cat examples/azure-aks.yaml \
    | sed -e "s@minNodeCount: .*@minNodeCount: 3@g" \
    | tee examples/azure-aks.yaml
    # Wait until all the resources are removed

    # Destroy the Kubernetes cluster
    # Destroy or reset the maanagement Kubernetes cluster
  3. vfarcic created this gist Dec 2, 2021.
    115 changes: 115 additions & 0 deletions 999-crossplane-terrajet.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,115 @@
    git clone https://github.com/vfarcic/devops-toolkit-crossplane

    cd devops-toolkit-crossplane

    # Create a Kubernetes cluster

    kubectl create namespace crossplane-system

    #########
    # Azure #
    #########

    az ad sp create-for-rbac \
    --sdk-auth \
    --role Owner \
    | tee azure-creds.json

    export AZURE_CLIENT_ID=$(\
    cat azure-creds.json \
    | grep clientId \
    | cut -c 16-51)

    export AAD_GRAPH_API=00000003-0000-0000-c000-000000000000

    az ad app permission add \
    --id "${AZURE_CLIENT_ID}" \
    --api ${AAD_GRAPH_API} \
    --api-permissions \
    e1fe6dd8-ba31-4d61-89e7-88639da4683d=Scope \
    06da0dbc-49e2-44d2-8312-53f166ab848a=Scope \
    7ab1d382-f21e-4acd-a863-ba3e13f7da61=Role

    az ad app permission grant \
    --id $AZURE_CLIENT_ID \
    --api $AAD_GRAPH_API \
    --expires never

    az ad app permission admin-consent \
    --id "${AZURE_CLIENT_ID}"

    kubectl --namespace crossplane-system \
    create secret generic azure-creds \
    --from-file creds=./azure-creds.json

    ##############
    # 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

    kubectl apply \
    --filename crossplane-config/provider-azure.yaml

    kubectl apply \
    --filename crossplane-config/provider-config-azure.yaml

    # Please re-run the previous command if the output is `unable to recognize ...`

    #######
    # AKS #
    #######

    cat crossplane-config/config-k8s.yaml

    kubectl apply \
    --filename crossplane-config/config-k8s.yaml

    cat examples/azure-aks.yaml

    kubectl apply \
    --filename examples/azure-aks.yaml

    kubectl get managed

    # Set `spec.parameters.nodeSize` to `5` in `examples/azure-aks.yaml`

    kubectl apply \
    --filename examples/azure-aks.yaml

    kubectl get managed

    export KUBECONFIG=$PWD/kubeconfig.yaml

    # TODO: Get KubeConfig from the secret
    # TODO: https://github.com/crossplane-contrib/provider-tf-azure/issues/80

    kubectl get nodes

    # TODO: Show that Prometheus is running

    unset KUBECONFIG

    kubectl get compositeclusters

    ###########
    # Destroy #
    ###########

    kubectl delete \
    --filename examples/azure-aks-no-claim.yaml

    cat examples/azure-aks.yaml \
    | sed -e "s@minNodeCount: .*@minNodeCount: 3@g" \
    | tee examples/azure-aks.yaml

    # Destroy the Kubernetes cluster