|
| 1 | +# Setup |
| 2 | + |
1 | 3 | ## Required Software:
|
2 | 4 |
|
3 | 5 | **Editor**: Visual Studio 2017 / Visual Studio Code
|
|
12 | 14 |
|
13 | 15 | **Minikube** (for local development): https://github.com/kubernetes/minikube
|
14 | 16 |
|
15 |
| -**Azure CLI 2.0** |
| 17 | +**Azure CLI 2.0** (can be run as [docker image](https://hub.docker.com/r/microsoft/azure-cli/)) |
| 18 | + |
| 19 | +## Concept of environments |
| 20 | + |
| 21 | +All the PS scripts have the mandatory `-EnvironmentTag` flag which needs to be set. This flag is one of the best practices when writing Infrastructure-as-Code scripts to be able to reuse same scripts between multiple environments. It also helps when multiple people are using the same scripts for their "local" environments so that they get no conflicts in the cloud (each has its own environment). |
| 22 | + |
| 23 | +Important here to know is: |
| 24 | +- choose a 2-4 letter [a-Z] tag which you want |
| 25 | +- provide the same tag to all the scripts you will be executing |
| 26 | + |
| 27 | +## Prerequisites |
| 28 | + |
| 29 | +This project can be run in two ways: |
| 30 | +- with a local cluster (e.g. minikube) while the PaaS components are in cloud (e.g. Event Hub) |
| 31 | +- completely in cloud (cluster with Azure Container Services) |
| 32 | + |
| 33 | +Depending whether you want local or cloud deployment, there are some small differences in setup. |
| 34 | + |
| 35 | +If you want to deploy the sample to Azure Container Services (cloud), you need to run the `Create-CloudClusterPrerequisites.ps1` script which should setup a KeyVault with deployment-time secrets (service principal, SSH Key, passwords and such) neccessary for Azure Container Services cluster to created. |
| 36 | + |
| 37 | +More info here: [Runnning Create-CloudClusterPrerequisites script](cloud-prerequisites.md) |
16 | 38 |
|
17 | 39 | ## Infrastructure Setup
|
18 | 40 |
|
19 |
| -For setting up the neccessary Azure Infrastructure (Infrastructure-as-Code) for the code to run, you can use the Create-Infrastructure.ps1 script. However, this script has a dependency on a Key Vault which should contain deployment-time secrets (service principal, SSH Key, passwords and such). |
| 41 | +For setting up the neccessary Azure Infrastructure (Infrastructure-as-Code) for the code to run, you can use the `Create-Infrastructure.ps1` script. |
| 42 | + |
| 43 | +First, make sure you log in to your Azure Subscription with |
| 44 | + |
| 45 | +```powershell |
| 46 | +Login-AzureRmAccount |
| 47 | +``` |
| 48 | + |
| 49 | +and, if necessary, switch to the correct subscription using |
| 50 | + |
| 51 | +```powershell |
| 52 | +# to find out the subscirption id, run Get-AzureRmSubscription |
| 53 | +Select-AzureRmSubscription |
| 54 | +``` |
| 55 | + |
| 56 | +You can execute the `Create-Infrastructure.ps1` script now. In case if you will be working with a local cluster (e.g. minikube), run the following: |
| 57 | + |
| 58 | +```powershell |
| 59 | +.\Create-Infrastructure.ps1 -EnvironmentTag <<set_tag_here>> -SkipCluster |
| 60 | +``` |
| 61 | + |
| 62 | +If you are going to be using a cloud cluster (ACS), omit the -SkipCluster flag. |
| 63 | + |
| 64 | +```powershell |
| 65 | +# make sure you execute the Create-CloudClusterPrerequisites.ps1 script first! |
| 66 | +# more info above in this document, or read cloud-prerequisites.md |
| 67 | +.\Create-Infrastructure.ps1 -EnvironmentTag <<your_tag_here>> |
| 68 | +``` |
| 69 | + |
| 70 | +Script should finish without any errors. |
20 | 71 |
|
21 |
| -To create such Key Vault with all required secrets, run the Create-Prerequisites.ps1 script. |
22 |
| -First, execute this like to securely enter your credentials for the service principal: |
| 72 | +## Initialize the cluster |
| 73 | + |
| 74 | +Before you start deploying the microservices, your cluster needs to be "initialized" first. What this actually means is that we need to write in a secret for private docker registry connections and that we need to initialize [Helm](https://helm.sh/) for doing the actual deployments. |
| 75 | + |
| 76 | +#### Local cluster |
| 77 | + |
| 78 | +If you already installed minikube and are planning to deploy locally, you can go ahead and run the script. |
| 79 | + |
| 80 | +```powershell |
| 81 | +.\Initialize-Cluster.ps1 -EnvironmentTag <<your_tag_here>> |
| 82 | +``` |
| 83 | + |
| 84 | +#### Cloud cluster |
| 85 | + |
| 86 | +If you are planning to use the cloud cluster (ACS), you need to configure your kubectl tool first. Easiest way to do this is through Azure CLI: |
| 87 | + |
| 88 | +```bash |
| 89 | +az acs kubernetes get-credentials --resource-group=... --name=... |
| 90 | +``` |
| 91 | + |
| 92 | +Afterwards, simple run the script: |
| 93 | + |
| 94 | +```powershell |
| 95 | +.\Initialize-Cluster.ps1 -EnvironmentTag <<your_tag_here>> |
| 96 | +``` |
| 97 | + |
| 98 | +#### Kubectl & contexts |
| 99 | + |
| 100 | +Important thing to realise here is that many of the tools like Helm and scripts you will be using in this project are supporting [Kubectl contexts](https://kubernetes.io/docs/tasks/access-application-cluster/authenticate-across-clusters-kubeconfig/) directly. One such context for your local cluster is setup when starting minikube, and the `az acs kubernetes get-credentials ... ` command above also sets up a context for your remote ACS cluster. |
| 101 | + |
| 102 | +## Building the containers |
| 103 | + |
| 104 | +**Short answer:** |
23 | 105 |
|
24 | 106 | ```powershell
|
25 |
| -$servicePrincipalCredentials = Get-Credential |
| 107 | +# builds all the containers and pushes them to a remove environment specific docker registry (ACR) |
| 108 | +.\Build-Containers.ps1 -EnvironmentTag <<your_tag_here>> |
26 | 109 | ```
|
27 | 110 |
|
28 |
| -Afterwards, you can execute the Create-Prerequisites.ps1 script itself: |
| 111 | +**Long answer:** |
| 112 | + |
| 113 | +One of the things that was setup in previous step, was a private Docker Registry in form of Azure Container Registry. For both scenarios, local and cloud, we will be using this registry to roll out the containers onto the Kubernetes cluster. |
| 114 | + |
| 115 | +Each of the microservices in this project has a Dockerfile which can be used out of the box and could do the classic docker build / docker tag / docker login / docker push if you wanted (or you can use something like [Draft](https://github.com/Azure/draft)) |
29 | 116 |
|
30 |
| -``` powershell |
31 |
| -.\Create-Prerequisites.ps1 -EnvironmentTag "white" -MachineSshPublicKey "ssh-rsa AAAA...6SkIQ0opBt" -ServicePrincipalCredentials $servicePrincipalCredentials |
| 117 | +## Deploying the application |
| 118 | + |
| 119 | +Simply use the Deploy-Application.ps1 script: |
| 120 | + |
| 121 | +```powershell |
| 122 | +# will use your current kubectl context for deployment target |
| 123 | +.\Deploy-Application.ps1 -EnvironmentTag <<your_tag_here>> |
32 | 124 | ```
|
33 | 125 |
|
34 |
| -Warning: make sure to delete the resources since they incure Azure costs! :) |
| 126 | +Once installed, you will be able to see the pods with `kubectl get pods`. |
| 127 | + |
| 128 | +`helm list` will also show you your new release. |
| 129 | + |
| 130 | +## Deleting the application |
| 131 | + |
| 132 | +Simply run `helm delete <<release_name>>` with the release name you got from `helm list`. |
0 commit comments