大网数据广告活动
服务器运维问答

Retrieve Azure Kubernetes virtual machines using Terraform

· 52CE 我爱测

I created an Azure Kubernetes cluster using Terraform. I used the recommanded azurerm_kubernetes_cluster resource, which create the nodes under the hood. As a consequence, I don't have access to the nodes as Kubernetes object. I …

问题原文

原帖链接 · dbourcet · CC BY-SA 4.0

I created an Azure Kubernetes cluster using Terraform. I used the recommanded azurerm_kubernetes_cluster resource, which create the nodes under the hood. As a consequence, I don't have access to the nodes as Kubernetes object. I now want to Terraform the alerting related to thoses nodes. But in order to do it, I need to have the nodes as a Terraform object (Terraform alert rule resource requires the id of the node: https://www.terraform.io/docs/providers/azurerm/r/monitor_metric_alertrule.html).

So I tried to access the nodes as Terraform data: https://www.terraform.io/docs/providers/azurerm/d/virtual_machine.html.

As stated in the previous link, we need two infos for that: the resource_group and the name of the virtual machine. The output of the azurerm_kubernetes_cluster resource gives us the resource_group, so that part is ok. But the nodes have a name generated randomly (to be more precised, one part of the name is generated randomly, the other part can be guessed from Terraform objects that we have). But as the previous link shows, there is no possibility to use a filter functionnality (such as in https://www.terraform.io/docs/providers/aws/d/ami.html) or to use a regex to match the nodes names. So the following is not possible (with the * in place of the random generated part and where part1 and part2 are known):

data "azurerm_virtual_machine" "nodes" {
  name                = "part1-*-part2"  
  resource_group_name = "${azurerm_kubernetes_cluster.this.node_resource_group}"
}

Does anyone have an id on how to unlock one of the following:

  • I can't find any explanation in the Azure AKS documentation on how the random generate part of the node name is generated (is it that random are can it be predicted?) and can't find myself by experimentation or wild guess. Does someone knows that?
  • Can we get the a list of virtual machines of a resource_group using datas in a way I didn't think of yet?
  • I can't seem to find any blog post or videos where AKS nodes alerting is done using Terraform, even with dirty tricks. Can someone provide me a link I missed to work on?

Terraform Azure provider version: 1.23.0

Terraform version: 0.10.x (required by the Azure provider 1.23.0)

已采纳解答

原帖链接 · Sam Cogan · CC BY-SA 4.0

You're coming at this the wrong way. When you create an AKS cluster, you are creating some VMs as worker nodes, however, these are not plain old VMs, you can't manage them like standalone VMs, the AKS cluster is undertaking most of the management work.

If you want to monitor the VMs, you need to do so through the AKS cluster, using AKS metrics, which include node metrics, not as standalone VMS. You can see more details of AKS metrics here - https://docs.microsoft.com/en-us/azure/azure-monitor/insights/container-insights-overview

The alternative approach recommended by MS is to have whatever monitoring tool or similar you want to run, running in a container its self. You can then have this run as a Daemonset on AKS so that it runs on every node. This is how the Azure Monitor collector works.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-04-01)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。