From 5b1b0fba9bbf4b9505cb58c21e4382ca0e249af8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ram=C3=B3n=20Tom=C3=A1s?= Date: Fri, 5 May 2017 09:41:22 +0200 Subject: [PATCH] Added script to set up azure environment before deploying kubernetes Updated deployment documentation --- README.k8s.md | 13 +++++++++++-- k8s/gen-k8s-env.ps1 | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 k8s/gen-k8s-env.ps1 diff --git a/README.k8s.md b/README.k8s.md index bb64e3018..28ebd49e8 100644 --- a/README.k8s.md +++ b/README.k8s.md @@ -2,8 +2,12 @@ The k8s directory contains Kubernetes configuration for the eShopOnContainers app and a PowerShell script to deploy it to a cluster. Each eShopOnContainers microservice has a deployment configuration in `deployments.yaml`, and is exposed to the cluster by a service in `services.yaml`. The microservices are exposed externally on individual routes (`/basket-api`, `/webmvc`, etc.) by an nginx reverse proxy specified in `frontend.yaml` and `nginx.conf`. ## Prerequisites -* A Kubernetes cluster. Follow Azure Container Service's [walkthrough](https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough) to create one. +* A Kubernetes cluster. Follow Azure Container Service's [walkthrough](https://docs.microsoft.com/en-us/azure/container-service/container-service-kubernetes-walkthrough) to create one. * A private Docker registry. Follow Azure Container Registry's [guide](https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal) to create one. +* Optionally, previous steps can be skipped if you run gen-k8s-env.ps1 script to automatically create the azure environment needed for kubernetes deployment. Azure cli 2.0 must be previously installed [installation guide](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli). For example: +>``` +>./gen-k8s-env -resourceGroupName k8sGroup -location westeurope -registryName k8sregistry -orchestratorName k8s-cluster -dnsName k8s-dns +>``` * A Docker development environment with `docker` and `docker-compose`. * Visit [docker.com](https://docker.com) to download the tools and set up the environment. Docker's [installation guide](https://docs.docker.com/engine/getstarted/step_one/#step-3-verify-your-installation) covers verifying your Docker installation. * The Kubernetes command line client, `kubectl`. @@ -12,7 +16,12 @@ The k8s directory contains Kubernetes configuration for the eShopOnContainers ap ## Deploy the application with the deployment script 1. Open a PowerShell command line at the `k8s` directory of your local eShopOnContainers repository. 1. Ensure `docker`, `docker-compose`, and `kubectl` are on the path, and configured for your Docker machine and Kubernetes cluster. -1. Run `deploy.ps1` with your registry information. The Docker username and password are provided by Azure Container Registry, and can be retrieved from the Azure portal. For example: +1. Run `deploy.ps1` with your registry information. The Docker username and password are provided by Azure Container Registry, and can be retrieved from the Azure portal. Optionally, ACR credentials can be obtained by running the following command: +>``` +>az acr credential show -n eshopregistry +>``` + +Once the user and password are retrieved, run the following script for deployment. For example: >``` >./deploy.ps1 -registry myregistry.azurecr.io -dockerUser User -dockerPassword SecretPassword >``` diff --git a/k8s/gen-k8s-env.ps1 b/k8s/gen-k8s-env.ps1 new file mode 100644 index 000000000..39dacba24 --- /dev/null +++ b/k8s/gen-k8s-env.ps1 @@ -0,0 +1,25 @@ +Param( + [parameter(Mandatory=$true)][string]$resourceGroupName, + [parameter(Mandatory=$true)][string]$location, + [parameter(Mandatory=$true)][string]$registryName, + [parameter(Mandatory=$true)][string]$orchestratorName, + [parameter(Mandatory=$true)][string]$dnsName +) + +# Create resource group +Write-Host "Creating resource group..." -ForegroundColor Yellow +az group create --name=$resourceGroupName --location=$location + +# Create Azure Container Registry +Write-Host "Creating Azure Container Registry..." -ForegroundColor Yellow +az acr create -n $registryName -g $resourceGroupName -l $location --admin-enabled true --sku Basic + +# Create kubernetes orchestrator +Write-Host "Creating kubernetes orchestrator..." -ForegroundColor Yellow +az acs create --orchestrator-type=kubernetes --resource-group $resourceGroupName --name=$orchestratorName --dns-prefix=$dnsName --generate-ssh-keys + +# Retrieve kubernetes cluster configuration and save it under ~/.kube/config +az acs kubernetes get-credentials --resource-group=$resourceGroupName --name=$orchestratorName + +# Show ACR credentials +az acr credential show -n $registryName \ No newline at end of file