Enable Monitoring in AKS Cluster

You might receive the following error code and message when enabling monitoring in AKS Cluster:

azure-native:containerservice:ManagedCluster (cluster): error: 1 error occurred: * Code="AddContainerInsightsSolutionError" Message="Code="MissingSubscriptionRegistration" Message="The subscription is not registered to use namespace 'Microsoft.OperationsManagement'. See https://aka.ms/rps-not-found for how to register subscriptions." Details=[{"code":"MissingSubscriptionRegistration","message":"The subscription is not registered to use namespace 'Microsoft.OperationsManagement'. See https://aka.ms/rps-not-found for how to register subscriptions.","target":"Microsoft.OperationsManagement"}]"

This describes resource provider registration errors that occur when you use a resource provider that you haven't already used in your Azure subscription. More detail at https://learn.microsoft.com/en-us/azure/azure-resource-manager/troubleshooting/error-register-resource-provider?tabs=azure-cliarrow-up-right

To enable monitoring, logs, and metrics in Azure Kubernetes Service (AKS), you need to integrate the AKS cluster with Azure Monitor. This includes:

  • Monitoring Logs: Logs from your AKS cluster, including Kubernetes and container logs, will be sent to Azure Monitor logs.

  • Metrics: Performance metrics such as CPU, memory usage, and other AllMetrics are sent to Azure Monitor for insights into the cluster and node health.

Azure Monitor collects metrics, logs, and insights from your AKS cluster and provides visibility into your cluster’s performance, reliability, and security.

Create Log Analytics Workspace

Azure Monitor requires a Log Analytics Workspace to collect and analyze logs and metrics. In Pulumi, you can create this workspace and link it to your AKS cluster. You will open aksCluster.ts file, and modify the following code:

...

export const aksCluster = (
    resourceGroupName: pulumi.Input<string>, 
    subnetIds: {
        nodeSubnetId: pulumi.Output<string>,
        podSubnetId: pulumi.Output<string>
    }) => {
    // Create a Log Analytics Workspace
    const logAnalyticsWorkspace = new azure_native.operationalinsights.Workspace("myLogAnalyticsWorkspace", {
        resourceGroupName: resourceGroupName,
        location: config.location,
        sku: {
            name: "PerGB2018",
        },
        retentionInDays: 30,  // Adjust log retention as needed
    });
    ...
    return new containerservice.ManagedCluster("cluster", {
        resourceGroupName: resourceGroupName,
        ...
        // Enable Monitoring with Log Analytics
        addonProfiles: {
            omsAgent: { // Configures the monitoring agent to collect logs and metrics
                enabled: true,
                config: {
                    logAnalyticsWorkspaceResourceID: logAnalyticsWorkspace.id,
                },
            },
        },
    });
};

With the monitoring agent enabled, your AKS cluster will start sending logs and metrics to Azure Monitor. Azure Monitor collects:

  • Pod logs and container logs.

  • Kubernetes resource logs (such as events and audit logs).

  • Metrics for CPU, memory, disk usage, and network performance (AllMetrics).

The logs and metrics are accessible from the Azure Monitor section in the Azure portal under "Logs" and "Metrics".

Finally, deploy your AKS cluster using the Pulumi CLI.

Viewing Logs and Metrics

Once the monitoring is enabled, you can view the logs and metrics in the Azure Monitor section of the Azure portal:

  • Container Logs: Navigate to Azure Monitor > Logs and select Kubernetes Services.

  • AllMetrics: Go to Azure Monitor > Metrics to view performance metrics for your AKS cluster.

You can filter by CPU Usage, Memory Usage, Node Health, Pod Status, etc., from the collected metrics and create alerts if required.

Last updated