azureazure-aksazure-monitoringconfigmap

How to customize ConfigMap for Container insights using Azure Monitor Agent on AKS?


To collect logs from the AKS container application insights can be enabled. This automatically creates a deployment called ama-logs-rs This deployment has an associated ConfigMap: ama-logs-rs-config

The Terraform resource for deploying the cluster and node pool does not have any options to configure any settings of the monitoring agent.

The suggestion from Microsoft seems to be to edit it manually, as described here

However, that does not ensure that for every node scaling event these settings are automatically transferred, which means that either you constantly have to manually check and update the ConfigMap, or write some custom job that does this periodically or based on some triggers.

Is there a better way to customize specific settings for the ama on AKS?


Solution

  • A custom config map is the way to go, but using the correct name is important.

    The deployment that controls the ama pods has some default optional mounts, one of them is the config map "container-azm-ms-agentconfig"

    By default the configmap does not exist, but if you create it, it is automatically picked up.

    This is the very minimal configmap we used in the end:

    apiVersion: v1
    data:
        log-data-collection-settings: |-
            # Log data collection settings
            #     # Any errors related to config map settings can be found in the KubeMonAgentEvents table in the Log Analytics workspace that the cluster is sending data to.
            #         # For additional setting see: https://raw.githubusercontent.com/microsoft/Docker-Provider/ci_prod/kubernetes/container-azm-ms-agentconfig.yaml
    
            [log_collection_settings]
              [log_collection_settings.env_var]
                # In the absense of this configmap, default value for enabled is true
                enabled = false
    kind: ConfigMap
    metadata:
      name: container-azm-ms-agentconfig
      namespace: kube-system
    

    kubectl describe deploy ama-logs-rs

    OUT

    Volumes:
    ...
        settings-vol-config:
            Type:      ConfigMap (a volume populated by a ConfigMap)
            Name:      container-azm-ms-agentconfig
            Optional:  true