0

We have a kubernetes cluster running in our environment, I have used the export template option and got the json file.

But the template is not usable as it is having hard coded values of subscription and resoure ids.

Can anyone please suggest how to make it usable. I am completely new to azure ARM templates.

My template:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "resourceName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Managed Cluster resource."
            }
        },
        "location": {
            "type": "string",
            "metadata": {
                "description": "The location of AKS resource."
            }
        },
        "dnsPrefix": {
            "type": "string",
            "metadata": {
                "description": "Optional DNS prefix to use with hosted Kubernetes API server FQDN."
            }
        },
        "osDiskSizeGB": {
            "type": "int",
            "defaultValue": 0,
            "metadata": {
                "description": "Disk size (in GiB) to provision for each of the agent pool nodes. This value ranges from 0 to 1023. Specifying 0 will apply the default disk size for that agentVMSize."
            },
            "minValue": 0,
            "maxValue": 1023
        },
        "kubernetesVersion": {
            "type": "string",
            "defaultValue": "1.7.7",
            "metadata": {
                "description": "The version of Kubernetes."
            }
        },
        "networkPlugin": {
            "type": "string",
            "allowedValues": [
                "azure",
                "kubenet"
            ],
            "metadata": {
                "description": "Network plugin used for building Kubernetes network."
            }
        },
        "enableRBAC": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Boolean flag to turn on and off of RBAC."
            }
        },
        "vmssNodePool": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Boolean flag to turn on and off of virtual machine scale sets"
            }
        },
        "windowsProfile": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Boolean flag to turn on and off of virtual machine scale sets"
            }
        },
        "enablePrivateCluster": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Enable private network access to the Kubernetes cluster."
            }
        },
        "enableHttpApplicationRouting": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Boolean flag to turn on and off http application routing."
            }
        },
        "enableAzurePolicy": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Boolean flag to turn on and off Azure Policy addon."
            }
        },
        "enableOmsAgent": {
            "type": "bool",
            "defaultValue": true,
            "metadata": {
                "description": "Boolean flag to turn on and off omsagent addon."
            }
        },
        "workspaceRegion": {
            "type": "string",
            "defaultValue": "East US",
            "metadata": {
                "description": "Specify the region for your OMS workspace."
            }
        },
        "workspaceName": {
            "type": "string",
            "metadata": {
                "description": "Specify the name of the OMS workspace."
            }
        },
        "omsWorkspaceId": {
            "type": "string",
            "metadata": {
                "description": "Specify the resource id of the OMS workspace."
            }
        },
        "omsSku": {
            "type": "string",
            "defaultValue": "standalone",
            "allowedValues": [
                "free",
                "standalone",
                "pernode"
            ],
            "metadata": {
                "description": "Select the SKU for your workspace."
            }
        },
        "networkPolicy": {
            "type": "string",
            "metadata": {
                "description": "Network policy used for building Kubernetes network."
            }
        },
        "vnetSubnetID": {
            "type": "string",
            "metadata": {
                "description": "Resource ID of virtual network subnet used for nodes and/or pods IP assignment."
            }
        },
        "serviceCidr": {
            "type": "string",
            "metadata": {
                "description": "A CIDR notation IP range from which to assign service cluster IPs."
            }
        },
        "dnsServiceIP": {
            "type": "string",
            "metadata": {
                "description": "Containers DNS server IP address."
            }
        },
        "dockerBridgeCidr": {
            "type": "string",
            "metadata": {
                "description": "A CIDR notation IP for Docker bridge."
            }
        }
    },
    "resources": [
        {
            "apiVersion": "2021-02-01",
            "dependsOn": [
                "[concat('Microsoft.Resources/deployments/', 'WorkspaceDeployment-20211130231648')]",
                "Microsoft.Network/virtualNetworks/trst-vnet"
            ],
            "type": "Microsoft.ContainerService/managedClusters",
            "location": "[parameters('location')]",
            "name": "[parameters('resourceName')]",
            "properties": {
                "kubernetesVersion": "[parameters('kubernetesVersion')]",
                "enableRBAC": "[parameters('enableRBAC')]",
                "dnsPrefix": "[parameters('dnsPrefix')]",
                "agentPoolProfiles": [
                    {
                        "name": "agentpool",
                        "osDiskSizeGB": "[parameters('osDiskSizeGB')]",
                        "count": 1,
                        "enableAutoScaling": true,
                        "minCount": 1,
                        "maxCount": 2,
                        "vmSize": "Standard_B4ms",
                        "osType": "Linux",
                        "storageProfile": "ManagedDisks",
                        "type": "VirtualMachineScaleSets",
                        "mode": "System",
                        "maxPods": 110,
                        "availabilityZones": [
                            "1",
                            "2",
                            "3"
                        ],
                        "vnetSubnetID": "[parameters('vnetSubnetID')]"
                    }
                ],
                "networkProfile": {
                    "loadBalancerSku": "standard",
                    "networkPlugin": "[parameters('networkPlugin')]",
                    "networkPolicy": "[parameters('networkPolicy')]",
                    "serviceCidr": "[parameters('serviceCidr')]",
                    "dnsServiceIP": "[parameters('dnsServiceIP')]",
                    "dockerBridgeCidr": "[parameters('dockerBridgeCidr')]"
                },
                "apiServerAccessProfile": {
                    "enablePrivateCluster": "[parameters('enablePrivateCluster')]"
                },
                "addonProfiles": {
                    "httpApplicationRouting": {
                        "enabled": "[parameters('enableHttpApplicationRouting')]"
                    },
                    "azurepolicy": {
                        "enabled": "[parameters('enableAzurePolicy')]"
                    },
                    "omsAgent": {
                        "enabled": "[parameters('enableOmsAgent')]",
                        "config": {
                            "logAnalyticsWorkspaceResourceID": "[parameters('omsWorkspaceId')]"
                        }
                    }
                }
            },
            "tags": {
                "Owner": "ukreddy@erwin.com",
                "purpose": "automation of mart server"
            },
            "identity": {
                "type": "SystemAssigned"
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "name": "SolutionDeployment-20211130231648",
            "apiVersion": "2017-05-10",
            "resourceGroup": "[split(parameters('omsWorkspaceId'),'/')[4]]",
            "subscriptionId": "[split(parameters('omsWorkspaceId'),'/')[2]]",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2015-11-01-preview",
                            "type": "Microsoft.OperationsManagement/solutions",
                            "location": "[parameters('workspaceRegion')]",
                            "name": "[concat('ContainerInsights', '(', split(parameters('omsWorkspaceId'),'/')[8], ')')]",
                            "properties": {
                                "workspaceResourceId": "[parameters('omsWorkspaceId')]"
                            },
                            "plan": {
                                "name": "[concat('ContainerInsights', '(', split(parameters('omsWorkspaceId'),'/')[8], ')')]",
                                "product": "[concat('OMSGallery/', 'ContainerInsights')]",
                                "promotionCode": "",
                                "publisher": "Microsoft"
                            }
                        }
                    ]
                }
            },
            "dependsOn": [
                "[concat('Microsoft.Resources/deployments/', 'WorkspaceDeployment-20211130231648')]"
            ]
        },
        {
            "type": "Microsoft.Resources/deployments",
            "name": "WorkspaceDeployment-20211130231648",
            "apiVersion": "2017-05-10",
            "resourceGroup": "[split(parameters('omsWorkspaceId'),'/')[4]]",
            "subscriptionId": "[split(parameters('omsWorkspaceId'),'/')[2]]",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "apiVersion": "2015-11-01-preview",
                            "type": "Microsoft.OperationalInsights/workspaces",
                            "location": "[parameters('workspaceRegion')]",
                            "name": "[parameters('workspaceName')]",
                            "properties": {
                                "sku": {
                                    "name": "[parameters('omsSku')]"
                                }
                            }
                        }
                    ]
                }
            }
        },
        {
            "type": "Microsoft.Resources/deployments",
            "name": "ClusterMonitoringMetricPulisherRoleAssignmentDepl-20211130231648",
            "apiVersion": "2017-05-10",
            "resourceGroup": "trst",
            "subscriptionId": "ae642de8-dea6-4c85-887e-6b6c2ea9a2db",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "type": "Microsoft.ContainerService/managedClusters/providers/roleAssignments",
                            "apiVersion": "2018-01-01-preview",
                            "name": "trstcluster/Microsoft.Authorization/8d6b2f7b-830e-4a4d-a644-084673fbee7a",
                            "properties": {
                                "roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '3913510d-42f4-4e42-8a64-420c390055eb')]",
                                "principalId": "[reference(parameters('resourceName')).addonProfiles.omsAgent.identity.objectId]",
                                "scope": "/subscriptions/ae642de8-dea6-4c85-887e-6b6c2ea9a2db/resourceGroups/trst/providers/Microsoft.ContainerService/managedClusters/trstcluster"
                            }
                        }
                    ]
                }
            },
            "dependsOn": [
                "/subscriptions/ae642de8-dea6-4c85-887e-6b6c2ea9a2db/resourceGroups/trst/providers/Microsoft.ContainerService/managedClusters/trstcluster"
            ]
        },
        {
            "apiVersion": "2020-11-01",
            "name": "trst-vnet",
            "type": "Microsoft.Network/virtualNetworks",
            "location": "centralindia",
            "properties": {
                "subnets": [
                    {
                        "name": "default",
                        "id": "/subscriptions/ae642de8-dea6-4c85-887e-6b6c2ea9a2db/resourceGroups/trst/providers/Microsoft.Network/virtualNetworks/trst-vnet/subnets/default",
                        "properties": {
                            "addressPrefix": "10.240.0.0/16"
                        }
                    }
                ],
                "addressSpace": {
                    "addressPrefixes": [
                        "10.0.0.0/8"
                    ]
                }
            },
            "tags": {}
        },
        {
            "type": "Microsoft.Resources/deployments",
            "name": "ClusterSubnetRoleAssignmentDeployment-20211130231648",
            "apiVersion": "2017-05-10",
            "resourceGroup": "trst",
            "subscriptionId": "ae642de8-dea6-4c85-887e-6b6c2ea9a2db",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "variables": {},
                    "resources": [
                        {
                            "type": "Microsoft.Network/virtualNetworks/subnets/providers/roleAssignments",
                            "apiVersion": "2018-09-01-preview",
                            "name": "trst-vnet/default/Microsoft.Authorization/47b6d7b9-cf3c-4b8c-890f-6e938f052be9",
                            "properties": {
                                "roleDefinitionId": "[concat('/subscriptions/', subscription().subscriptionId, '/providers/Microsoft.Authorization/roleDefinitions/', '4d97b98b-1d4f-4787-a291-c67834d212e7')]",
                                "principalId": "[reference(parameters('resourceName'),'2021-02-01','Full').identity.principalId]",
                                "scope": "/subscriptions/ae642de8-dea6-4c85-887e-6b6c2ea9a2db/resourceGroups/trst/providers/Microsoft.Network/virtualNetworks/trst-vnet/subnets/default"
                            }
                        }
                    ]
                }
            },
            "dependsOn": [
                "Microsoft.Network/virtualNetworks/trst-vnet"
            ]
        }
    ],
    "outputs": {
        "controlPlaneFQDN": {
            "type": "string",
            "value": "[reference(concat('Microsoft.ContainerService/managedClusters/', parameters('resourceName'))).fqdn]"
        }
    }
}
uday kiran
  • 46
  • 4

0 Answers0