使用azurerm_kubernetes_cluster
创建新的aks集群时,会自动创建一个名为-MC_%RESOURCE_GROUP_NAME%_%CLUSTER_NAME%_%LOCATION%
的新资源组,其中包含该集群的所有网络资源。
我的目标是使用一个Vnet,该Vnet将容纳这些资源(AKS网络资源)以及其他资源,例如VM和Azure缓存。
据我所知,有2个选项可以解决此问题-
目前,我正在尝试接近2,但到目前为止还没有运气。
任何想法,建议和示例都将不胜感激。
答案 0 :(得分:3)
它不是真的那样工作。如您所见,azure将创建一个全新的RG,其中包含大量与AKS相关的内容。但是群集itef会进入您想要放入的任何RG。然后使用azure
网络插件,您的Pod可以转到您指定的VNEts上,并可以访问Vnet中的其他资源。 / p>
这里有一个示例,是我在满足自己的需求进行开发时如何构建它的,应该对您来说是一个很好的入门。
resource "azurerm_resource_group" "rg" {
name = var.rgname
location = var.location
tags = var.default-tags
}
resource "azurerm_virtual_network" "vnet" {
name = "vnet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = [var.ipspace]
tags = var.default-tags
}
resource "azurerm_subnet" "vmsubnet" {
name = "vmsubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefix = var.vmsubnet
}
resource "azurerm_subnet" "akspodssubnet" {
name = "akspodssubnet"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefix = var.akspodssubnet
}
resource "azurerm_kubernetes_cluster" "k8s" {
name = "K8Scluster"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name # th RG the single cluster entity goes is
dns_prefix = "k8s"
node_resource_group = "K8S${azurerm_resource_group.rg.name}" # all the k8s' entities must be in fdifferent RG than where the cluster object itself is
api_server_authorized_ip_ranges = ["REDACTED"]
#enable_pod_security_policy = true
kubernetes_version = "1.15.7"
default_node_pool {
name = "default"
type = "AvailabilitySet"
vm_size = var.vmsize # Standard_DC2s_v2 Standard_B1ms
enable_node_public_ip = false
enable_auto_scaling = false
os_disk_size_gb = 30
node_count = 1
vnet_subnet_id = azurerm_subnet.akspodssubnet.id
}
addon_profile {
kube_dashboard { enabled = true }
}
network_profile {
network_plugin = "azure"
network_policy = "azure"
load_balancer_sku = "standard"
service_cidr = var.aksservicecidr
docker_bridge_cidr = var.dockercidrip
dns_service_ip = var.aksdns
}
linux_profile {
admin_username = var.sudouser
ssh_key { key_data = var.sshpubkey }
}
service_principal {
client_id = var.client_id
client_secret = var.client_secret
}
tags = var.default-tags
}
output "client_certificate" {
value = azurerm_kubernetes_cluster.k8s.kube_config.0.client_certificate
}
output "kube_config" {
value = azurerm_kubernetes_cluster.k8s.kube_config_raw
}