Create Kubernetes Cluster in Azure

2017, Dec 01    


Azure has 2 container service offerings, ACS and AKS.
ACS was the first to be released, gives a choice of orchestrators but is little more than an ARM template with no management capability. These are some of the issues that AKS address. I’m confident that when AKS is Generally Available, ACS will become deprecated. Until that point however, i like to stay with the GA container service.

I have a shell script that creates my cluster with my optimal “cheapo” settings. Probably worth noting that this config is pretty slow, and not great at taking load tests – but hey, you get what you pay for.

I usually kick this off in the Azure Cloud Shell, and i pass in simply one parameter which is the name of the Resource Group.
The reason for the script is as follows.
1) I want to consistently add tags to my resource group for automation
2) I use a service principal to access Azure which has a much lower set of permissions. At point of creation i want it to automatically have Contributor access.
3) I want the cluster to be small, and sized to be cheap.
4) I want the ssh credentials zipped and ready for me to download to other clients to access the cluster. I do this partly so i can easily get away from the cloudshell and its aggressive timeouts. It’s probably worth saying that this is a sledgehammer approach, i could just go into the /.kube/ directory and copy out the specific kube config file.

Hope this proves useful

sh MyK8S
az group create --name $1 --location eastus2 --tag Environment=BlowMeUpAtMidnight
az role assignment create --role Contributor --resource-group $1 --assignee theobjectIdOfmyServicePrincipal
az acs create --orchestrator-type kubernetes --resource-group $1 --name $1Cluster --generate-ssh-keys --agent-count=1 --agent-vm-size=Standard_A1_v2 --master-vm-size=Standard_A1_v2
sleep 45
az acs kubernetes get-credentials --resource-group=$1 --name=$1Cluster 
zip -q -9 -j ~/clouddrive/sshkeys-$(date +%F).zip ~/.ssh/*