通过ARM模板提供经典云服务 [英] Provision classic cloud service via ARM template

查看:27
本文介绍了通过ARM模板提供经典云服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的一个项目中,我们试图在 Azure 上自动部署云组件.对于大多数组件(基本上是所有 ARM 组件,如 Redis、服务总线、应用服务等),我们能够使用 ARM 模板和 Powershell 脚本实现它.

In one of our project, we are trying to automate deployment of cloud components on Azure. For majority of components (basically all ARM components like Redis, Service bus, App Service etc.) we were able to achieve it using ARM templates and Powershell script.

然而,我们被困在云服务(经典)组件.云服务组件中仅包含WebRole,无需配置VM.

However, we are stuck at Cloud Service (classic) component. Cloud service component contains only WebRole in it and no VM needs to be provisioned.

我们可以通过经典的部署模型,即在 Power Shell 中使用 ASM 命令.但是因为 ARM 模型支持从 azure 门户进行配置和部署,所以我想知道 ARM REST API 也必须对这个组件提供开箱即用的支持.我试图弄清楚但找不到任何相关的文档.

We can go via classic deployment model i.e. using ASM commands in power shell. But since, ARM model supports provisioning and deployment from azure portal so I was wondering ARM REST API's must have out of box support for this component as well. I try to figure out but couldn't find any related documentation to it.

Azure 模板 (AzureDeploy.json)

Azure template (AzureDeploy.json)

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "parameters": {
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
         {
            "apiVersion": "2014-06-01",
            "name": "[parameters('name')]",
            "location": "[parameters('location')]",
            "type": "Microsoft.ClassicCompute/domainNames"
        }
    ]
}

Powershell 脚本:

Powershell script:

Param(
    [string] $ResourceGroupLocation = 'South India',
    [string] $ResourceGroupName = 'FreeTrial',
    [string] $TemplateFile = 'AzureDeploy.json'
)

$TemplateFile = [System.IO.Path]::GetFullPath([System.IO.Path]::Combine($PSScriptRoot, $TemplateFile))

New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop 
New-AzureRmResourceGroupDeployment -Name ((Get-ChildItem $TemplateFile).BaseName + '-' + ((Get-Date).ToUniversalTime()).ToString('MMdd-HHmm')) `
                                   -ResourceGroupName $ResourceGroupName `
                                   -TemplateFile $TemplateFile `
                                   -Force -Verbose

如果我尝试执行上述脚本,执行会卡在检查部署一个小时左右,并且必须手动终止脚本执行..

If I try to execute the above script, execution gets stuck at Checking deployment for an hour or so and have to manually kill the script execution. .

但是,如果我在 power shell 中运行以下命令,它会成功地在门户中创建一个资源:

However, if I ran following command in power shell, it succesfully creates a resource in portal:

New-AzureRmResource -Location "南印度" -ResourceName"cloudsmplservice" -ResourceType"Microsoft.ClassicCompute/domainNames" -ResourceGroupName "FreeTrial"

New-AzureRmResource -Location "South India" -ResourceName "cloudsmplservice" -ResourceType "Microsoft.ClassicCompute/domainNames" -ResourceGroupName "FreeTrial"

但我不明白 ARM 模板方法有什么问题.有人可以指导我解决第一种方法的问题吗?

But I do not understand what's an issue with ARM template approach. Can someone please direct me to the problem in first approach?

附录:

我发现了一个奇怪的行为.如果我在资源定义中硬编码资源名称值或在 powershell 提示时传递它,部署工作正常.

I found a strange behaviour. If I hardcode the resource name value in the resource definition OR pass it when powershell prompt for it, deployment works fine.

但是,如果我为参数设置了一些默认值或通过参数文件传递它,则它不起作用.

However, if I set some default Value for parameter OR pass it via parameter file, its not working.

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "cloudName": {
      "type": "string",
      "defaultValue": "cloudsrvc"
    }
  },
  "resources": [
    {
      "apiVersion": "2015-06-01",
      "name": "[parameters('cloudName')]",
      "location": "[resourceGroup().location]",
      "type": "Microsoft.ClassicCompute/domainNames"
    }
  ]
}

<小时>

附录 2:

似乎是一些 powershell 配置问题.将向 Azure 团队报告更多详细信息.因此,Far 能够通过简单的步骤重现它:

Seems like some powershell configuration issue. Will report it to Azure team with more details. So, far was able to reproduce it with simple steps:

  1. 在 azure 中创建了一个全新的 VM.
  2. 导入 AzureRM 模块.
  3. 尝试使用默认值模板配置云服务.(如前所述)
  4. 现在尝试通过从 powershell 传递参数来进行配置.(工作正常)
  5. 现在使用默认值模板再试一次.(工作正常)

推荐答案

我建议您从 Azure 门户中的模板部署验证您的云服务 ARM 模板.

I will recommend you to validate your Cloud Service ARM Template from the Template Deployment in the Azure portal.

我可以使用下面的模板部署裸机云服务,并在几秒钟内部署成功.

I am able to deploy a bare metal Cloud Service using the template below and the deployment is successful within seconds.

当尝试从 Azure 门户创建新的云服务时,您还可以通过单击自动化选项对云服务 ARM 模板进行逆向工程".

You can also "reverse engineer" the Cloud Service ARM Template by clicking on the Automation option when try to create a new Cloud Service from the Azure portal.

我没有看到通过 ARM 模板方法自动化云服务的问题.

I didn't see the problem in automating Cloud Service by the ARM Template approach.

注意:

我已经在印度南部位置部署了它,并且可以正常工作.

I have deployed this in South India location and it works.

附录:

我已经使用您的 PowerShell 脚本部署了如下模板,它也能正常工作.

I have deployed the template as below using your PowerShell script and it works as well.

Azure PowerShell 版本为 4.3.1(2017 年 8 月).

Azure PowerShell version is 4.3.1 (August 2017).

截图如下.

{
    "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "name": {
            "type": "string"
        },
        "location": {
            "type": "string"
        }
    },
    "resources": [
        {
            "apiVersion": "2016-11-01",
            "name": "[parameters('name')]",
            "location": "[parameters('location')]",
            "type": "Microsoft.ClassicCompute/domainNames"
        }
    ]
}

附录 2:

尝试使用具有默认参数值的模板,部署也成功.

Try with template with default param values and the deployment is also working successful.

注意:我注意到您的 api 版本较旧,我的云服务的 api 版本是 2016-11-01

Note: I notice your api version is older and the api version for my cloud service is 2016-11-01

{
  "$schema": "http://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "name": {
      "type": "string",
      "defaultValue": "[resourceGroup().name]"
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    }
  },
  "resources": [
    {
      "apiVersion": "2016-11-01",
      "name": "[parameters('name')]",
      "location": "[parameters('location')]",
      "type": "Microsoft.ClassicCompute/domainNames"
    }
  ]
}

这篇关于通过ARM模板提供经典云服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