Skip to content

Instantly share code, notes, and snippets.

@noelbundick
Last active June 3, 2018 16:59
Show Gist options
  • Select an option

  • Save noelbundick/6ec32af1cb7356187d0ee032fb161a05 to your computer and use it in GitHub Desktop.

Select an option

Save noelbundick/6ec32af1cb7356187d0ee032fb161a05 to your computer and use it in GitHub Desktop.
aks-custom-vnet

How to create an AKS cluster in a custom vnet

This uses properties directly from the REST API documentation to create a managed Kubernetes cluster in a preexisting VNET

WARNING

AKS is still in preview and this functionality isn't officially supported yet as of 2018-02-27. But this does seem to work! Expect things to break!

If you're reading this from the future - Howdy! I'd encourage you to check out the official docs at https://docs.microsoft.com/en-us/azure/aks instead of this quick template hack

# Create a VNET
az group create -n my-vnet-rg
az network vnet create -g my-vnet-rg -n customvnet --address-prefix 10.0.0.0/16 --subnet-name customsubnet --subnet-prefix 10.0.0.0/24
# Get the subnet resource id
az network vnet subnet show -n customsubnet --vnet-name customvnet -g my-vnet-rg --query 'id'
# Create a Service Principal for AKS
az ad sp create-for-rbac
# Fill out the template
# * agentPoolProfiles.vnetSubnetID
# * linuxProfile.ssh.publicKeys[0].keyData
# * servicePrincipalProfile.clientId
# * servicePrincipalProfile.secret
# Create an AKS cluster
az group create -n aks -l eastus
az group deployment create -g aks --template-file template.json
# Create a routes for pod networking
az network route-table create -n k8s-routetable -g my-vnet-rg
az network route-table route create -n pods -g my-vnet-rg --route-table-name k8s-routetable --address-prefix 10.244.0.0/24 --next-hop-type VirtualAppliance --next-hop-ip-address 10.0.0.4
az network vnet subnet update -n customsubnet --vnet-name customvnet -g my-vnet-rg --route-table k8s-routetable
MIT License
Copyright (c) 2018 Noel Bundick
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "0.1.0.0",
"parameters": {},
"variables": {},
"resources": [
{
"type": "Microsoft.ContainerService/managedClusters",
"apiVersion": "2017-08-31",
"name": "custom-vnet-cluster",
"location": "[resourceGroup().location]",
"tags": {},
"properties": {
"kubernetesVersion": "1.8.7",
"dnsPrefix": "aks-custom-vnet",
"agentPoolProfiles": [
{
"name": "default",
"vmSize": "Standard_B2s",
"count": 1,
"vnetSubnetID": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/my-vnet-rg/providers/Microsoft.Network/virtualNetworks/customvnet/subnets/customsubnet"
}
],
"linuxProfile": {
"adminUsername": "azureuser",
"ssh": {
"publicKeys": [
{
"keyData": "ssh-rsa your-key-goes-here"
}
]
}
},
"servicePrincipalProfile": {
"clientId": "your-service-principal-appId",
"secret": "your-service-principal-password"
}
}
}
],
"outputs": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment