|
6 | 6 | # Run `az login` at least once BEFORE running this script |
7 | 7 | # |
8 | 8 |
|
9 | | -from subprocess import check_output, CalledProcessError, STDOUT, Popen, PIPE |
| 9 | +from subprocess import check_output, CalledProcessError, STDOUT, Popen, PIPE, getoutput |
| 10 | +from time import sleep |
10 | 11 | import os |
11 | 12 | import getpass |
| 13 | +import json |
12 | 14 |
|
13 | 15 | def executeCmd (cmd): |
14 | 16 | if os.name=="nt": |
@@ -57,16 +59,27 @@ def executeCmd (cmd): |
57 | 59 | # os.environ['DOCKER_PASSWORD']=DOCKER_PASSWORD |
58 | 60 | os.environ['ACCEPT_EULA']="Yes" |
59 | 61 |
|
60 | | -print ("Set azure context to subcription: "+SUBSCRIPTION_ID) |
| 62 | +print ("Set azure context to subscription: "+SUBSCRIPTION_ID) |
61 | 63 | command = "az account set -s "+ SUBSCRIPTION_ID |
62 | 64 | executeCmd (command) |
63 | 65 |
|
64 | 66 | print ("Creating azure resource group: "+GROUP_NAME) |
65 | 67 | command="az group create --name "+GROUP_NAME+" --location "+AZURE_REGION |
66 | 68 | executeCmd (command) |
67 | 69 |
|
| 70 | +SP_NAME = AZURE_REGION + '_' + GROUP_NAME + '_' + CLUSTER_NAME |
| 71 | +print ("Creating Service Principal: "+SP_NAME) |
| 72 | +command = "az ad sp create-for-rbac --skip-assignment --name http://" + SP_NAME |
| 73 | +SP_RESULT=getoutput(command) |
| 74 | +SP_JSON = json.loads(SP_RESULT[SP_RESULT.find("{"):]) |
| 75 | +SP_PRINCIPAL = (SP_JSON['appId']) |
| 76 | +SP_PW = (SP_JSON['password']) |
| 77 | + |
| 78 | +# Waiting for 10 seconds for the SP to sync |
| 79 | +sleep(10) |
| 80 | + |
68 | 81 | print("Creating AKS cluster: "+CLUSTER_NAME) |
69 | | -command = "az aks create --name "+CLUSTER_NAME+" --resource-group "+GROUP_NAME+" --generate-ssh-keys --node-vm-size "+VM_SIZE+" --node-count "+AKS_NODE_COUNT |
| 82 | +command = "az aks create --name "+CLUSTER_NAME+" --resource-group "+GROUP_NAME+" --generate-ssh-keys --node-vm-size "+VM_SIZE+" --node-count "+AKS_NODE_COUNT+ " --service-principal " + SP_PRINCIPAL + " --client-secret " + SP_PW |
70 | 83 | executeCmd (command) |
71 | 84 |
|
72 | 85 | command = "az aks get-credentials --overwrite-existing --name "+CLUSTER_NAME+" --resource-group "+GROUP_NAME+" --admin" |
|
0 commit comments