Created
November 9, 2020 22:03
-
-
Save veyalla/07ce5b016714388d8c2551e01fa51ec1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"dnsLabelPrefix": { | |
"type": "string", | |
"metadata": { | |
"description": "Unique DNS Name for the Storage Account where the Virtual Machine's disks will be placed." | |
} | |
}, | |
"adminUsername": { | |
"type": "string", | |
"metadata": { | |
"description": "User name for the Virtual Machine." | |
} | |
}, | |
"deviceConnectionString": { | |
"type": "string", | |
"metadata": { | |
"description": "IoT Edge Device Connection String" | |
} | |
}, | |
"vmSize": { | |
"type": "string", | |
"defaultValue": "Standard_D2s_v3", | |
"metadata": { | |
"description": "VM size" | |
} | |
}, | |
"ubuntuOSVersion": { | |
"type": "string", | |
"defaultValue": "18.04-LTS", | |
"metadata": { | |
"description": "The Ubuntu version for the VM. This will pick a fully patched image of this given Ubuntu version." | |
} | |
}, | |
"location": { | |
"type": "string", | |
"defaultValue": "[resourceGroup().location]", | |
"metadata": { | |
"description": "Location for all resources." | |
} | |
}, | |
"authenticationType": { | |
"type": "string", | |
"defaultValue": "sshPublicKey", | |
"allowedValues": [ | |
"sshPublicKey", | |
"password" | |
], | |
"metadata": { | |
"description": "Type of authentication to use on the Virtual Machine. SSH key is recommended." | |
} | |
}, | |
"adminPasswordOrKey": { | |
"type": "securestring", | |
"metadata": { | |
"description": "SSH Key or password for the Virtual Machine. SSH key is recommended." | |
} | |
} | |
}, | |
"variables": { | |
"imagePublisher": "Canonical", | |
"imageOffer": "UbuntuServer", | |
"nicName": "[concat('nic-', uniquestring(parameters('dnsLabelPrefix')))]", | |
"vmName": "[parameters('dnsLabelPrefix')]", | |
"virtualNetworkName": "[concat('vnet-', uniquestring(parameters('dnsLabelPrefix')))]", | |
"publicIPAddressName": "[concat('ip-', parameters('dnsLabelPrefix'))]", | |
"addressPrefix": "10.0.0.0/16", | |
"subnet1Name": "[concat('subnet-', uniquestring(parameters('dnsLabelPrefix')))]", | |
"subnet1Prefix": "10.0.0.0/24", | |
"publicIPAddressType": "Dynamic", | |
"storageAccountType": "Standard_LRS", | |
"vnetID": "[resourceId('Microsoft.Network/virtualNetworks',variables('virtualNetworkName'))]", | |
"subnet1Ref": "[concat(variables('vnetID'),'/subnets/',variables('subnet1Name'))]", | |
"apiVersion": "2015-06-15", | |
"linuxConfiguration": { | |
"disablePasswordAuthentication": true, | |
"ssh": { | |
"publicKeys": [ | |
{ | |
"path": "[concat('/home/', parameters('adminUsername'), '/.ssh/authorized_keys')]", | |
"keyData": "[parameters('adminPasswordOrKey')]" | |
} | |
] | |
} | |
}, | |
"dcs": "[parameters('deviceConnectionString')]", | |
"user": "[parameters('adminUsername')]", | |
"networkSecurityGroupName": "[concat('nsg-', uniquestring(parameters('dnsLabelPrefix')))]" | |
}, | |
"resources": [ | |
{ | |
"apiVersion": "2015-06-15", | |
"type": "Microsoft.Network/publicIPAddresses", | |
"name": "[variables('publicIPAddressName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"publicIPAllocationMethod": "[variables('publicIPAddressType')]", | |
"dnsSettings": { | |
"domainNameLabel": "[parameters('dnsLabelPrefix')]" | |
} | |
} | |
}, | |
{ | |
"comments": "Default Network Security Group for template", | |
"type": "Microsoft.Network/networkSecurityGroups", | |
"apiVersion": "2019-08-01", | |
"name": "[variables('networkSecurityGroupName')]", | |
"location": "[parameters('location')]", | |
"properties": { | |
"securityRules": [ | |
{ | |
"name": "default-allow-22", | |
"properties": { | |
"priority": 1000, | |
"access": "Allow", | |
"direction": "Inbound", | |
"destinationPortRange": "22", | |
"protocol": "Tcp", | |
"sourceAddressPrefix": "*", | |
"sourcePortRange": "*", | |
"destinationAddressPrefix": "*" | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"apiVersion": "2015-06-15", | |
"type": "Microsoft.Network/virtualNetworks", | |
"name": "[variables('virtualNetworkName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" | |
], | |
"properties": { | |
"addressSpace": { | |
"addressPrefixes": [ | |
"[variables('addressPrefix')]" | |
] | |
}, | |
"subnets": [ | |
{ | |
"name": "[variables('subnet1Name')]", | |
"properties": { | |
"addressPrefix": "[variables('subnet1Prefix')]", | |
"networkSecurityGroup": { | |
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"apiVersion": "2015-06-15", | |
"type": "Microsoft.Network/networkInterfaces", | |
"name": "[variables('nicName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIPAddressName'))]", | |
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]" | |
], | |
"properties": { | |
"ipConfigurations": [ | |
{ | |
"name": "ipconfig1", | |
"properties": { | |
"privateIPAllocationMethod": "Dynamic", | |
"publicIPAddress": { | |
"id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]" | |
}, | |
"subnet": { | |
"id": "[variables('subnet1Ref')]" | |
} | |
} | |
} | |
] | |
} | |
}, | |
{ | |
"apiVersion": "2016-04-30-preview", | |
"type": "Microsoft.Compute/virtualMachines", | |
"name": "[variables('vmName')]", | |
"location": "[parameters('location')]", | |
"dependsOn": [ | |
"[concat('Microsoft.Network/networkInterfaces/', variables('nicName'))]" | |
], | |
"properties": { | |
"hardwareProfile": { | |
"vmSize": "[parameters('vmSize')]" | |
}, | |
"osProfile": { | |
"computerName": "[variables('vmName')]", | |
"adminUsername": "[parameters('adminUsername')]", | |
"adminPassword": "[parameters('adminPasswordOrKey')]", | |
"customData": "[base64(concat('#cloud-config\n\napt:\n preserve_sources_list: true\n sources:\n msft.list:\n source: \"deb https://packages.microsoft.com/ubuntu/18.04/multiarch/prod bionic main\"\n key: |\n -----BEGIN PGP PUBLIC KEY BLOCK-----\n Version: GnuPG v1.4.7 (GNU/Linux)\n\n mQENBFYxWIwBCADAKoZhZlJxGNGWzqV+1OG1xiQeoowKhssGAKvd+buXCGISZJwT\n LXZqIcIiLP7pqdcZWtE9bSc7yBY2MalDp9Liu0KekywQ6VVX1T72NPf5Ev6x6DLV\n 7aVWsCzUAF+eb7DC9fPuFLEdxmOEYoPjzrQ7cCnSV4JQxAqhU4T6OjbvRazGl3ag\n OeizPXmRljMtUUttHQZnRhtlzkmwIrUivbfFPD+fEoHJ1+uIdfOzZX8/oKHKLe2j\n H632kvsNzJFlROVvGLYAk2WRcLu+RjjggixhwiB+Mu/A8Tf4V6b+YppS44q8EvVr\n M+QvY7LNSOffSO6Slsy9oisGTdfE39nC7pVRABEBAAG0N01pY3Jvc29mdCAoUmVs\n ZWFzZSBzaWduaW5nKSA8Z3Bnc2VjdXJpdHlAbWljcm9zb2Z0LmNvbT6JATUEEwEC\n AB8FAlYxWIwCGwMGCwkIBwMCBBUCCAMDFgIBAh4BAheAAAoJEOs+lK2+EinPGpsH\n /32vKy29Hg51H9dfFJMx0/a/F+5vKeCeVqimvyTM04C+XENNuSbYZ3eRPHGHFLqe\n MNGxsfb7C7ZxEeW7J/vSzRgHxm7ZvESisUYRFq2sgkJ+HFERNrqfci45bdhmrUsy\n 7SWw9ybxdFOkuQoyKD3tBmiGfONQMlBaOMWdAsic965rvJsd5zYaZZFI1UwTkFXV\n KJt3bp3Ngn1vEYXwijGTa+FXz6GLHueJwF0I7ug34DgUkAFvAs8Hacr2DRYxL5RJ\n XdNgj4Jd2/g6T9InmWT0hASljur+dJnzNiNCkbn9KbX7J/qK1IbR8y560yRmFsU+\n NdCFTW7wY0Fb1fWJ+/KTsC4=\n =J6gs\n -----END PGP PUBLIC KEY BLOCK----- \npackages:\n - moby-cli\n - moby-engine\n - jq\n - unzip\n - tree\nruncmd:\n - |\n set -x\n (\n # Kubectl\n curl -LO https://storage.googleapis.com/kubernetes-release/release/v1.17.0/bin/linux/amd64/kubectl\n chmod +x ./kubectl\n sudo mv ./kubectl /usr/local/bin/kubectl\n alias k=''kubectl''\n\n # Install K9s (visual cluster explorer)\n wget https://github.com/derailed/k9s/releases/download/v0.15.2/k9s_Linux_x86_64.tar.gz\n tar xvf ./k9s_Linux_x86_64.tar.gz\n mv ./k9s /usr/local/bin/\n rm ./k9s_Linux_x86_64.tar.gz ./LICENSE ./README.md\n\n # Install Helm 3\n wget https://get.helm.sh/helm-v3.1.0-linux-amd64.tar.gz\n tar xvf ./helm-v3.1.0-linux-amd64.tar.gz\n mv ./linux-amd64/helm /usr/local/bin\n rm -rf ./linux-amd64/\n\n # Wait for docker daemon to start\n while [ $(ps -ef | grep -v grep | grep docker | wc -l) -le 0 ]; do \n sleep 3\n done\n\n # Download and bootstrap k3d cluster\n wget -q -O - https://raw.githubusercontent.com/rancher/k3d/master/install.sh | TAG=v1.6.0 bash\n k3d create -n k3s1 -w 2 --image rancher/k3s:v1.17.2-k3s1 --server-arg \"--no-deploy=traefik\"\n\n sleep 20\n\n # Set default KUBECONFIG\n mkdir /home/', variables('user'), '/.kube\n cat $(sudo k3d get-kubeconfig --name=''k3s1'') > /home/', variables('user'), '/.kube/config\n\n sleep 5\n\n # Install IoT Edge\n\n kubectl create ns helloworld --kubeconfig=/home/', variables('user'), '/.kube/config\n helm install --repo https://edgek8s.blob.core.windows.net/staging edge-crd edge-kubernetes-crd --kubeconfig=/home/', variables('user'), '/.kube/config\n helm install --repo https://edgek8s.blob.core.windows.net/staging edge1 edge-kubernetes --namespace helloworld --set \"provisioning.deviceConnectionString=', variables('dcs'), '\" --kubeconfig=/home/', variables('user'), '/.kube/config\n \n echo done\n ) &\n'))]", | |
"linuxConfiguration": "[if(equals(parameters('authenticationType'), 'password'), json('null'), variables('linuxConfiguration'))]" | |
}, | |
"storageProfile": { | |
"imageReference": { | |
"publisher": "[variables('imagePublisher')]", | |
"offer": "[variables('imageOffer')]", | |
"sku": "[parameters('ubuntuOSVersion')]", | |
"version": "latest" | |
}, | |
"osDisk": { | |
"createOption": "FromImage" | |
} | |
}, | |
"networkProfile": { | |
"networkInterfaces": [ | |
{ | |
"id": "[resourceId('Microsoft.Network/networkInterfaces',variables('nicName'))]" | |
} | |
] | |
} | |
} | |
} | |
], | |
"outputs": { | |
"Public SSH": { | |
"type": "string", | |
"value": "[concat('ssh -i ~/.ssh/id_k8s_lab ', reference(resourceId('Microsoft.Compute/virtualMachines', variables('vmName'))).osProfile.adminUsername, '@', reference(resourceId('Microsoft.Network/publicIPAddresses', variables('publicIPAddressName'))).dnsSettings.fqdn)]" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment