Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alisson276/f1c3a9c8bc5e8956d9d3c4f1842a044c to your computer and use it in GitHub Desktop.
Save alisson276/f1c3a9c8bc5e8956d9d3c4f1842a044c to your computer and use it in GitHub Desktop.

Revisions

  1. @vfarcic vfarcic revised this gist Sep 21, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -134,7 +134,7 @@ argocd login \

    argocd account update-password \
    --current-password $PASS \
    --new-password admin
    --new-password admin123

    echo http://argo-cd.$INGRESS_HOST.nip.io

  2. @vfarcic vfarcic revised this gist Aug 3, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -243,7 +243,7 @@ git push
    unset KUBECONFIG

    # In the second terminal
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs.helm.crossplane.io,releases

    # Wait until all the resources are removed

  3. @vfarcic vfarcic revised this gist Aug 2, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -23,7 +23,7 @@
    # Setup #
    #########

    # Create a Kuberentes cluster with Ingress
    # Create a Kuberentes cluster with Ingress. It can be a local (e.g., KinD, minikube, etc.) or a remote cluster.

    # Replace `[...]` with the external IP of the Ingress service
    export INGRESS_HOST=[...]
    @@ -165,7 +165,7 @@ git commit -m "Team A infra"
    git push

    # In the second terminal
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs,releases
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs.helm.crossplane.io,releases

    # It might take a while until Argo CD detects the changes and the resources appear.

  4. @vfarcic vfarcic revised this gist Aug 2, 2021. 1 changed file with 17 additions and 18 deletions.
    35 changes: 17 additions & 18 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -23,14 +23,10 @@
    # Setup #
    #########

    # Feel free to use any other Kubernetes distribution
    minikube start
    # Create a Kuberentes cluster with Ingress

    # If not using Minikube, install Ingress in whichever way is suitable for your Kubernetes distribution
    minikube addons enable ingress

    # If not using Minikube, replace the value with the IP through which the Ingress Service can be accessed.
    export INGRESS_HOST=$(minikube ip)
    # Replace `[...]` with the external IP of the Ingress service
    export INGRESS_HOST=[...]

    # Replace `[...]` with the GitHub organization or user
    export GITHUB_ORG=[...]
    @@ -65,10 +61,6 @@ cat orig/team-apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee orig/team-apps.yaml

    cat argo-cd/overlays/production/ingress.yaml \
    | sed -e "s@host: .*@host: argo-cd.$INGRESS_HOST.nip.io@g" \
    | tee argo-cd/overlays/production/ingress.yaml

    cat apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee apps.yaml
    @@ -108,13 +100,20 @@ git commit -m "Personalization"

    git push

    kustomize build \
    argo-cd/overlays/production \
    | kubectl apply --filename -
    helm repo add argo \
    https://argoproj.github.io/argo-helm

    kubectl --namespace argocd \
    rollout status \
    deployment argocd-server
    helm repo update

    helm upgrade --install \
    argocd argo/argo-cd \
    --namespace argocd \
    --create-namespace \
    --set server.ingress.hosts="{argo-cd.$INGRESS_HOST.nip.io}" \
    --set server.ingress.enabled=true \
    --set server.extraArgs="{--insecure}" \
    --set controller.args.appResyncPeriod=30 \
    --wait

    kubectl apply --filename project.yaml

    @@ -266,4 +265,4 @@ git commit -m "Revert"

    git push

    minikube delete
    # Delete the cluster
  5. @vfarcic vfarcic revised this gist Aug 2, 2021. No changes.
  6. @vfarcic vfarcic revised this gist Aug 2, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -63,11 +63,11 @@ cat orig/team-app-reqs.yaml \

    cat orig/team-apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee cat orig/team-apps.yaml
    | tee orig/team-apps.yaml

    cat argo-cd/overlays/production/ingress.yaml \
    | sed -e "s@host: .*@host: argo-cd.$INGRESS_HOST.nip.io@g" \
    | tee cat argo-cd/overlays/production/ingress.yaml
    | tee argo-cd/overlays/production/ingress.yaml

    cat apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
  7. @vfarcic vfarcic revised this gist Aug 2, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -65,6 +65,10 @@ cat orig/team-apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee cat orig/team-apps.yaml

    cat argo-cd/overlays/production/ingress.yaml \
    | sed -e "s@host: .*@host: argo-cd.$INGRESS_HOST.nip.io@g" \
    | tee cat argo-cd/overlays/production/ingress.yaml

    cat apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee apps.yaml
  8. @vfarcic vfarcic revised this gist Jul 26, 2021. 1 changed file with 0 additions and 10 deletions.
    10 changes: 0 additions & 10 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -45,20 +45,10 @@ cd crossplane-kubevela-argocd-demo

    export REPO_URL=https://github.com/$GITHUB_ORG/crossplane-kubevela-argocd-demo

    cat argo-cd/overlays/production/ingress.yaml \
    | sed -e "s@host: .*@host: argo-cd.$INGRESS_HOST.nip.io@g" \
    | tee argo-cd/overlays/production/ingress.yaml

    cat production/sealed-secrets.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/sealed-secrets.yaml

    cp orig/argo-cd.yaml production/.

    cat production/argo-cd.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/argo-cd.yaml

    cat production/crossplane.yaml \
    | sed -e "s@repoURL: https://github.com.*@repoURL: $REPO_URL@g" \
    | tee production/crossplane.yaml
  9. @vfarcic vfarcic revised this gist Jul 26, 2021. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -53,6 +53,8 @@ cat production/sealed-secrets.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/sealed-secrets.yaml

    cp orig/argo-cd.yaml production/.

    cat production/argo-cd.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/argo-cd.yaml
  10. @vfarcic vfarcic revised this gist Jul 13, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,9 @@
    # Source: https://gist.github.com/6fb3e7da327df9203d9d4c184fcb5831

    ############################################################################
    # Making Kubernetes Dissapear With Argo CD, Crossplane, And Kubevela (OAM) #
    # https://youtu.be/eEcgn_gU3SM #
    ############################################################################
    ##############################################################################
    # Combining Argo CD (GitOps), Crossplane (Control Plane), And Kubevela (OAM) #
    # https://youtu.be/eEcgn_gU3SM #
    ##############################################################################

    # Referenced videos:
    # - Argo CD - Applying GitOps Principles To Manage Production Environment In Kubernetes: https://youtu.be/vpWQeoaiRM4
  11. @vfarcic vfarcic revised this gist Jul 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Source: TODO:
    # Source: https://gist.github.com/6fb3e7da327df9203d9d4c184fcb5831

    ############################################################################
    # Making Kubernetes Dissapear With Argo CD, Crossplane, And Kubevela (OAM) #
  12. @vfarcic vfarcic created this gist Jul 13, 2021.
    273 changes: 273 additions & 0 deletions 099-crossplane-kubevela-argocd.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,273 @@
    # Source: TODO:

    ############################################################################
    # Making Kubernetes Dissapear With Argo CD, Crossplane, And Kubevela (OAM) #
    # https://youtu.be/eEcgn_gU3SM #
    ############################################################################

    # Referenced videos:
    # - Argo CD - Applying GitOps Principles To Manage Production Environment In Kubernetes: https://youtu.be/vpWQeoaiRM4
    # - Cloud-Native Apps With Open Application Model (OAM) And KubeVela: https://youtu.be/2CBu6sOTtwk
    # - Crossplane - GitOps-based Infrastructure as Code through Kubernetes API: https://youtu.be/n8KjVmuHm7A
    # - How to apply GitOps to everything - combining Argo CD and Crossplane: https://youtu.be/yrj4lmScKHQ
    # - How To Shift Left Infrastructure Management Using Crossplane Composites: https://youtu.be/AtbS1u2j7po
    # - Bitnami Sealed Secrets - How To Store Kubernetes Secrets In Git Repositories: https://youtu.be/xd2QoV6GJlc
    # - Terraform vs. Pulumi vs. Crossplane - Infrastructure as Code (IaC) Tools Comparison: https://youtu.be/RaoKcJGchKM
    # - Portainer - Container Management Made Easy: https://youtu.be/-mWUbDHTEkQ
    # - Ketch - How to Simplify Kubernetes Deployments: https://youtu.be/sMOIiTfGnj0
    # - Shipa - A Kubernetes platform from developer's perspective: https://youtu.be/aCwlI3AhNOY
    # - Flux CD v2 With GitOps Toolkit - Kubernetes Deployment And Sync Mechanism: https://youtu.be/R6OeIgb7lUI
    # - GitHub CLI - How to manage repositories more efficiently: https://youtu.be/BII6ZY2Rnlc

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

    # Feel free to use any other Kubernetes distribution
    minikube start

    # If not using Minikube, install Ingress in whichever way is suitable for your Kubernetes distribution
    minikube addons enable ingress

    # If not using Minikube, replace the value with the IP through which the Ingress Service can be accessed.
    export INGRESS_HOST=$(minikube ip)

    # Replace `[...]` with the GitHub organization or user
    export GITHUB_ORG=[...]

    # Watch https://youtu.be/BII6ZY2Rnlc if you are not familiar with GitHub CLI
    gh repo fork vfarcic/crossplane-kubevela-argocd-demo \
    --clone

    cd crossplane-kubevela-argocd-demo

    # Install Crossplane CLI from https://crossplane.io/docs/v1.3/getting-started/install-configure.html#start-with-a-self-hosted-crossplane

    export REPO_URL=https://github.com/$GITHUB_ORG/crossplane-kubevela-argocd-demo

    cat argo-cd/overlays/production/ingress.yaml \
    | sed -e "s@host: .*@host: argo-cd.$INGRESS_HOST.nip.io@g" \
    | tee argo-cd/overlays/production/ingress.yaml

    cat production/sealed-secrets.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/sealed-secrets.yaml

    cat production/argo-cd.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/argo-cd.yaml

    cat production/crossplane.yaml \
    | sed -e "s@repoURL: https://github.com.*@repoURL: $REPO_URL@g" \
    | tee production/crossplane.yaml

    cat production/team-a-infra.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee production/team-a-infra.yaml

    cat orig/team-app-reqs.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee orig/team-app-reqs.yaml

    cat orig/team-apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee cat orig/team-apps.yaml

    cat apps.yaml \
    | sed -e "s@repoURL: .*@repoURL: $REPO_URL@g" \
    | tee apps.yaml

    kubectl apply --filename sealed-secrets

    #############
    # Setup AWS #
    #############

    # Replace `[...]` with your access key ID`
    export AWS_ACCESS_KEY_ID=[...]

    # Replace `[...]` with your secret access key
    export AWS_SECRET_ACCESS_KEY=[...]

    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 crossplane-configs/aws-creds.yaml

    #################
    # Setup Argo CD #
    #################

    git add .

    git commit -m "Personalization"

    git push

    kustomize build \
    argo-cd/overlays/production \
    | kubectl apply --filename -

    kubectl --namespace argocd \
    rollout status \
    deployment argocd-server

    kubectl apply --filename project.yaml

    kubectl apply --filename apps.yaml

    export PASS=$(kubectl \
    --namespace argocd \
    get secret argocd-initial-admin-secret \
    --output jsonpath="{.data.password}" \
    | base64 --decode)

    argocd login \
    --insecure \
    --username admin \
    --password $PASS \
    --grpc-web \
    argo-cd.$INGRESS_HOST.nip.io

    argocd account update-password \
    --current-password $PASS \
    --new-password admin

    echo http://argo-cd.$INGRESS_HOST.nip.io

    # Open it in a browser

    # Use `admin` as both the username and password

    # Open a second terminal and go to the same directory as in the first

    ##########
    # GitOps #
    ##########

    # Observe the Argo CD UI and wait until the apps are rolled out

    ##################
    # Infrastructure #
    ##################

    cat orig/cluster.yaml

    cp orig/cluster.yaml team-a-infra/.

    git add .

    git commit -m "Team A infra"

    git push

    # In the second terminal
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs,releases

    # It might take a while until Argo CD detects the changes and the resources appear.

    # Wait until all the resources are ready and synced

    chmod +x config-cluster-aws.sh

    ./config-cluster-aws.sh team-a

    ################
    # Applications #
    ################

    cat orig/my-app.yaml

    cp orig/my-app.yaml team-a-apps/.

    git add .

    git commit -m "Team A apps"

    git push

    # In the second terminal
    export KUBECONFIG=$PWD/kubeconfig.yaml

    # In the second terminal
    kubectl --namespace production \
    get all,hpa,ingress

    ##########################
    # How did it all happen? #
    ##########################

    # In the second terminal
    cat apps.yaml

    # In the second terminal
    ls -1 production

    # In the second terminal
    cat production/team-a-infra.yaml

    # In the second terminal
    ls -1 team-a-infra

    # In the second terminal
    cat crossplane-compositions/definition.yaml

    # In the second terminal
    cat crossplane-compositions/cluster-aws.yaml

    cat team-a-infra/cluster.yaml

    # In the second terminal
    cat team-a-app-reqs/kubevela.yaml

    cat team-a-apps/my-app.yaml

    # Show Argo CD

    ###########################
    # Deleting infrastructure #
    ###########################

    rm team-a-infra/cluster.yaml

    git add .

    git commit -m "Remove the cluster"

    git push

    # In the second terminal
    unset KUBECONFIG

    # In the second terminal
    kubectl get clusters,nodegroup,iamroles,iamrolepolicyattachments,vpcs,securitygroups,subnets,internetgateways,routetables,providerconfigs

    # Wait until all the resources are removed

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

    rm -rf team-a-apps

    rm -rf team-a-app-reqs

    rm production/team-a-apps.yaml

    rm production/team-a-app-reqs.yaml

    git add .

    git commit -m "Revert"

    git push

    minikube delete