Azure AKS - oms 代理和诊断设置可以一起使用吗?

标签 azure terraform azure-aks monitor

我正在通过 Terraform 部署 AKS 集群。

我在我的 aks 资源 block 中设置了 oms_agent block :

resource "azurerm_kubernetes_cluster" "tfdemo-cluster" {
  resource_group_name               = var.resourcegroup_name
  location                          = var.location
  name                              = "${var.projectname}-aks"
  node_resource_group               = "${var.resourcegroup_name}-node"
  ... omitted to shorten ...
  
  oms_agent {
    log_analytics_workspace_id = var.log_analytics_workspace_id
  }

就像这样,它可以按方面工作。

但是当我像这样添加诊断设置类型的附加资源时

resource "azurerm_monitor_diagnostic_setting" "aks-diagnostics" {
  name = "aks-logs"
  storage_account_id = var.storage_account_id
  target_resource_id = azurerm_kubernetes_cluster.tfdemo-cluster.id

  log {
    category = "kube-audit"
    enabled  = true
  }

  metric {
    category = "AllMetrics"
    retention_policy {
      days    = 30
      enabled = true
    }
  }
}

我遇到一个错误:

“diagnosticsettings.DiagnosticSettingsClient#CreateOrUpdate:发送请求失败:StatusCode=409 -- 原始错误:autorest/azure:服务返回错误。Status=nil nil”

当我尝试在 google 上搜索该错误消息时,我发现了与其他 Azure 服务相关的问题,其中该服务的 sku 与指定的功能或容量不匹配,但我在这里没有看到这一点。

为什么我想要将日志分析工作区和日志转储到存储帐户中:我的想法只是日志分析。与存储帐户中的存储相比,ws 确实很昂贵。所以我想我将长期保留的审核数据发送到便宜的存储帐户(给定示例中的我的设置可能不能 100% 代表这一点,但这不是我想说的重点)并且仍然具有“昂贵”日志分析服务来深入了解集群性能。

非常感谢您的任何意见!

最佳答案

我尝试在我的环境中重现相同的内容,以使用 Terraform 创建具有 OMS 代理和诊断设置的 Azure AKS 群集:

将长期数据保留日志发送到 Azure 存储帐户比将其保存在 Azure Log Analytics 工作区中更具成本效益。不过,Azure Log Analytics 工作区对于实时分析和性能监控仍然很有用。

    provider "azurerm" {
  features {}
}
resource "azurerm_resource_group" "aksgroup" {
  name     = "aks-rg"
  location = "East US"
}

resource "azurerm_log_analytics_workspace" "oms" {
  name                = "oms-workspace"
  location            = azurerm_resource_group.aksgroup.location
  resource_group_name = azurerm_resource_group.aksgroup.name
  sku                 = "PerGB2018"
}

resource "azurerm_kubernetes_cluster" "aks" {
  name                = "cluster-aks1"
  location            = azurerm_resource_group.aksgroup.location
  resource_group_name = azurerm_resource_group.aksgroup.name
  dns_prefix          = "aks1"

  default_node_pool {
    name       = "default"
    node_count = 1
    vm_size    = "standard_a2_v2"
  }

  identity {
    type = "SystemAssigned"
  }

  tags = {
    Environment = "Production"
  }
  addon_profile {
      oms_agent {
        enabled                    = true
        log_analytics_workspace_id = azurerm_log_analytics_workspace.oms.id
      }
    }
}

output "client_certificate" {
  value     = azurerm_kubernetes_cluster.aks.kube_config.0.client_certificate
  sensitive = true
}

output "kube_config" {
  value = azurerm_kubernetes_cluster.aks.kube_config_raw

  sensitive = true
}

resource "azurerm_monitor_diagnostic_setting" "aks" {
  name                 = "aks-diagnostic-setting"
  target_resource_id   = azurerm_kubernetes_cluster.aks.id
  storage_account_id   = azurerm_storage_account.aks.id
  log_analytics_workspace_id = azurerm_log_analytics_workspace.oms.id
  log {
    category = "kube-audit"
    enabled  = true
  }
  metric {
    category = "AllMetrics"
    retention_policy {
      days    = 30
      enabled = true
    }
  }
}

resource "azurerm_storage_account" "aks" {
  name                = "aksdiagnostic"
  resource_group_name = azurerm_resource_group.aksgroup.name
  location            = azurerm_resource_group.aksgroup.location
  account_tier        = "Standard"
  account_replication_type = "LRS"
}

Terraform 应用:

enter image description here

运行后,将创建代码资源,如下所示。

enter image description here

使用 Log Analytics 设置创建的 Azure AKS 诊断设置。

enter image description here

Log Analytics 设置 - 已创建

enter image description here

关于Azure AKS - oms 代理和诊断设置可以一起使用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75391858/

相关文章:

Azure Functions 服务无法识别从外部客户端发送的请求

security - 从企业到 Windows Azure 的 VPN 连接

terraform - 此处不能使用each.value

Terraform resource_aws_vpc_endpoint Dns 列表为空

amazon-web-services - 安全组定义中不允许自引用

azure - 无法连接到服务器: dial tcp: lookup <Server Location>: no such host

Azure AKS - 此容器服务处于失败状态

python - 如何从用 Python 编写的 azure 函数中检索存储在 BLOB 存储中的模型 (UnpicklingError)

azure - 使用 CSI 驱动程序将 AKV 与 AKS 集成后从/mnt/secrets-store/读取值

r - 自定义模块的多个输出