2016-09-29 12:22:00 +03:00
# Cloud Infrastructure Provisioning - Azure
2016-09-30 02:29:52 +03:00
This lab will walk you through provisioning the compute instances required for running a H/A Kubernetes cluster. A total of 10 virtual machines will be created.
The guide assumes you'll be creating resources in the `West Us` region as a single Azure Resource Manager resource group.
2016-10-02 02:09:16 +03:00
> All machines will be provisioned with fixed private IP addresses to simplify the bootstrap process.
2016-09-30 02:29:52 +03:00
2016-10-02 02:09:16 +03:00
The cluster VNs are only accessible via a jump box (a VM with publicly accessible ssh endpoint). The workers machines are exposed via external load balancer that carries both an public IP and public FQDN.
2016-09-30 02:29:52 +03:00
2016-09-29 12:22:00 +03:00
## Variables
2016-10-02 02:09:16 +03:00
Change the following values as needed.
2016-09-29 12:22:00 +03:00
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
# dns for jumpbox is <jumpboxDnsLabel>.westus.cloudapp.azure.com
2016-09-30 02:29:52 +03:00
jumpboxDnsLabel="the-hard-way-jumpbox"
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
# dns for workers is <workersDnsLabel>.westus.cloudapp.azure.com
2016-09-30 02:29:52 +03:00
workersDnsLabel="the-hard-way"
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
#storage account used by jumpbox + controllers + Etcd VMs
2016-09-30 22:44:38 +03:00
controlPlaneStorageAccount="thehardwaycsa"
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
2016-10-02 02:09:16 +03:00
```
2016-09-30 03:52:48 +03:00
#storage account used by workers VMs
2016-09-29 12:22:00 +03:00
workersStorageAccount="thehardwaywsa"
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
2016-10-02 02:09:16 +03:00
```
2016-09-29 12:22:00 +03:00
# all vms are using ubunut 16.4 LTS
imageUrn="Canonical:UbuntuServer:16.04.0-LTS:latest"
```
## Create Resource Group
```
azure group create \
--name the-hard-way \
--location "West Us"
```
## Networking
### Create Routing Table
```
azure network route-table create \
--resource-group the-hard-way \
--name the-hard-way-rtable \
--location "West Us"
```
### Create Network Security Group
```
azure network nsg create \
--resource-group the-hard-way \
--name the-hard-way-nsg \
--location "West Us"
```
2016-10-02 02:09:16 +03:00
Create NSG rule allowing SSH to the jumpbox
2016-09-29 12:22:00 +03:00
```
azure network nsg rule create \
--resource-group the-hard-way \
--nsg-name the-hard-way-nsg \
--name allow-ssh-jumpbox \
--protocol tcp \
--access allow \
2016-09-30 03:52:48 +03:00
--destination-address-prefix 10.0.0.5/32 \
2016-09-29 12:22:00 +03:00
--destination-port-range 22 \
--priority 100 \
--direction inbound
```
### Create VNET + Subnet
Cluster VNET
```
azure network vnet create \
--resource-group the-hard-way \
--name the-hard-way-net \
--address-prefixes 10.0.0.0/8 \
--location "West Us"
```
2016-10-02 02:09:16 +03:00
Create subnets
2016-09-29 12:22:00 +03:00
```
2016-10-02 02:09:16 +03:00
# Azure UDR routes traffic subnet's eggress
# workers & pod ips have to be 2 separate subnets
2016-10-02 01:40:07 +03:00
azure network vnet subnet create \
--resource-group the-hard-way \
--vnet-name the-hard-way-net \
--name kubernetes-mgmt \
--address-prefix 10.0.0.0/16
2016-09-29 12:22:00 +03:00
azure network vnet subnet create \
--resource-group the-hard-way \
--vnet-name the-hard-way-net \
--name kubernetes \
2016-10-02 01:40:07 +03:00
--address-prefix 10.239.0.0/11
2016-09-29 12:22:00 +03:00
```
2016-10-02 01:40:07 +03:00
Link routing table and NSG to Kubernetes/-mgmt subnets
2016-09-29 12:22:00 +03:00
```
2016-10-02 01:40:07 +03:00
azure network vnet subnet set \
--resource-group the-hard-way \
--vnet-name the-hard-way-net \
--name kubernetes-mgmt \
--network-security-group-name the-hard-way-nsg \
--route-table-name the-hard-way-rtable
2016-09-29 12:22:00 +03:00
azure network vnet subnet set \
--resource-group the-hard-way \
--vnet-name the-hard-way-net \
--name kubernetes \
--network-security-group-name the-hard-way-nsg \
2016-09-30 22:44:38 +03:00
--route-table-name the-hard-way-rtable
2016-09-29 12:22:00 +03:00
```
2016-10-02 01:40:07 +03:00
Create public IP + DNS label for the jumpbox
2016-09-29 12:22:00 +03:00
```
azure network public-ip create \
--resource-group the-hard-way \
--name the-hard-way-jumpbox \
2016-10-02 01:40:07 +03:00
--allocation-method Dynamic \
2016-09-29 12:22:00 +03:00
--domain-name-label $jumpboxDnsLabel \
--location "West Us"
```
## Virtual Machines
2016-10-02 02:09:16 +03:00
Create SSH keys (Used by All VMs)
2016-09-29 12:22:00 +03:00
```
mkdir keys
ssh-keygen -t rsa -f ./keys/cluster
```
### Storage Accounts
2016-09-30 00:49:08 +03:00
Create storage account for control plane VMs (Etcd & Controllers)
2016-09-29 12:22:00 +03:00
```
azure storage account create $controlPlaneStorageAccount \
--resource-group the-hard-way \
--kind storage \
--sku-name LRS \
--location "West Us"
```
2016-10-02 02:09:16 +03:00
Create storage account for workers VMs
2016-09-29 12:22:00 +03:00
```
azure storage account create $workersStorageAccount \
--resource-group the-hard-way \
--kind storage \
--sku-name LRS \
--location "West Us"
```
### Jump Box
2016-10-02 02:09:16 +03:00
#### Create Nic (Private IP + Public IP + FQDN)
2016-09-29 12:22:00 +03:00
```
azure network nic create \
--resource-group the-hard-way \
--name jumpbox-nic \
2016-09-30 00:49:08 +03:00
--private-ip-address "10.0.0.5" \
2016-09-29 12:22:00 +03:00
--subnet-vnet-name the-hard-way-net \
2016-10-02 01:40:07 +03:00
--subnet-name kubernetes-mgmt \
2016-09-29 12:22:00 +03:00
--public-ip-name the-hard-way-jumpbox \
--location "West Us"
```
#### Create VM
```
azure vm create \
--resource-group the-hard-way \
--name jumpbox \
--vm-size Standard_A1 \
--nic-name jumpbox-nic \
--vnet-name the-hard-way-net \
2016-10-02 01:40:07 +03:00
--vnet-subnet-name kubernetes-mgmt \
2016-09-29 12:22:00 +03:00
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd jumpbox.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
### Etcd
#### Etcd 0
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name etcd-0-nic \
--private-ip-address "10.240.0.10" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
2016-09-30 03:52:48 +03:00
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name etcd0 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name etcd-0-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd etcd-0.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Etcd 1
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name etcd-1-nic \
--private-ip-address "10.240.0.11" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
--location "West Us"
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name etcd1 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name etcd-1-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd etcd-1.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Etcd 2
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name etcd-2-nic \
--private-ip-address "10.240.0.12" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
2016-09-30 03:52:48 +03:00
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name etcd2 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name etcd-2-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd etcd-2.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
### Kubernetes Controllers
2016-09-30 00:49:08 +03:00
2016-09-30 22:44:38 +03:00
#### Controllers Internal Load Balancer
2016-09-30 00:49:08 +03:00
2016-10-02 02:09:16 +03:00
Create load balancer
2016-09-30 00:49:08 +03:00
```
azure network lb create \
--resource-group the-hard-way \
--name the-hard-way-clb \
--location "West Us"
```
2016-09-30 22:44:38 +03:00
Create & assign the front-end private IP to the internal load balancer
2016-09-30 00:49:08 +03:00
```
azure network lb frontend-ip create \
--resource-group the-hard-way \
--name the-hard-way-cfe \
--lb-name the-hard-way-clb \
2016-10-02 01:40:07 +03:00
--private-ip-address "10.240.0.4" \
2016-09-30 00:49:08 +03:00
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes
```
Create a backend address pool for the load balancer
```
clbbackendPoolId=$(azure network lb address-pool create \
--resource-group the-hard-way \
--lb-name the-hard-way-clb \
--name backend-pool \
--json | jq -r '.id')
```
2016-09-30 22:44:38 +03:00
#### Create controllers availability set
2016-09-30 00:49:08 +03:00
```
azure availset create \
--resource-group the-hard-way \
--name controllers-availset \
--location "West Us"
```
2016-09-29 12:22:00 +03:00
#### Controller 0
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name controller-0-nic \
--private-ip-address "10.240.0.20" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $clbbackendPoolId \
2016-09-29 12:22:00 +03:00
--location "West Us"
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name controller0 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name controller-0-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--availset-name controllers-availset \
2016-09-29 12:22:00 +03:00
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd controller-0.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Controller 1
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name controller-1-nic \
--private-ip-address "10.240.0.21" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $clbbackendPoolId \
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name controller1 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name controller-1-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--availset-name controllers-availset \
2016-09-29 12:22:00 +03:00
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd controller-1.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Controller 2
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name controller-2-nic \
--private-ip-address "10.240.0.22" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $clbbackendPoolId \
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name controller2 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-names controller-2-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
2016-09-30 00:49:08 +03:00
--availset-name controllers-availset \
2016-09-29 12:22:00 +03:00
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $controlPlaneStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd controller-2.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
### Kubernetes Workers
2016-09-30 00:49:08 +03:00
#### Workers External Load Balancer
2016-09-29 12:22:00 +03:00
2016-10-02 01:40:07 +03:00
Create public IP + DNS label for workers ingestion external load balancer
2016-09-29 12:22:00 +03:00
```
azure network public-ip create \
--resource-group the-hard-way \
--name the-hard-way-workers \
2016-10-02 01:40:07 +03:00
--allocation-method Dynamic \
2016-09-29 12:22:00 +03:00
--domain-name-label $workersDnsLabel \
--location "West Us"
```
Create load balancer
```
azure network lb create \
--resource-group the-hard-way \
--name the-hard-way-lb \
--location "West Us"
```
2016-10-02 02:09:16 +03:00
Assign the front-end public IP + FQDN to the load balancer
2016-09-29 12:22:00 +03:00
```
azure network lb frontend-ip create \
--resource-group the-hard-way \
--name the-hard-way-fe \
--lb-name the-hard-way-lb \
2016-10-02 01:40:07 +03:00
--public-ip-name the-hard-way-workers
2016-09-29 12:22:00 +03:00
```
Create a backend address pool for the load balancer
```
2016-09-30 00:49:08 +03:00
wlbbackendPoolId=$(azure network lb address-pool create \
2016-09-29 12:22:00 +03:00
--resource-group the-hard-way \
--lb-name the-hard-way-lb \
--name backend-pool \
--json | jq -r '.id')
```
#### Create Workers Availablity set
```
azure availset create \
--resource-group the-hard-way \
--name workers-availset \
--location "West Us"
```
#### Worker 0
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name worker-0-nic \
--private-ip-address "10.240.0.30" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
--enable-ip-forwarding "true" \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $wlbbackendPoolId \
2016-09-30 03:52:48 +03:00
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name worker0 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name worker-0-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--availset-name workers-availset \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $workersStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd worker-0.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Worker 1
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name worker-1-nic \
--private-ip-address "10.240.0.31" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
--enable-ip-forwarding "true" \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $wlbbackendPoolId \
2016-09-29 12:22:00 +03:00
--location "West Us"
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name worker1 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name worker-1-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--availset-name workers-availset \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $workersStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd worker-1.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
#### Worker 2
Create Nic
```
azure network nic create \
--resource-group the-hard-way \
--name worker-2-nic \
--private-ip-address "10.240.0.32" \
--subnet-vnet-name the-hard-way-net \
--subnet-name kubernetes \
--enable-ip-forwarding "true" \
2016-09-30 00:49:08 +03:00
--lb-address-pool-ids $wlbbackendPoolId \
--location "West Us"
2016-09-29 12:22:00 +03:00
```
Create VM
```
azure vm create \
--resource-group the-hard-way \
2016-09-30 05:04:01 +03:00
--name worker2 \
2016-09-29 12:22:00 +03:00
--vm-size Standard_D4 \
--nic-name worker-2-nic \
--vnet-name the-hard-way-net \
--vnet-subnet-name kubernetes \
--availset-name workers-availset \
--os-type linux \
--image-urn $imageUrn \
--storage-account-name $workersStorageAccount \
--storage-account-container-name vhds \
--os-disk-vhd worker-2.vhd \
--admin-username thehardway \
--ssh-publickey-file ./keys/cluster.pub \
--location "West US"
```
## Verify
```
azure vm list --resource-group the-hard-way
```
Expected Output
```
info: Executing command vm list
+ Getting virtual machines
data: ResourceGroupName Name ProvisioningState PowerState Location Size
data: ----------------- ------------ ----------------- ---------- -------- -----------
data: the-hard-way controller-0 Succeeded VM running westus Standard_D4
data: the-hard-way controller-1 Succeeded VM running westus Standard_D4
data: the-hard-way controller-2 Succeeded VM running westus Standard_D4
data: the-hard-way etcd-0 Succeeded VM running westus Standard_D4
data: the-hard-way etcd-1 Succeeded VM running westus Standard_D4
data: the-hard-way etcd-2 Succeeded VM running westus Standard_D4
data: the-hard-way jumpbox Succeeded VM running westus Standard_A1
data: the-hard-way worker-0 Succeeded VM running westus Standard_D4
data: the-hard-way worker-1 Succeeded VM running westus Standard_D4
data: the-hard-way worker-2 Succeeded VM running westus Standard_D4
info: vm list command OK
```
## Using The Jumpbox
### Connect to Jumpbox
```
ssh -i ./keys/cluster \
thehardway@$jumpboxDnsLabel.westus.cloudapp.azure.com
```
2016-10-02 02:09:16 +03:00
### Copy the cluster private key to jumpbox
2016-09-29 12:22:00 +03:00
```
scp -i ./keys/cluster \
./keys/cluster \
thehardway@$jumpboxDnsLabel.westus.cloudapp.azure.com:~/cluster
```
### Connecting to Other VMs
```
# on the jumpbox
#connect to the second controller
ssh -i ./cluster \
thehardway@10.240.0.31
#or
ssh -i ./cluster \
thehardway@controller-1
```