azure - 在 shell 脚本中使用 while 循环与 AKS CLI 并行创建多个 AKS 群集
问题描述
az aks create
我创建了运行不同命令的 shell 脚本。
我有很多变量,但现在我在 while 循环中只更改集群名称。
shell脚本的结构是:
cnt=1
while [ $cnt -lt 3 ]
do
aksName=AKS0$cnt
# more AKS VARs
# and then CLI command:
az aks create --name $aksName #--<MORE AKS CREATE SWITCHES>
cnt=`expr $cnt + 1`
done
它确实创建了 2 个 AKS 集群,但是 1 接 1 串联,有没有办法并行创建多个集群,可能正在使用 ansible,如果有,请告诉我如何?
谢谢
解决方案
我建议使用像 Pulumi 或 Terraform 这样的 IaC 工具来创建 AKS 集群而不是 Ansible。这是用于创建 2 个 AKS 集群的 Terraform 代码。如果您想要更多,只需更新计数值,Terraform 还将并行创建这些集群:
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.80.0"
}
}
required_version = "=1.0.5"
}
provider "azurerm" {
features {}
}
data "azurerm_client_config" "current" {
}
locals {
rg_name = "demo"
location = "westeurope"
name = "demo"
common_tags = {
env = "demo"
managedBy = data.azurerm_client_config.current.client_id
}
}
resource "azurerm_resource_group" "demo" {
name = local.rg_name
location = local.location
}
resource "azurerm_kubernetes_cluster" "aks" {
count = 2
name = "${local.name}-${count.index}"
location = azurerm_resource_group.demo.location
resource_group_name = azurerm_resource_group.demo.name
dns_prefix = "${local.name}-${count.index}"
tags = local.common_tags
identity {
type = "SystemAssigned"
}
default_node_pool {
name = "default"
node_count = 3
vm_size = "Standard_D2_v2"
}
}
推荐阅读
- javascript - 如何在数组循环中强制执行承诺
- php - 如何使用 id 更新正确的数据?
- amazon-cloudformation - 如果已附加弹性 IP,则允许重新关联
- android - 更新 android studio 后出现的错误怎么办?
- mysql - 如何使用 MySQL 获得取决于 id 的价格
- assembly - 如何修复 Microsoft 16 位链接器上的错误 L2029?
- unit-testing - RPC 在单元测试中被阻塞
- node.js - 从 node.js 在 mysql 中创建存储过程
- python-3.x - 以最快的速度列出嵌套字典
- java - 在java中,'for(int i=0; i
}' 和 'array = 新 [数组.长度]'?