AKS ARM 模板 |查询

问题描述 投票:0回答:1

我正在努力使用 ARM 模板构建 AKS 集群。我遇到的情况是,如果我将操作系统类型定义为 Windows,模板应填充“WindowsProfile”,如果我在操作系统类型中选择 linux,则它应填充 linuxprofile。

这里是选择了linux配置文件的模板,如果我向windows提供参数OSType值,我如何在这里插入windows配置文件。

     "name": "[parameters('AKSClustername')]",
        "type": "Microsoft.ContainerService/managedClusters",
        "apiVersion": "2021-05-01",
        "location": "[parameters('Region')]",
        "properties": {
            "kubernetesVersion": "[parameters('kubernetesversion')]",
            "dnsPrefix": "dnsprefix",
            "agentPoolProfiles": [
                {
                    "name": "[parameters('agentPoolName')]",
                    "count": "[parameters('nodeCount')]",
                    "vmSize": "[parameters('vmSize')]",
                    "osType": "[parameters('OSType')]",
                    "storageProfile": "ManagedDisks",
                    "enableAutoScaling": "[parameters('autoscalepools')]",
                    //                        "availabilityZones": "[if(equals(parameters('availabilityZones'), bool('true')), variables('AVZone'), json('null'))]"
                    "availabilityZones": "[if(equals(parameters('availabilityZones'), or('1', '2', '3')), variables('AVZone'), json('null'))]"
                }
            ],
            "linuxProfile": {
                "adminUsername": "adminUserName",
                "ssh": {
                    "publicKeys": [
                        {
                            "keyData": "keyData"
                        }
                    ]
                }
            },
azure azure-aks azure-resource-manager
1个回答
0
投票

说实话,使用 ARM Template 并不具有真正的可读性和可维护性。 我建议你看看Bicep。 它将编译为 ARM 模板,但更具可读性。使用二头肌,你可以做类似的事情:

//main.bicep

param AKSClustername string
param Region string
param kubernetesversion string
param agentPoolName string
param nodeCount int
param vmSize string
param OSType string
param autoscalepools bool

// Define common properties
var baseProperties = {
  kubernetesVersion: kubernetesversion
  dnsPrefix: 'dnsprefix'
  agentPoolProfiles: [
    {
      name: agentPoolName
      count: nodeCount
      vmSize: vmSize
      osType: OSType
      storageProfile: 'ManagedDisks'
      enableAutoScaling: autoscalepools
    }
  ]
}

// Add profile based on OSType
var propertiesWithOsProfile = union(baseProperties, OSType == 'Linux' ? {
    linuxProfile: {
      adminUsername: 'adminUserName'
      ssh: {
        publicKeys: [
          {
            keyData: 'keyData'
          }
        ]
      }
    }
  } : {
    windowsProfile: {
      adminPassword: ''
      adminUsername: ''
      licenseType: 'Windows_Server'
    }
  }
)

// Create the cluster
resource aks 'Microsoft.ContainerService/managedClusters@2021-05-01' = {
  name: AKSClustername
  location: Region
  properties: propertiesWithOsProfile
}

Azure CLIPowershell 都支持 Bicep。

如果您确实需要生成ARM模板,您可以运行此命令

az bicep build --file main.bicep

它将为您生成一个ARM模板。

© www.soinside.com 2019 - 2024. All rights reserved.