使用ARM模板在现有Vnet /子网中部署AKS集群

时间:2019-10-23 21:23:06

标签: azure kubernetes arm-template azure-virtual-network

我有一个使用两个子网创建的现有虚拟网络:aks-subnetpersistence-subnet

我的目标是在aks-subnet

内创建一个Azure Kubernetes群集

我正在使用PowerShell核心中的New-AzDeployment命令来创建资源组和资源at the subscription level

就像我的想法是创建一个资源组并向其中部署资源一样,我有一个嵌套的模板,用于定义要在资源组中创建的资源。

所以我有从ARM模板创建的资源组

  • 请在该线程末尾显示的整个模板中找到此json定义
"type": "Microsoft.Resources/resourceGroups",

我正在使用“部署”资源,以便将包含要创建的资源的模板嵌套在资源组中。

  • 请在之后立即查找:
"type": "Microsoft.Resources/deployments"

所以在Microsoft.Resources/deployments内部,我用前面提到的两个子网创建了一个Vnet,

并且有效!,Vnet和子网创建在同一模板中创建的资源组内。

  • 请在此线程末尾显示的整个模板中找到
"type": "Microsoft.Network/virtualNetworks",

现在,我想在aks-vnet内添加一个Azure Kubernetes群集。

  • 请在整个模板中找到
"dependsOn": [
    "Microsoft.Network/virtualNetworks/AssessmentVNet"
],
"type": "Microsoft.ContainerService/managedClusters",

然后将默认池(或虚拟机)与aks-subnet关联时,

  • 请在此线程末尾显示的整个模板中以这种方式找到 vnetSubnetID属性:
"vnetSubnetID": "[resourceId(parameters('resourceGroupName'),'Microsoft.Network/virtualNetworks/subnets',parameters('vnetName'),parameters('subnet1Name'))]",

根据此AKS advanced networking official link建议,我正在尝试以这种方式访问​​VnetSubnetID:

根据上面的内容,我正在执行以下操作:

  • 我从Vnet所在的resourceId获得了resourceGroupName
  • 我正在指示资源子网Microsoft.Network/virtualNetworks/subnets
  • 的类型
  • 我像参数一样传递了具有子网的Vnet的名称以及子网的名称parameters('vnetName'),parameters('subnet1Name'))

但是当我从Power Shell执行模板时,出现以下错误:

PS /home/bgarcial/projects/my-project/Deployments/ARMTemplates/ResourceGroup> New-AzDeployment `
>>  -Name SentiaAssessment `
>>  -location westeurope `
>>  -TemplateUri $templateUri `
>>  -resourceGroupName $resourceGroupName `
>>  -environmentName accp `
>>  -dnsPrefix WordpressSentiaAssessment-dns `
>>  -servicePrincipalClientId $servicePrincipalClientId `
>>  -servicePrincipalClientSecret $servicePrincipalClientSecret

New-AzDeployment : 10:20:02 PM - Resource Microsoft.Resources/deployments 'storageDeployment' failed with message '{


