Edit

Troubleshoot high CPU usage in AKS clusters

Note

This article discusses high CPU utilization. In many situations, CPU Pressure Stall Information (PSI) metrics provide a more accurate indication of CPU pressure than utilization alone. For more information, see Troubleshoot CPU pressure in AKS clusters using PSI metrics.

Summary

High CPU usage is a symptom of one or more applications or processes that require so much CPU time that the performance or usability of the machine is impacted. High CPU usage can occur in many ways, but user configuration mostly causes it.

When a node in an Azure Kubernetes Service (AKS) cluster experiences high CPU usage, the applications running on it can experience degradation in performance and reliability. Applications or processes also become unstable, which might lead to problems beyond slow responses.

This article helps you identify the nodes and containers that consume high CPU and provides best practices to resolve high CPU usage.

Symptoms

The following table outlines the common symptoms of high CPU usage:

Symptom Description
CPU starvation CPU-intensive applications slow down other applications on the same node.
Slow state changes Pods may take longer to get ready.
NotReady node state Severe CPU contention can starve the kubelet of CPU time and prevent it from sending timely status updates to the API server. As a result, the node might be marked NotReady.

Troubleshoot high CPU usage in AKS

To resolve high CPU usage, use effective monitoring tools and apply best practices.

Step 1: Identify nodes and containers with high CPU usage

Use either of the following methods to identify nodes and containers with high CPU usage:

  • In a web browser, use the Container Insights feature of AKS in the Azure portal.

  • In a console, use the Kubernetes command-line tool (kubectl).

Container Insights is a feature within AKS. It's designed to monitor the performance of container workloads. Use Container Insights to identify nodes, containers, or pods that drive high CPU usage.

To identify nodes, containers, or pods that drive high CPU usage, follow these steps:

  1. Go to the cluster from the Azure portal.

  2. Under Monitoring, select Insights.

    Screenshot of the Monitoring under Insights.

  3. Set the appropriate Time range.

    Screenshot of a time range of six hours.

  4. Find the nodes with high CPU usage and check if the node CPU usage is stable.

    Select Nodes. Set Metric to CPU Usage (millicores) and then set the sample to Max. Use the sort feature on the Max to order the nodes by Max%. The nodes with the highest CPU usage appear at the top.

    In the following screenshot, the node uses only 12% of the max CPU and has been running for 16 days.

    Screenshot of the Nodes under the Monitoring selection.

  5. After you find the nodes with high CPU usage, select the nodes to find pods on them and their CPU usage.

    Screenshot of the insights option for pods under the Monitoring selection.

    Note

    The percentage of CPU or memory usage for pods is based on the CPU request specified for the container. It doesn't represent the percentage of the CPU or memory usage for the node. So, look at the actual CPU or memory usage rather than the percentage of CPU or memory usage for pods.

    After you get the list of pods with high CPU usage, you can map it to the applications that cause the spike in CPU usage.

Step 2: Review best practices to avoid high CPU usage

Review the following table to learn how to implement best practices for avoiding high CPU usage:

Best practice Description
Set appropriate requests and limits for containers CPU requests help Kubernetes schedule workloads and determine CPU allocation during contention. CPU limits restrict the maximum CPU a container can consume and can result in throttling. Configure requests and limits according to the workload's observed requirements and choose the appropriate Kubernetes Quality of Service (QoS) class for each pod.
Enable Horizontal Pod Autoscaler (HPA) Set appropriate CPU requests and use HPA for workloads that can scale horizontally. Verify that the workload hasn't reached its configured maximum replica count and that the cluster has sufficient capacity for additional replicas.
Increase or adjust node-pool capacity If the workload requires more CPU capacity, consider adding nodes, selecting a VM size with more or more appropriate CPU resources, or moving the workload to a dedicated node pool.
Isolate system and user workloads Run application workloads on user node pools and reserve system node pools for critical system workloads. This separation reduces the risk that application CPU usage affects Kubernetes system components.

References