gpt4 book ai didi

Azure ARM 模板和 REST API

转载 作者:行者123 更新时间:2023-12-02 06:33:05 24 4
gpt4 key购买 nike

我正在尝试学习 Azure 资源模板,并尝试了解何时使用它们以及何时使用 REST API 背后的工作流程。

我的感觉是,在 Azure 中创建虚拟网络和子网是一种相当罕见的情况,一旦您按照需要进行设置,就不会过于频繁地修改它,而是将内容部署到该结构中。

对于 ARM 模板,假设我有一个包含 VNET 和子网资源的模板。以 https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-template-walkthrough#virtual-network-and-subnet 为例我可能有:

{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('vnetName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/16"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
}

我将其部署到资源组。假设我随后添加负载均衡器并重新部署模板。在这种情况下,用户会被要求再次提供 vnetName 参数的值,当然不能提供相同的值,因此我们最终会得到另一个 VNET,这不是我们想要的。

那么您的 ARM 模板(VNET、LB、子网、NIC 等)是一次性定义然后部署的工作流程吗?然后,当您想要部署虚拟机、规模集等时,您可以使用 REST API 来部署到资源组/VNET 子网吗?或者是否有一种方法可以逐步构建 ARM 模板并多次部署它,如果 VNET 已经存在(例如),则不会提示用户提供另一个模板的详细信息?

我已经阅读并看到了增量模式(除非指定完整,否则默认),但不确定这是否相关以及是否如何使用它。

非常感谢您的帮助!

更新

好的,我现在可以使用azure group deployment create -f azuredeploy.json -g ARM-Template-Tests -m Incremental,并修改了模板中的 VNET 资源

{
"apiVersion": "2016-09-01",
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[variables('addressPrefix')]"
]
},
"subnets": [
{
"name": "[variables('subnetName')]",
"properties": {
"addressPrefix": "[variables('subnetPrefix')]"
}
}
]
}
},

{
"apiVersion": "2015-05-01-preview",
"type": "Microsoft.Network/virtualNetworks",
"name": "[parameters('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"properties": {
"addressSpace": {
"addressPrefixes": [
"[parameters('addressPrefix')]"
]
},
"subnets": [
{
"name": "[parameters('subnet1Name')]",
"properties": {
"addressPrefix": "[parameters('subnet1Prefix')]"
}
},
{
"name": "[parameters('gatewaySubnet')]",
"properties": {
"addressPrefix": "[parameters('gatewaySubnetPrefix')]"
}
}
]
}
},

但子网不会改变。他们是否应该使用azure组部署create -f azuredeploy.json -g ARM-Template-Tests -m Incremental

最佳答案

我要搭载这个 Azure documentation 。引用下面的相应部分:

Incremental and complete deployments

When deploying your resources, you specify that the deployment is either an incremental update or a complete update. By default, Resource Manager handles deployments as incremental updates to the resource group.

With incremental deployment, Resource Manager

  1. leaves unchanged resources that exist in the resource group but are not specified in the template
  2. adds resources that are specified in the template but do not exist in the resource group
  3. does not reprovision resources that exist in the resource group in the same condition defined in the template
  4. reprovisions existing resources that have updated settings in the template

With complete deployment, Resource Manager:

  1. deletes resources that exist in the resource group but are not specified in the template
  2. adds resources that are specified in the template but do not exist in the resource group
  3. does not reprovision resources that exist in the resource group in the same condition defined in the template
  4. reprovisions existing resources that have updated settings in the template

选择增量更新或完全更新取决于您是否有正在使用的资源。如果 devops 要求始终使资源与 json 模板中定义的内容同步,则应使用Complete Update 模式。使用模板和源代码部署资源的最大好处是防止配置漂移,并且有利于使用Complete Update模式。

至于指定参数,如果在参数文件中指定,则不必再次指定。

关于Azure ARM 模板和 REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41508244/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com