添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

本文說明如何使用叢集的數據收集規則 (DCR) 在容器深入解析 中設定數據收集。 當您將叢集上線至容器深入解析時,就會建立 DCR。 容器化代理程式會使用此 DCR 來定義叢集的數據收集。

DCR 主要用於設定效能和清查數據的數據收集,以及設定成本優化。

您可以使用 DCR 執行的特定設定包括:

  • 啟用/停用效能和清查數據的收集與命名空間篩選
  • 定義效能和清查數據的收集間隔
  • 啟用/停用 stdout 和 stderr 記錄的收集
  • 啟用/停用 Syslog 集合
  • 選取記錄架構
  • 請參閱 使用 ConfigMap 在容器深入解析中設定數據收集,以使用 DCR 設定數據收集,以讓您設定不同的設定。

  • AKS 叢集必須使用系統或使用者指派的受控識別。 如果叢集使用服務主體,您必須 升級至受控識別
  • 設定數據收集

    當您啟用容器深入解析時所建立的 DCR 名為 MSCI-cluster-region-cluster-name ><<>。 您可以在 Azure 入口網站 中選取 [監視 ] 功能表中的 [數據收集規則 ] 選項 ,以在 Azure 入口網站 中檢視它。 您應該使用下列其中一種方法來設定數據收集,而不是直接修改 DCR。 如需每個方法所使用之不同可用設定的詳細資訊,請參閱 數據收集參數

    預設的容器深入解析體驗取決於所有現有的數據流。 拿掉一或多個預設數據流會讓容器深入解析體驗無法使用,而您需要使用其他工具,例如 Grafana 儀錶板和記錄查詢來分析收集的數據。

    記錄和事件 ContainerLog 或 ContainerLogV2、KubeEvents、KubePodInventory 如果您已啟用受控 Prometheus 計量,建議使用 工作負載、部署和 HPA InsightsMetrics、KubePodInventory、KubeEvents、ContainerInventory、ContainerNodeInventory、KubeNodeInventory、KubeServices 永續性磁碟區 InsightsMetrics、KubePVInventory

    Azure CLI 所需的最低版本為 2.51.0。 - 針對 AKS 叢集, aks-preview 0.5.147 版或更高版本 - 針對已啟用 Arc 的 Kubernetes 和 AKS 混合式、 k8s-extension 1.4.3 版或更高版本

    AKS cluster

    當您使用 CLI 來設定 AKS 叢集的監視時,您可以使用下列格式提供設定作為 JSON 檔案。 這些數據集合參數 會說明這些設定。

    "interval": "1m", "namespaceFilteringMode": "Include", "namespaces": ["kube-system"], "enableContainerLogV2": true, "streams": ["Microsoft-Perf", "Microsoft-ContainerLogV2"]

    新的 AKS 叢集

    使用下列命令建立已啟用監視的新 AKS 叢集。 這會假設名為 dataCollection 設定.json 的組態檔

    az aks create -g <clusterResourceGroup> -n <clusterName> --enable-managed-identity --node-count 1 --enable-addons monitoring --data-collection-settings dataCollectionSettings.json --generate-ssh-keys 
    

    現有的 AKS 叢集

    沒有監視附加元件 的叢集 使用下列命令將監視新增至現有的叢集,而未啟用容器深入解析。 這會假設名為 dataCollection 設定.json 的組態檔

    az aks enable-addons -a monitoring -g <clusterResourceGroup> -n <clusterName> --data-collection-settings dataCollectionSettings.json
    

    具有現有監視附加元件 的叢集 使用下列命令,將新的組態新增至已啟用容器深入解析的現有叢集。 這會假設名為 dataCollection 設定.json 的組態檔

    # get the configured log analytics workspace resource id
    az aks show -g <clusterResourceGroup> -n <clusterName> | grep -i "logAnalyticsWorkspaceResourceID"
    # disable monitoring 
    az aks disable-addons -a monitoring -g <clusterResourceGroup> -n <clusterName>
    # enable monitoring with data collection settings
    az aks enable-addons -a monitoring -g <clusterResourceGroup> -n <clusterName> --workspace-resource-id <logAnalyticsWorkspaceResourceId> --data-collection-settings dataCollectionSettings.json
    

    已啟用 Arc 的 Kubernetes 叢集

    使用下列命令將監視新增至已啟用Arc的現有 Kubernetes 叢集。 如需可用設定的定義,請參閱 數據收集參數

    az k8s-extension create --name azuremonitor-containers --cluster-name <cluster-name> --resource-group <resource-group> --cluster-type connectedClusters --extension-type Microsoft.AzureMonitor.Containers --configuration-settings amalogs.useAADAuth=true dataCollectionSettings='{"interval":"1m","namespaceFilteringMode": "Include", "namespaces": [ "kube-system"],"enableContainerLogV2": true,"streams": ["<streams to be collected>"]}'
    

    在 Windows 電腦上部署時,必須逸出 dataCollection 設定 字段。 例如,dataCollection 設定={“interval”:“1m”,“namespaceFilteringMode”: “Include”, “namespaces”: [ “kube-system”]} 而不是 dataCollection 設定='{“interval”:“1m”,“namespaceFilteringMode”: “Include”, “namespaces”: [ “kube-system”]}'

    AKS 混合式叢集

    使用下列命令將監視新增至現有的 AKS 混合式叢集。 如需可用設定的定義,請參閱 數據收集參數

    az k8s-extension create --name azuremonitor-containers --cluster-name <cluster-name> --resource-group <resource-group> --cluster-type provisionedclusters --cluster-resource-provider "microsoft.hybridcontainerservice" --extension-type Microsoft.AzureMonitor.Containers --configuration-settings amalogs.useAADAuth=true dataCollectionSettings='{"interval":"1m","namespaceFilteringMode":"Include", "namespaces": ["kube-system"],"enableContainerLogV2": true,"streams": ["<streams to be collected>"]}'
    

    在 Windows 電腦上部署時,必須逸出 dataCollection 設定 字段。 例如,dataCollection 設定={“interval”:“1m”,“namespaceFilteringMode”: “Include”, “namespaces”: [ “kube-system”]} 而不是 dataCollection 設定='{“interval”:“1m”,“namespaceFilteringMode”: “Include”, “namespaces”: [ “kube-system”]}'

  • 使用下列命令下載 Azure Resource Manager 範本和參數檔案。 如需每個叢集組態的範本和參數檔案,請參閱下文。

    curl -L <template file> -o existingClusterOnboarding.json
    curl -L <parameter file> -o existingClusterParam.json
    

    AKS cluster

  • 樣本: https://aka.ms/aks-enable-monitoring-costopt-onboarding-template-file
  • 參數: https://aka.ms/aks-enable-monitoring-costopt-onboarding-template-parameter-file
  • 已啟用 Arc 的 Kubernetes

  • 樣本: https://aka.ms/arc-k8s-enable-monitoring-costopt-onboarding-template-file
  • 參數: https://aka.ms/arc-k8s-enable-monitoring-costopt-onboarding-template-parameter-file
  • AKS 混合式叢集

  • 樣本: https://aka.ms/existingClusterOnboarding.json
  • 參數: https://aka.ms/existingClusterParam.json
  • 編輯參數檔案中的值。 如需每個設定的詳細數據,請參閱 數據收集參數 。 如需每個叢集組態的唯一設定,請參閱下方。

    AKS cluster

  • 針對 aksResourceIdaksResourceLocation,請使用 AKS 叢集的 AKS 概觀 頁面上的值。
  • 已啟用 Arc 的 Kubernetes

  • 針對 clusterResourceIdclusterResourceLocation,請使用 AKS 混合式叢集 [ 概觀 ] 頁面上的值。
  • AKS 混合式叢集

  • 針對 clusterResourceIdclusterRegion,請使用已啟用 Arc 的 Kubernetes 叢集 [概觀] 頁面上的值。
  • 使用下列命令部署 ARM 樣本:

    az login
    az account set --subscription"Cluster Subscription Name"
    az deployment group create --resource-group <ClusterResourceGroupName> --template-file ./existingClusterOnboarding.json --parameters @./existingClusterParam.json
    收集頻率
    Cli: interval
    手臂: dataCollectionInterval 決定代理程式收集數據的頻率。 有效值為 1m - 30m,間隔為 1m,預設值為 1m。 如果值超出允許的範圍,則預設值為 1 m。 命名空間篩選
    Cli: namespaceFilteringMode
    手臂: namespaceFilteringModeForDataCollection 包含:只從命名空間欄位中的值收集數據。
    排除:從命名空間欄位中的值以外的所有命名空間收集數據
    關閉:忽略任何 命名空間 選取專案,並收集所有命名空間的數據。 命名空間篩選
    Cli: namespaces
    手臂: namespacesForDataCollection 以逗號分隔的 Kubernetes 命名空間陣列,以根據 namespaceFilteringMode 收集清查和效能數據。
    例如,命名空間 = [“kube-system”, “default”] 與 Include 設定只會收集這兩個命名空間。 使用 Exclude 設定時,代理程式會從 kube 系統預設值以外的所有其他命名空間收集數據。 使用 Off 設定時,代理程式會從所有命名空間收集數據,包括 kube-system預設值。 忽略無效和無法辨識的命名空間。 啟用 ContainerLogV2
    Cli: enableContainerLogV2
    手臂: enableContainerLogV2 布爾值旗標以啟用 ContainerLogV2 架構。 如果設定為 true,stdout/stderr 記錄會內嵌至 ContainerLogV2 數據表。 如果沒有,除非在 ConfigMap 中另有指定,否則容器記錄會內嵌至 ContainerLog 數據表。 指定個別數據流時,您必須包含 ContainerLog 或 ContainerLogV2 的對應數據表。 收集的數據
    Cli: streams
    手臂: streams 容器深入解析數據表數據流的陣列。 請參閱上述支持的數據流至數據表對應。

    適用的數據表和計量

    收集頻率命名空間篩選設定不適用於所有容器深入解析數據。 下表列出 Container Insights 所使用的 Log Analytics 工作區中的數據表,以及其收集的計量,以及套用至每個的設定。

    這項功能會設定 ContainerLog 和 ContainerLogV2 以外的所有容器深入解析數據表的設定。 若要設定這些數據表的設定,請更新代理程序數據收集設定中所述的 ConfigMap。

    對視覺效果和警示的影響

    如果您目前將上述數據表用於其他自定義警示或圖表,則修改數據收集設定可能會降低這些體驗。 如果您排除命名空間或減少數據收集頻率,請使用此數據檢閱現有的警示、儀錶板和活頁簿。

    若要掃描參考這些數據表的警示,請執行下列 Azure Resource Graph 查詢:

    resources
    | where type in~ ('microsoft.insights/scheduledqueryrules') and ['kind'] !in~ ('LogToMetric')
    | extend severity = strcat("Sev", properties["severity"])
    | extend enabled = tobool(properties["enabled"])
    | where enabled in~ ('true')
    | where tolower(properties["targetResourceTypes"]) matches regex 'microsoft.operationalinsights/workspaces($|/.*)?' or tolower(properties["targetResourceType"]) matches regex 'microsoft.operationalinsights/workspaces($|/.*)?' or tolower(properties["scopes"]) matches regex 'providers/microsoft.operationalinsights/workspaces($|/.*)?'
    | where properties contains "Perf" or properties  contains "InsightsMetrics" or properties  contains "ContainerInventory" or properties  contains "ContainerNodeInventory" or properties  contains "KubeNodeInventory" or properties  contains"KubePodInventory" or properties  contains "KubePVInventory" or properties  contains "KubeServices" or properties  contains "KubeEvents" 
    | project id,name,type,properties,enabled,severity,subscriptionId
    | order by tolower(name) asc
    
  • 請參閱 使用 ConfigMap 在容器深入解析中設定數據收集,以使用 ConfigMap 而不是 DCR 來設定資料收集。
  •