From 89b8da435c661292dc1bf1e79d6c23c8796b7c40 Mon Sep 17 00:00:00 2001 From: Hannah Kennedy Date: Mon, 31 Oct 2022 15:42:33 -0400 Subject: [PATCH] Adjustments to outloop labs. --- labs/outer-loop-aks-azure.md | 157 ++++++++++---------- labs/outer-loop-arc-gitops.md | 122 ++++++++-------- labs/outer-loop-multi-cluster.md | 186 ++++++++++++------------ labs/outer-loop-ring-deployment.md | 223 +++++++++++++++++------------ labs/outer-loop.md | 213 ++++++++++++++------------- 5 files changed, 482 insertions(+), 419 deletions(-) diff --git a/labs/outer-loop-aks-azure.md b/labs/outer-loop-aks-azure.md index 7aa46750..a5ed1d74 100644 --- a/labs/outer-loop-aks-azure.md +++ b/labs/outer-loop-aks-azure.md @@ -17,115 +17,124 @@ git branch --show-current ## Login to Azure -- Login to Azure using `az login --use-device-code` - > Use `az login --use-device-code --tenant ` to specify a different tenant - - If you have more than one Azure subscription, select the correct subscription +Login to Azure using `az login --use-device-code`. - ```bash +Use `az login --use-device-code --tenant ` to specify a different tenant if you have access +to more than one tenant. - # verify your account - az account show +If you have more than one Azure subscription, select the correct subscription: - # list your Azure accounts - az account list -o table +```bash - # set your Azure subscription - az account set -s mySubNameOrId +# verify your account +az account show - # verify your account - az account show +# list your Azure accounts +az account list -o table - ``` +# set your Azure subscription +az account set -s mySubNameOrId -- Validate user role on subscription - > Make sure your RoleDefinitionName is `Contributor` or `Owner` to create resources in this lab succssfully +# verify your account +az account show - ```bash +``` - # get az user name and validate your role assignment - principal_name=$(az account show --query "user.name" --output tsv | sed -r 's/[@]+/_/g') - az role assignment list --query "[].{principalName:principalName, roleDefinitionName:roleDefinitionName, scope:scope} | [? contains(principalName,'$principal_name')]" -o table +Validate user role on the subscription. Make sure your RoleDefinitionName is `Contributor` or `Owner` +to create resources in this lab successfully. - ``` +```bash -## Create Arc enabled AKS Cluster +# get az user name and validate your role assignment +principal_name=$(az account show --query "user.name" --output tsv | sed -r 's/[@]+/_/g') +az role assignment list --query "[].{principalName:principalName, roleDefinitionName:roleDefinitionName, scope:scope} | [? contains(principalName,'$principal_name')]" -o table -### Create AKS Cluster +``` -> This AKS setup is insecure and intended for learning, dev and test only. For secure or production clusters, please refer [AKS Secure Baseline](https://github.com/mspnp/aks-baseline) +## Create Arc-enabled AKS Cluster - ```bash +### Create AKS Cluster - # set MY_AKS_CLUSTER - export MY_AKS_CLUSTER=central-tx-atx-$MY_BRANCH-aks +> ⛔️ This AKS setup is **insecure** and intended for learning, dev and test only. For secure +> or production clusters, please refer [AKS Secure Baseline](https://github.com/mspnp/aks-baseline). - # set MY_RG - export MY_RG=$MY_BRANCH-rg +```bash - ``` +# set MY_AKS_CLUSTER +export MY_AKS_CLUSTER=central-tx-atx-$MY_BRANCH-aks - ```bash +# set MY_RG +export MY_RG=$MY_BRANCH-rg - # create resource group - az group create --name $MY_RG --location eastus +# create resource group +az group create --name $MY_RG --location eastus - # create AKS cluster - # this may take 3-5 mins - az aks create -g $MY_RG -n $MY_AKS_CLUSTER --enable-managed-identity --node-count 1 --generate-ssh-keys +# create AKS cluster +# this may take 3-5 mins +az aks create -g $MY_RG -n $MY_AKS_CLUSTER \ +--enable-managed-identity --node-count 1 \ +--generate-ssh-keys - ``` +``` ### Arc enable the AKS Cluster - ```bash +```bash - # install the connectedk8s Azure CLI extension - az extension add --name connectedk8s +# install the connectedk8s Azure CLI extension +az extension add --name connectedk8s - # get aks creds - az aks get-credentials --resource-group $MY_RG --name $MY_AKS_CLUSTER +# get aks creds +az aks get-credentials --resource-group $MY_RG --name $MY_AKS_CLUSTER - # arc enable - # this may take 2-3 mins - az connectedk8s connect --name $MY_AKS_CLUSTER --resource-group $MY_RG --location eastus +# arc enable +# this may take 2-3 mins +az connectedk8s connect --name $MY_AKS_CLUSTER \ +--resource-group $MY_RG \ +--location eastus - ``` +``` ## Set up for GitOps -### Flt setup +### `flt` setup + +```bash - ```bash +# create the cluster metadata +flt create --gitops-only -c $MY_AKS_CLUSTER - # create the cluster metadata - flt create --gitops-only -c $MY_AKS_CLUSTER +``` - ``` +This will create the cluster metadata for GitOps. You will have to wait for the CI/CD steps to +complete. -- This will create the cluster metadata for GitOps -- Wait for ci-cd to complete -- run `git pull` - - You should see the yaml files created in the `clusters` directory +Run `git pull` and you should see the yaml files created in the `clusters` directory! ### Create flux secret - ```bash +```bash + +# create secret for GitOps +kubectl apply -f "clusters/$MY_AKS_CLUSTER/flux-system/namespace.yaml" - # create secret for GitOps - kubectl apply -f "clusters/$MY_AKS_CLUSTER/flux-system/namespace.yaml" - flux create secret git flux-system -n flux-system --url "$PIB_FULL_REPO" -u gitops -p "$PIB_PAT" +flux create secret git flux-system \ +-n flux-system \ +--url "$PIB_FULL_REPO" \ +-u gitops -p "$PIB_PAT" - ``` +``` ## Create GitOps configuration with Arc -- All of the values you need for Arc setup are displayed via `flt env` and starts with PIB_* +All of the values you need for Arc setup are displayed via `flt env` and start with `PIB_*`. -- From the Azure Arc Portal - - Select `Kubernetes Clusters` in left nav - - Select the cluster - - Select `GitOps` in the left nav - - Click `Create` +- Go to the Azure Arc Portal. +- Select `Kubernetes Clusters` in left navigation. +- Select the cluster. +- Select `GitOps` in the left navigation. +- Click `Create`. +- The recommended settings are: - Basics: - Configuration Name: `gitops` - Namespace: `flux-system` @@ -134,7 +143,7 @@ git branch --show-current - Source kind: `Git Repository` - Repository URL: `https://github.com/kubernetes101/pib-dev` - Reference type: `Branch` - - Branch: value of MY_BRANCH + - Branch: value of `MY_BRANCH` - Repository Type:`Private` - Authentication source: `Provide Authentication information here` - HTTPS User: `gitops` @@ -143,23 +152,21 @@ git branch --show-current - Sync interval: 1 minute - Sync timeout: 3 minutes - Kustomization - - Instance name: flux-system - - Path: ./clusters/{{cluster-name}}/flux-system + - Instance name: `flux-system` + - Path: `./clusters/{{cluster-name}}/flux-system` - Sync interval: 1 minute - Sync timeout: 3 minutes - Retry interval: 1 minute - Prune: checked - Force: checked - Depends on: leave blank - - Wait for gitops configuration to be created - - Select `Configuration objects` from the left nav of `GitOps` config - - Wait for `gitops-flux-system` to be created - - Wait for it to be `Compliant` +- Wait for GitOps configuration to be created. +- Select `Configuration objects` from the left navigation of the `GitOps` configuration. +- Wait for `gitops-flux-system` to be created, and then for it to be "Compliant." ## Check in Arc Portal -- Use the Arc Portal to check GitOps setup - - Check cluster namespaces and workloads +Use the Arc Portal to check GitOps setup. Check on the cluster namespaces and workloads. ## Deploy sample app @@ -186,7 +193,7 @@ git pull ## Cleanup -- Once you're finished with the workshop and experimenting, delete your cluster and Azure resources +Once you're finished with the workshop and experimenting, delete your cluster and Azure resources: ```bash diff --git a/labs/outer-loop-arc-gitops.md b/labs/outer-loop-arc-gitops.md index a211cb49..5710f1fe 100644 --- a/labs/outer-loop-arc-gitops.md +++ b/labs/outer-loop-arc-gitops.md @@ -17,25 +17,28 @@ git branch --show-current ## Login to Azure -- Login to Azure using `az login --use-device-code` - > Use `az login --use-device-code --tenant ` to specify a different tenant - - If you have more than one Azure subscription, select the correct subscription +Login to Azure using `az login --use-device-code`. - ```bash +Use `az login --use-device-code --tenant ` to specify a different tenant if you have access +to more than one tenant. - # verify your account - az account show +If you have more than one Azure subscription, select the correct subscription: - # list your Azure accounts - az account list -o table +```bash + +# verify your account +az account show + +# list your Azure accounts +az account list -o table - # set your Azure subscription - az account set -s mySubNameOrId +# set your Azure subscription +az account set -s mySubNameOrId - # verify your account - az account show +# verify your account +az account show - ``` +``` - Validate user role on subscription > Make sure your RoleDefinitionName is `Contributor` or `Owner` to create resources in this lab succssfully @@ -50,11 +53,15 @@ git branch --show-current ## Create/Set Managed Identity -- If you don't already have managed identity set in your subscription, follow [these steps](./azure-codespaces-setup.md#create-managed-identity) to create RG and MI -- Run `flt env` and make sure `PIB_MI` is set +If you don't already have managed identity set in your subscription, follow [these steps](./azure-codespaces-setup.md#create-managed-identity) +to create a resource group and managed identity. + +Run `flt env` and make sure `PIB_MI` is set. ## Create an Arc enabled Dev Cluster +> The cluster name here is just an example. You can follow a different pattern. + ```bash # set MY_CLUSTER @@ -68,8 +75,8 @@ flt create cluster -c $MY_CLUSTER --arc ## Update Git Repo -- [CI-CD](https://github.com/kubernetes101/pib-dev/actions) generates the deployment manifests - - Wait for CI-CD to complete (usually about 30 seconds) +[CI-CD](https://github.com/kubernetes101/pib-dev/actions) generates the deployment manifests. You +will have to wait for CI-CD to complete, which usually takes about 30 seconds. ```bash @@ -99,64 +106,67 @@ watch flt check setup ## Deploy IMDb App -- Deploy IMDb app to Arc enabled K3d cluster +Deploy IMDb app to Arc-enabled K3d cluster: - ```bash +```bash - # start in the apps/imdb directory - cd $PIB_BASE/apps/imdb +# start in the apps/imdb directory +cd $PIB_BASE/apps/imdb - # deploy to central and west regions - flt targets add all - flt targets deploy +# deploy to central and west regions +flt targets add all +flt targets deploy - ``` +``` -- Wait for [ci-cd](https://github.com/kubernetes101/pib-dev/actions) to finish -- Force cluster to sync +Then wait for [ci-cd](https://github.com/kubernetes101/pib-dev/actions) to finish. - ```bash +You can force cluster to sync: + +```bash - # should see imdb added - git pull +# should see imdb added +git pull - # force flux to reconcile - flt sync +# force flux to reconcile +flt sync - ``` +``` ## Validate IMDb app on Azure Arc -- Get Azure Arc bearer token by running - `flt az arc-token` -- Login to Azure Portal and navigate to `Azure Arc` service -- Click on `Kubernetes clusters` from the left nav and select your cluster -- Click on `Workloads` from the left nav and place bearer token retrieved earlier -- Validate the IMDb app running on the cluster +You can get Azure Arc bearer token by running `flt az arc-token`. + +To check the app: + +- Login to Azure Portal and navigate to `Azure Arc` service. +- Click on `Kubernetes clusters` from the left navigation and select your cluster. +- Click on `Workloads` from the left navigation and place bearer token retrieved earlier. +- Validate the IMDb app running on the cluster. ## Delete Your Cluster -- Once you're finished with the workshop and experimenting, delete your cluster +Once you're finished with the workshop and experimenting, delete your cluster. - ```bash +```bash - # start in the root of your repo - cd $PIB_BASE - git pull +# start in the root of your repo +cd $PIB_BASE +git pull - # delete azure resource - flt delete $MY_CLUSTER +# delete azure resource +flt delete $MY_CLUSTER - # remove ips file - rm ips +# remove ips file +rm ips - # reset the targets - cd apps/imdb - flt targets clear - cd ../.. +# reset the targets +cd apps/imdb +flt targets clear +cd ../.. - # update the repo - git commit -am "deleted cluster" - git push +# update the repo +git commit -am "deleted cluster" +git push - ``` +``` diff --git a/labs/outer-loop-multi-cluster.md b/labs/outer-loop-multi-cluster.md index 50f70567..aa0a67dc 100644 --- a/labs/outer-loop-multi-cluster.md +++ b/labs/outer-loop-multi-cluster.md @@ -9,36 +9,35 @@ # the value can be overwritten if needed echo $MY_BRANCH -# make sure your branch is set and pushed remotely -# commands will fail if you are in main branch -git branch --show-current - ``` ## Login to Azure -- Login to Azure using `az login --use-device-code` - > Use `az login --use-device-code --tenant ` to specify a different tenant - - If you have more than one Azure subscription, select the correct subscription +Login to Azure using `az login --use-device-code`. + +Use `az login --use-device-code --tenant ` to specify a different tenant if you have access +to more than one tenant. + +If you have more than one Azure subscription, select the correct subscription: - ```bash +```bash - # verify your account - az account show +# verify your account +az account show - # list your Azure accounts - az account list -o table +# list your Azure accounts +az account list -o table - # set your Azure subscription - az account set -s mySubNameOrId +# set your Azure subscription +az account set -s mySubNameOrId - # verify your account - az account show +# verify your account +az account show - ``` +``` -- Validate user role on subscription - > Make sure your RoleDefinitionName is `Contributor` or `Owner` to create resources in this lab succssfully +Validate the user role on subscription. Make sure your RoleDefinitionName is `Contributor` or `Owner` +to create resources in this lab successfully. ```bash @@ -50,120 +49,111 @@ git branch --show-current ## Create 3 Clusters -- Use one Azure Resource Group -- Create a cluster in each region - - You can use different names as long as they are unique - - Standard Naming Format - - region (central, east, west) - - state - - city - - store_number - - ```bash +In one Azure Resource Group, create a cluster in three different regions. You can use different +names as long as they are unique. - # start in the base of the repo - cd $PIB_BASE +In our example we're using the following name format: +region (central, east, west), state, the branch name, and a "store number." - flt create \ - -g $MY_BRANCH-fleet \ - -c central-tx-$MY_BRANCH-1001 \ - -c east-ga-$MY_BRANCH-1001 \ - -c west-wa-$MY_BRANCH-1001 - - ``` +```bash -## Verifying the Clusters +# start in the base of the repo +cd $PIB_BASE -- Update Git Repo after [CI-CD](https://github.com/kubernetes101/pib-dev/actions) is complete (usually about 30 seconds) +flt create \ + -g $MY_BRANCH-fleet \ + -c central-tx-$MY_BRANCH-1001 \ + -c east-ga-$MY_BRANCH-1001 \ + -c west-wa-$MY_BRANCH-1001 - ```bash +``` - # update the git repo after ci-cd completes - git pull +## Verifying the Clusters - # add ips to repo - git add ips - git commit -am "added ips" - git push +Update Git Repo after [CI-CD](https://github.com/kubernetes101/pib-dev/actions) is complete. +This usually takes about 30 seconds. - ``` +```bash -- Verify clusters setup +# update the git repo after ci-cd completes +git pull - ```bash +# add ips to repo +git add ips +git commit -am "added ips" +git push - # check the setup for "complete" - # rerun as necessary - flt check setup +``` - ``` +Then verify the cluster's setup with `flt check setup`. Check the setup status for "complete", +and rerun as necessary. -- Check Heartbeat +You can check the heartbeat. - ```bash +```bash - # check that heartbeat is running on your cluster - flt check heartbeat +# check that heartbeat is running on your cluster +flt check heartbeat - # check heartbeat on clusters in specific region - flt check heartbeat --filter central +# check heartbeat on clusters in specific region +flt check heartbeat --filter central - ``` +``` ## IMDb Deployment -- By default, the IMDb app is not deployed to any clusters -- Experiment with different deployments +By default, the IMDb app is not deployed to any clusters. So now we can experiment with +different deployments! - ```bash +```bash - # start in the apps/imdb directory - cd $PIB_BASE/apps/imdb +# start in the apps/imdb directory +cd $PIB_BASE/apps/imdb - # deploy to central and west regions - flt targets add region:central region:west - flt targets deploy +# deploy to central and west regions +flt targets add region:central region:west +flt targets deploy - # wait for ci-cd to complete and update the cluster - git pull - flt sync +# wait for ci-cd to complete and update the cluster +git pull +flt sync - # check the cluster for imdb - flt check app imdb +# check the cluster for imdb +flt check app imdb - # deploy to just the east region - flt targets clear - flt targets add region:east - flt targets deploy +# deploy to just the east region +flt targets clear +flt targets add region:east +flt targets deploy - # wait for ci-cd to complete and update the repo - git pull - flt sync +# wait for ci-cd to complete and update the repo +git pull +flt sync - # check the cluster for imdb - flt check app imdb +# check the cluster for imdb +flt check app imdb - # deploy to all clusters - flt targets clear - flt targets add all - flt targets deploy +# deploy to all clusters +flt targets clear +flt targets add all +flt targets deploy - # wait for ci-cd to complete and update the repo - git pull - flt sync +# wait for ci-cd to complete and update the repo +git pull +flt sync - # check the cluster for imdb - flt check app imdb +# check the cluster for imdb +flt check app imdb - ``` +``` ## Deploy Dogs-Cats App -- Dogs and cats app is a simple "voting" app for demo purposes - - Note that dogs-cats and IMDb cannot be deployed to the same cluster due to ingress conflicts - - In a production environment, you would add ingress rules for host, url, or port based routing +The "Dogs and Cats" app is a simple "voting" app for demo purposes. + +> Note here that dogs-cats and IMDb cannot be deployed to the same cluster due to ingress conflicts. -> Start in the apps/imdb directory +In a production environment, you would add ingress rules for host, url, or port-based routing. ```bash @@ -194,7 +184,7 @@ flt curl /version ## Clean Up -- Once you are finished with the workshop, you can delete your Azure resources +Once you are finished with the workshop, you can delete your Azure resources. ```bash diff --git a/labs/outer-loop-ring-deployment.md b/labs/outer-loop-ring-deployment.md index 121cec96..aa0a67dc 100644 --- a/labs/outer-loop-ring-deployment.md +++ b/labs/outer-loop-ring-deployment.md @@ -1,10 +1,4 @@ -# PiB outer-loop with Ring Based Deployment - -- PiB includes `GitOps Automation` that uses `cluster metadata` for targeted deployments -- In this lab we will - - Create the GitOps structure for 15 clusters - - Add `ring` metadata to each cluster - - Add targets based on cluster metadata +# PiB Outer-Loop Multi-Cluster ## Validate cluster identifier and working branch @@ -15,132 +9,182 @@ # the value can be overwritten if needed echo $MY_BRANCH -# make sure your branch is set and pushed remotely -# commands will fail if you are in main branch -git branch --show-current - ``` -## Create 15 Clusters +## Login to Azure + +Login to Azure using `az login --use-device-code`. + +Use `az login --use-device-code --tenant ` to specify a different tenant if you have access +to more than one tenant. + +If you have more than one Azure subscription, select the correct subscription: + +```bash + +# verify your account +az account show -> Note: we don't actually create the clusters, just the GitOps folders +# list your Azure accounts +az account list -o table + +# set your Azure subscription +az account set -s mySubNameOrId + +# verify your account +az account show + +``` + +Validate the user role on subscription. Make sure your RoleDefinitionName is `Contributor` or `Owner` +to create resources in this lab successfully. ```bash - # start in the base of the repo - cd $PIB_BASE - - flt create \ - --gitops-only \ - -g $MY_BRANCH-fleet \ - -c central-tx-atx-101 \ - -c central-tx-dal-101 \ - -c central-tx-hou-101 \ - -c central-tx-ftw-101 \ - -c central-tx-san-101 \ - -c east-ga-atl-101 \ - -c east-fl-mia-101 \ - -c east-al-bham-101 \ - -c east-ms-bil-101 \ - -c east-nc-clt-101 \ - -c west-wa-sea-101 \ - -c west-nv-lv-101 \ - -c west-ca-sd-101 \ - -c west-or-pdx-101 \ - -c west-mt-bose-101 + # get az user name and validate your role assignment + principal_name=$(az account show --query "user.name" --output tsv | sed -r 's/[@]+/_/g') + az role assignment list --query "[].{principalName:principalName, roleDefinitionName:roleDefinitionName, scope:scope} | [? contains(principalName,'$principal_name')]" -o table ``` -## Cluster Metadata Files +## Create 3 Clusters - ```bash +In one Azure Resource Group, create a cluster in three different regions. You can use different +names as long as they are unique. - ls -alF clusters/*.yaml +In our example we're using the following name format: +region (central, east, west), state, the branch name, and a "store number." - cat clusters/central-tx-atx-101.yaml +```bash - ``` +# start in the base of the repo +cd $PIB_BASE -## Update Git Repo +flt create \ + -g $MY_BRANCH-fleet \ + -c central-tx-$MY_BRANCH-1001 \ + -c east-ga-$MY_BRANCH-1001 \ + -c west-wa-$MY_BRANCH-1001 -- `flt create` generates GitOps files for the cluster -- [CI-CD](https://github.com/kubernetes101/pib-dev/actions) generates the deployment manifests - - Wait for CI-CD to complete (usually about 30 seconds) +``` - ```bash +## Verifying the Clusters - # update the git repo after ci-cd completes - git pull +Update Git Repo after [CI-CD](https://github.com/kubernetes101/pib-dev/actions) is complete. +This usually takes about 30 seconds. - ``` +```bash -## Add Metadata to Clusters +# update the git repo after ci-cd completes +git pull + +# add ips to repo +git add ips +git commit -am "added ips" +git push + +``` + +Then verify the cluster's setup with `flt check setup`. Check the setup status for "complete", +and rerun as necessary. + +You can check the heartbeat. ```bash -echo "ring: 0" >> clusters/central-tx-atx-101.yaml -echo "ring: 1" >> clusters/central-tx-dal-101.yaml -echo "ring: 2" >> clusters/central-tx-ftw-101.yaml -echo "ring: 3" >> clusters/central-tx-hou-101.yaml -echo "ring: 4" >> clusters/central-tx-san-101.yaml -echo "ring: 0" >> clusters/east-al-bham-101.yaml -echo "ring: 1" >> clusters/east-fl-mia-101.yaml -echo "ring: 2" >> clusters/east-ga-atl-101.yaml -echo "ring: 3" >> clusters/east-ms-bil-101.yaml -echo "ring: 4" >> clusters/east-nc-clt-101.yaml -echo "ring: 0" >> clusters/west-ca-sd-101.yaml -echo "ring: 1" >> clusters/west-mt-bose-101.yaml -echo "ring: 2" >> clusters/west-nv-lv-101.yaml -echo "ring: 3" >> clusters/west-or-pdx-101.yaml -echo "ring: 4" >> clusters/west-wa-sea-101.yaml - -git add clusters +# check that heartbeat is running on your cluster +flt check heartbeat + +# check heartbeat on clusters in specific region +flt check heartbeat --filter central ``` -## Deploy IMDb to ring:0 +## IMDb Deployment + +By default, the IMDb app is not deployed to any clusters. So now we can experiment with +different deployments! ```bash +# start in the apps/imdb directory cd $PIB_BASE/apps/imdb -flt targets clear -flt targets add ring:0 + +# deploy to central and west regions +flt targets add region:central region:west flt targets deploy -# wait for ci-cd to finish +# wait for ci-cd to complete and update the cluster git pull +flt sync -``` +# check the cluster for imdb +flt check app imdb -## Add ring:1 +# deploy to just the east region +flt targets clear +flt targets add region:east +flt targets deploy -```bash +# wait for ci-cd to complete and update the repo +git pull +flt sync -cd $PIB_BASE/apps/imdb -flt targets add ring:1 +# check the cluster for imdb +flt check app imdb + +# deploy to all clusters +flt targets clear +flt targets add all flt targets deploy -# wait for ci-cd to finish +# wait for ci-cd to complete and update the repo git pull +flt sync + +# check the cluster for imdb +flt check app imdb ``` -## Add Central Region +## Deploy Dogs-Cats App + +The "Dogs and Cats" app is a simple "voting" app for demo purposes. + +> Note here that dogs-cats and IMDb cannot be deployed to the same cluster due to ingress conflicts. + +In a production environment, you would add ingress rules for host, url, or port-based routing. ```bash +# start in the apps/imdb directory cd $PIB_BASE/apps/imdb + +# deploy IMDb to the central region +flt targets clear flt targets add region:central + +cd ../dogs-cats + +# deploy dogs-cats to the west region +flt targets clear +flt targets add region:west flt targets deploy -# wait for ci-cd to finish +# wait for ci-cd to complete and update the repo git pull +flt sync + +# check apps on cluster +flt check app imdb +flt check app dogs +flt curl /version ``` ## Clean Up -- Once you are finished with the workshop, you can delete your GitOps resources +Once you are finished with the workshop, you can delete your Azure resources. ```bash @@ -148,21 +192,24 @@ git pull cd $PIB_BASE git pull -# restore the clusters dir from main -git restore -s main clusters -git add . +# delete the Azure resources +flt delete central-tx-$MY_BRANCH-1001 +flt delete east-ga-$MY_BRANCH-1001 +flt delete west-wa-$MY_BRANCH-1001 +flt delete $MY_BRANCH-fleet + +# remove ips file +rm -f ips -# clear imdb targets +# reset the targets cd apps/imdb flt targets clear - -# clear dogs-cats targets cd ../dogs-cats flt targets clear - -# push changes -flt targets deploy - cd ../.. +# update the repo +git commit -am "deleted fleet" +git push + ``` diff --git a/labs/outer-loop.md b/labs/outer-loop.md index 4ca5b505..575c7594 100644 --- a/labs/outer-loop.md +++ b/labs/outer-loop.md @@ -2,27 +2,33 @@ ## Introduction -- As part of PiB, we have automated the creation of `dev/test clusters` using a repeatable, consistent, Infrastructure as Code approach -- PiB ships a separate CLI (`flt`) for outer-loop dev/test clusters -- The dev/test clusters run `k3d` in an `Azure VM` -- `flt` connects to the dev/test VMs via SSH -- Access to the dev/test fleet can be shared between Codespaces and users - - We have an advanced workshop under development for fleet sharing +As part of PiB, we have automated the creation of dev/test clusters using a repeatable, +consistent, Infrastructure as Code approach. PiB ships a separate CLI (`flt`) for `outer-loop` dev/test +clusters. -![images](./images/outer-loop..drawio.png) +The clusters run `k3d` in an Azure Virtual Machine (VM). `flt` connects to the dev/test VMs via SSH. +Access to the dev/test fleet can be shared between Codespaces and users. -## flt CLI +We have an advanced workshop under development for fleet sharing! Keep your eyes out. -- `flt` encapsulates many of the hard concepts of K8s for the application developer, tester, and ops team -- A design requirement is that `flt` can't have any "magic" - - Anything you can do with `flt`, you can do using standard K8s tools -- `flt` has rich tab completion -- `flt` is `context aware` - - Running `flt list` will return Error: unknown command "list" for "flt" -- The `flt CLI` is customizable and extensible - - We have a workshop under development as an advanced scenario +![A diagram with a simplified fleet diagram. TODO: This diagram could be clearer.](./images/outer-loop.png) -## Experiment with the `flt CLI` +## `flt` CLI + +`flt` encapsulates many of the hard concepts of kubernetes (K8s) for the application developer, +tester, and ops team. A design requirement is that `flt` can't have any "magic." Anything you can +do with `flt`, you can do using standard K8s tools. + +`flt` has rich tab completion and is "context aware"; that is, depending on your location in the +directory structure and what you have already run, different commands will be available to you. + +Running `flt list` will return `Error: unknown command "list" for "flt"` when you first start, since +no fleets exist yet. TODO: CONFIRM THIS + +The `flt` CLI is customizable and extensible - we have a workshop under development as an advanced +scenario! Keep an eye out! + +## Experiment with the `flt` CLI ```bash @@ -55,36 +61,39 @@ git branch --show-current ## Login to Azure -- Login to Azure using `az login --use-device-code` - > Use `az login --use-device-code --tenant ` to specify a different tenant - - If you have more than one Azure subscription, select the correct subscription +Login to Azure using `az login --use-device-code`. - ```bash +Use `az login --use-device-code --tenant ` to specify a different tenant if you have access +to more than one tenant. - # verify your account - az account show +If you have more than one Azure subscription, select the correct subscription: - # list your Azure accounts - az account list -o table +```bash - # set your Azure subscription - az account set -s mySubNameOrId +# verify your account +az account show - # verify your account - az account show +# list your Azure accounts +az account list -o table - ``` +# set your Azure subscription +az account set -s mySubNameOrId -- Validate user role on subscription - > Make sure your RoleDefinitionName is `Contributor` or `Owner` to create resources in this lab succssfully +# verify your account +az account show - ```bash +``` - # get az user name and validate your role assignment - principal_name=$(az account show --query "user.name" --output tsv | sed -r 's/[@]+/_/g') - az role assignment list --query "[].{principalName:principalName, roleDefinitionName:roleDefinitionName, scope:scope} | [? contains(principalName,'$principal_name')]" -o table +Validate the user role on the subscription, and make sure your RoleDefinitionName is `Contributor` +or `Owner` to create resources in this lab successfully. - ``` +```bash + +# get az user name and validate your role assignment +principal_name=$(az account show --query "user.name" --output tsv | sed -r 's/[@]+/_/g') +az role assignment list --query "[].{principalName:principalName, roleDefinitionName:roleDefinitionName, scope:scope} | [? contains(principalName,'$principal_name')]" -o table + +``` ## Create a Dev Cluster @@ -101,9 +110,10 @@ flt create cluster -c $MY_CLUSTER ## Update Git Repo -- `flt create` generates GitOps files for the cluster -- [CI-CD](https://github.com/kubernetes101/pib-dev/actions) generates the deployment manifests - - Wait for CI-CD to complete (usually about 30 seconds) +`flt create` generates GitOps files for the cluster. + +A GitHub action [CI-CD](https://github.com/kubernetes101/pib-dev/actions) generates the deployment +manifests. You will need to wait for CI-CD to complete, which usually takes about 30 seconds. ```bash @@ -119,12 +129,11 @@ git push ## Verify the Cluster Setup -> If you get an SSH error, just retry every few seconds for the SSHD server to configure and start +> If you get an SSH error, just retry every few seconds for the SSHD server to configure and start. -- `flt create` creates the Azure VM that hosts the k3d cluster -- Additional setup is done via the `cloud-init` script -- We have to wait for the k3d setup to complete - - This usually takes 3-4 minutes after VM setup completes +`flt create` creates the Azure VM that hosts the `k3d` cluster. Any additional setup is done via the +`cloud-init` script. We have to wait for the `k3d` setup to complete, which usually takes 3-4 minutes +after the VM setup completes. ```bash @@ -140,9 +149,8 @@ watch flt check setup ## Force GitOps to Sync -- We use Flux v2 for GitOps -- Flux synchs on a schedule (1 minute) -- We can force Flux to sync (reconcile) immediately at any time +We use Flux v2 for GitOps. Flux syncs on a schedule of 1 minute. We can force Flux to sync (reconcile) +immediately at any time. ```bash @@ -156,11 +164,10 @@ flt check flux ## Check Heartbeat -- We deploy the `heartbeat` app to the cluster for observability -- Check the heartbeat status - - Note that heartbeat uses Let's Encrypt for ingress - - It can take up to 60 seconds for the Let's Encrypt handshake to complete - - It's normal to get a `no healthy upstream` error until the handshake is completed +We deploy the `heartbeat` app to the cluster for observability. We check the heartbeat status and +note that heartbeat uses "Let's Encrypt" for ingress. It can take up to 60 seconds for the "Let's +Encrypt" handshake to complete. It's normal to get a `no healthy upstream` error until the handshake +is completed. ```bash @@ -174,15 +181,17 @@ flt curl /heartbeat/17 ## Deploy Reference App -- PiB provides a reference application - IMDb - - dotnet WebAPI that exposes actors, genres, and movies from a subset of the IMDb data set -- `flt` provides `GitOps Automation` for the dev/test fleet -- The `flt targets` commands control which clusters an app is deployed to - - `flt targets` is context aware, so the current directory matters -- `flt targets` can use any KV pair defined in the cluster metadata - - `flt targets add all` is a special case that deploys to all clusters in the fleet (which is 1 for this lab) - - Note that the `all` target must be the only target specified - - An advanced workshop demonstrating `ring based deployment` is under development +PiB provides a reference application IMDB, which is a dotnet WebAPI that exposes actors, genres, +and movies from a subset of the IMDb data set. + +`flt` provides GitOps Automation for the dev/test fleet. The `flt targets` commands control which +clusters an app is deployed to. `flt targets` is context aware, so the current directory matters! +The command can use any KV pair defined in the cluster metadata too. + +`flt targets add all` is a special case that deploys to all clusters in the fleet (which is one fleet +for this lab). Note that the `all` target must be the only target specified. + +An advanced workshop demonstrating `ring based deployment` can be found [here](outer-loop-ring-deployment.md). ```bash @@ -211,14 +220,13 @@ flt targets deploy ``` -## Wait for ci-cd to finish +## Wait for `ci-cd` to finish -- Check [ci-cd status](https://github.com/kubernetes101/pib-dev/actions) +Check on the [ci-cd status](https://github.com/kubernetes101/pib-dev/actions). ## Update Cluster -- Force the cluster to sync -- Update local git repo +Force the cluster to sync and then update the local git repo. ```bash @@ -232,7 +240,7 @@ flt sync ## Verify IMDb was Deployed -- You may have to retry the command a few times as the pods start +> You may have to retry the command a few times as the pods start. ```bash @@ -243,60 +251,61 @@ flt check app imdb ## Curl an IMDb URL -- Note that IMDb uses Let's Encrypt for ingress - - It can take up to 60 seconds for the Let's Encrypt handshake to complete - - It's normal to get a `no healthy upstream` error until the handshake is completed +Note that IMDb uses "Let's Encrypt" for ingress. It can take up to 60 seconds for the "Let's Encrypt" +handshake to complete. It's normal to get a `no healthy upstream` error until the handshake is +completed. - ```bash +```bash - flt curl /version +flt curl /version - # curl additional URLs - flt curl /healthz - flt curl /readyz - flt curl /api/genres - flt curl /metrics +# curl additional URLs +flt curl /healthz +flt curl /readyz +flt curl /api/genres +flt curl /metrics - ``` +``` ## Test DNS Integration -- Use http to test your external DNS name +Use `http` to test your external DNS name. - ```bash +```bash - # export MY_IP - cd $PIB_BASE - export MY_IP=$(cat ips | cut -f2) +# export MY_IP +cd $PIB_BASE +export MY_IP=$(cat ips | cut -f2) - http http://$MY_IP/version +http http://$MY_IP/version - http http://$MY_IP/api/genres +http http://$MY_IP/api/genres - ``` +``` ## Delete Your Cluster -- Once you're finished with the workshop and experimenting, delete your cluster +Once you're finished with the workshop and experimenting, delete your cluster. - ```bash +```bash - # start in the root of your repo - cd $PIB_BASE - git pull - flt delete $MY_CLUSTER - rm ips - git commit -am "deleted cluster" - git push +# start in the root of your repo +cd $PIB_BASE +git pull +flt delete $MY_CLUSTER +rm ips +git commit -am "deleted cluster" +git push + +``` - ``` +You can recreate your cluster at any time. -- You can recreate your cluster at any time - - Note that to reuse the same name, you have to wait for the Azure RG to delete +> To reuse the same name, you have to wait for the Azure resource group to delete. - ```bash +```bash - # you should see your RG in the "deleting" state - flt az groups +# you should see your RG in the "deleting" state +flt az groups - ``` +```