Skip to content

Commit 7a964ca

Browse files
committed
Added script to set up azure environment before deploying kubernetes
Updated deployment documentation
1 parent fa048c2 commit 7a964ca

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

README.k8s.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
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`.
33

44
## Prerequisites
5-
* 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.
5+
* 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.
66
* 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.
7+
* 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:
8+
>```
9+
>./gen-k8s-env -resourceGroupName k8sGroup -location westeurope -registryName k8sregistry -orchestratorName k8s-cluster -dnsName k8s-dns
10+
>```
711
* A Docker development environment with `docker` and `docker-compose`.
812
* 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.
913
* The Kubernetes command line client, `kubectl`.
@@ -12,7 +16,12 @@ The k8s directory contains Kubernetes configuration for the eShopOnContainers ap
1216
## Deploy the application with the deployment script
1317
1. Open a PowerShell command line at the `k8s` directory of your local eShopOnContainers repository.
1418
1. Ensure `docker`, `docker-compose`, and `kubectl` are on the path, and configured for your Docker machine and Kubernetes cluster.
15-
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:
19+
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:
20+
>```
21+
>az acr credential show -n eshopregistry
22+
>```
23+
24+
Once the user and password are retrieved, run the following script for deployment. For example:
1625
>```
1726
>./deploy.ps1 -registry myregistry.azurecr.io -dockerUser User -dockerPassword SecretPassword
1827
>```

k8s/gen-k8s-env.ps1

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Param(
2+
[parameter(Mandatory=$true)][string]$resourceGroupName,
3+
[parameter(Mandatory=$true)][string]$location,
4+
[parameter(Mandatory=$true)][string]$registryName,
5+
[parameter(Mandatory=$true)][string]$orchestratorName,
6+
[parameter(Mandatory=$true)][string]$dnsName
7+
)
8+
9+
# Create resource group
10+
Write-Host "Creating resource group..." -ForegroundColor Yellow
11+
az group create --name=$resourceGroupName --location=$location
12+
13+
# Create Azure Container Registry
14+
Write-Host "Creating Azure Container Registry..." -ForegroundColor Yellow
15+
az acr create -n $registryName -g $resourceGroupName -l $location --admin-enabled true --sku Basic
16+
17+
# Create kubernetes orchestrator
18+
Write-Host "Creating kubernetes orchestrator..." -ForegroundColor Yellow
19+
az acs create --orchestrator-type=kubernetes --resource-group $resourceGroupName --name=$orchestratorName --dns-prefix=$dnsName --generate-ssh-keys
20+
21+
# Retrieve kubernetes cluster configuration and save it under ~/.kube/config
22+
az acs kubernetes get-credentials --resource-group=$resourceGroupName --name=$orchestratorName
23+
24+
# Show ACR credentials
25+
az acr credential show -n $registryName

0 commit comments

Comments
 (0)