"error": {
    "code": "InvalidTemplate",
    "message": "Unable to process template language expressions for resource '/subscriptions/9148bd11-f32b-4b5d-a6c0-5ac5317f29ca/resourceGroups/sentia-assessment/providers/Microsoft.Resources/deployments/storageDeployment' at line '150' and column '9'. 'The provided value 'sentia-assessment' is not valid subscription identifier. Please see https://aka.ms/arm-template-expressions/#resourceid for usage details.'",
    "additionalInfo": [
      {
        "type": "TemplateViolation",
        "info": {
          "lineNumber": 150,
          "linePosition": 9,
          "path": ""
        }
      }
    ]
  }
}'
At line:1 char:1
+ New-AzDeployment `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [New-AzDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureDeploymentCmdlet

New-AzDeployment : 10:20:02 PM - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
At line:1 char:1
+ New-AzDeployment `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [New-AzDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureDeploymentCmdlet

New-AzDeployment : 10:20:02 PM - Template output evaluation skipped: at least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.
At line:1 char:1
+ New-AzDeployment `
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : NotSpecified: (:) [New-AzDeployment], Exception
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureDeploymentCmdlet


DeploymentName          : MyDeployment
Location                : westeurope


ProvisioningState       : Failed
Timestamp               : 10/23/19 8:19:57 PM
Mode                    : Incremental
TemplateLink            : 
Parameters              : 
                          Name                            Type                       Value     
                          ==============================  =========================  ==========
                          resourceGroupName               String                     sentia-assessment
                          location                        String                     West Europe
                          vnetName                        String                     AssessmentVNet
                          vnetAddressPrefix               String                     10.0.0.0/8
                          subnet1Prefix                   String                     10.240.0.0/16
                          subnet1Name                     String                     aks-subnet
                          subnet2Prefix                   String                     10.241.0.0/27
                          subnet2Name                     String                     persistence-subnet
                          k8s_cluster_name                String                     WordpressSentiaAssessment
                          kubernetesVersion               String                     1.14.7    
                          dnsPrefix                       String                     WordpressSentiaAssessment-dns
                          nodeCount                       Int                        3         
                          agentVMSize                     String                     Standard_D2_v2
                          servicePrincipalClientId        SecureString                         
                          servicePrincipalClientSecret    SecureString                         
                          serviceCidr                     String                     100.0.0.0/16
                          dnsServiceIP                    String                     100.0.0.10
                          dockerBridgeCidr                String                     172.17.0.1/16
                          environmentName                 String                     accp      

Outputs                 : 
DeploymentDebugLogLevel : 


PS /home/bgarcial/projects/my-project/Deployments/ARMTemplates/ResourceGroup> 

看起来我需要在我正在使用的resourceId模板函数中包含suscriptionId值,但是尽管我正在查询the template reference

,但目前尚不清楚如何执行此操作

顺便说一句,其他细节是我正在使用networkPlugin kubenet。

我是否需要使用 Azure CNI 作为网络插件才能获得它?

这是完整的ARM模板。我把它放在这里是为了给我一个想法,让我知道我在做什么以及如何做,也可以让我找到上面我解释过的json部分代码定义。

如果有人能指出我正确的方向,我将不胜感激

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "resourceGroupName": {
      "type": "string"  
    },
    "location": {
      "type": "string",
      "defaultValue": "West Europe",
      "metadata": {
        "description": "Geographic Location for all resources."
      }
    },
    "vnetName": {
      "type": "string",
      "defaultValue": "AssessmentVNet",
      "metadata": {
        "description": "Sentia Wordpress Assesment Vnet"
      }
    },
    "vnetAddressPrefix": {
      "type": "string",
      "defaultValue": "10.0.0.0/8",
      "metadata": {
        "description": "Address prefix"
      }
    },
    "subnet1Prefix": {
      "type": "string",
      "defaultValue": "10.240.0.0/16",
      "metadata": {
        "description": "AKS Subnet"
      }
    },
    "subnet1Name": {
      "type": "string",
      "defaultValue": "aks-subnet",
      "metadata": {
        "description": "aks-subnet"
      }
    },
    "subnet2Prefix": {
      "type": "string",
      "defaultValue": "10.241.0.0/27",
      "metadata": {
        "description": "Persistence subnet"
      }
    },
    "subnet2Name": {
      "type": "string",
      "defaultValue": "persistence-subnet",
      "metadata": {
        "description": "persistence-subnet"
      }
    },
    "k8s_cluster_name":{
      "type": "string",
      "defaultValue": "WordpressSentiaAssessment",
      "metadata": {
        "description": "The name of the Azure Kubernetes Service Cluster"
      }
    },
    "kubernetesVersion": {
      "type": "string",
        "defaultValue": "1.14.7",
        "metadata": {
          "description": "The version of the Azure Kubernetes Service Cluster"
        }
    },
    "dnsPrefix": {
      "type": "string",
      "metadata": {
          "description": "Optional DNS prefix to use with hosted Kubernetes API server FQDN."
      }
    },
    "nodeCount": {
      "type": "int",
      "defaultValue": 3,
      "metadata": {
          "description": "The number of nodes that should be created along with the cluster."
      },
      "minValue": 1,
      "maxValue": 100
    },
    "agentVMSize": {
      "type": "string",
      "defaultValue": "Standard_D2_v2",
      "metadata": {
        "description": "The size of the Virtual Machine."
      }
    },
    "servicePrincipalClientId": {
      "metadata": {
        "description": "Client ID (used by cloudprovider)."
      },
      "type": "securestring"
    },
    "servicePrincipalClientSecret": {
      "metadata": {
        "description": "The Service Principal Client Secret."
      },
      "type": "securestring"
    },
    "serviceCidr": {
      "type": "string",
        "metadata": {
            "description": "A CIDR notation IP range from which to assign service cluster IPs."
        },
        "defaultValue": "100.0.0.0/16"
    },
    "dnsServiceIP": {
      "type": "string",
        "metadata": {
          "description": "Containers DNS server IP address."
        },
        "defaultValue": "100.0.0.10"
    },
    "dockerBridgeCidr": {
      "type": "string",
      "metadata": {
          "description": "A CIDR notation IP for Docker bridge."
      },
      "defaultValue": "172.17.0.1/16"
    },
    "environmentName": {
      "type": "string",
      "metadata": {
        "description": "Environment name for tagging purposes, e.g. dev, accp, prod"
      }
    }
  },
  "variables": {
    "osDiskSizeGB": 0,
    "osType": "Linux",
    "maxPods": 110,
    "networkPlugin": "kubenet"
  },
  "resources": [
    {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2018-05-01",
      "location": "[parameters('location')]",
      "name": "[parameters('resourceGroupName')]",
      "properties": {}
    },
    {
      "type": "Microsoft.Resources/deployments",
      "apiVersion": "2018-05-01",
      "name": "storageDeployment",
      "resourceGroup": "[parameters('resourceGroupName')]",
      "dependsOn": [
          "[resourceId('Microsoft.Resources/resourceGroups/', parameters('resourceGroupName'))]"
      ],
      "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": "2018-10-01",
              "type": "Microsoft.Network/virtualNetworks",
              "name": "[parameters('vnetName')]",
              "location": "[parameters('location')]",
              "properties": {
                "subnets": [
                  {
                    "name": "[parameters('subnet1Name')]",
                    "properties": {
                      "addressPrefix": "[parameters('subnet1Prefix')]"
                    }
                  },
                  {
                    "name": "[parameters('subnet2Name')]",
                    "properties": {
                      "addressPrefix": "[parameters('subnet2Prefix')]",
                      "serviceEndpoints": [
                        {
                          "service": "Microsoft.Storage",
                          "locations": "[parameters('location')]"
                        },
                        {
                          "service": "Microsoft.Sql",
                          "locations": "[parameters('location')]"
                        }
                      ]
                    }
                  }
                ],      
                "addressSpace": {
                  "addressPrefixes": [
                    "[parameters('vnetAddressPrefix')]"
                  ]
                }
              },
              "tags": {
                "Environment": "[parameters('environmentName')]"
              }
            },
            {
              "apiVersion": "2019-06-01",
              "dependsOn": [
                "Microsoft.Network/virtualNetworks/AssessmentVNet"
              ],
              "type": "Microsoft.ContainerService/managedClusters",
              "location":"[parameters('location')]",
              "name": "[concat(parameters('k8s_cluster_name'), '-aks')]",
              "properties":{
                "kubernetesVersion":"[parameters('kubernetesVersion')]",
                "enableRBAC": true,
                "dnsPrefix": "[concat(parameters('k8s_cluster_name'),'-dns')]",
                "agentPoolProfiles":[
                  {
                    "name":"defaultpool",
                    "osDiskSizeGB": "[variables('osDiskSizeGB')]",
                    "count":"[parameters('nodeCount')]",
                    "vmSize": "[parameters('agentVMSize')]",
                    "osType": "[variables('osType')]",
                    "storageProfile": "ManagedDisks",
                    "type": "VirtualMachineScaleSets",
                    "vnetSubnetID": "[resourceId(parameters('resourceGroupName'),'Microsoft.Network/virtualNetworks/subnets',parameters('vnetName'),parameters('subnet1Name'))]",
                    "maxPods": "[variables('maxPods')]"
                  }
                ],
                "servicePrincipalProfile": {
                    "ClientId": "[parameters('servicePrincipalClientId')]",
                    "Secret": "[parameters('servicePrincipalClientSecret')]"
                },
                "networkProfile": {
                  "networkPlugin": "[variables('networkPlugin')]",
                  "serviceCidr": "[parameters('serviceCidr')]",
                  "dnsServiceIP": "[parameters('dnsServiceIP')]",
                  "dockerBridgeCidr": "[parameters('dockerBridgeCidr')]"
                }
              },
              "tags": {
                "Environment": "[parameters('environmentName')]"
              }
            },
            {

            }  
          ]
        }
      }
    }    
  ]
}

0 个答案:

没有答案