AKS icon indicating copy to clipboard operation
AKS copied to clipboard

[BUG] Cost Analysis Addon: Disk Zone Attachment Issue with Availability Zones

Open torumakabe opened this issue 1 year ago • 8 comments

The AKS Cost Analysis addon experiences volume attachment failures when deployed in clusters with availability zones enabled. The cost-analysis-agent pod gets stuck in ContainerCreating state due to disk zone mismatch errors.

Symptom

  • Cost analysis addon pod stuck in ContainerCreating state
  • Pod fails to schedule with volume attachment errors
  • Error message example: Disk cannot be attached to the VM because it is not in zone '2'

The managed cost analysis addon initially creates a PersistentVolumeClaim (PVC) using Standard_LRS storage class without zone specification. This causes cross-zone attachment failures when the pod is scheduled on a node in a different availability zone than where the disk was created.

Events:
  Type     Reason              Age                  From                     Message
  ----     ------              ----                 ----                     -------
  Warning  FailedAttachVolume  2m43s (x6 over 4m)  attachdetach-controller  AttachVolume.Attach failed for volume "pvc-xxx-xxx-xxx-xxx-xxx": rpc error: code = Unknown desc = Disk cannot be attached to the VM because it is not in zone '2'

Steps to Reproduce

Create AKS cluster with availability zones enabled

resource aksCluster 'Microsoft.ContainerService/managedClusters@2024-02-01' = {
  name: clusterName
  location: location
  properties: {
    agentPoolProfiles: [{
      availabilityZones: ['1', '2', '3']
      // other configurations
    }]
    metricsProfile: {
      costAnalysis: {
        enabled: true
      }
    }
  }
}

Expected behavior The cost analysis addon should automatically detect when a cluster has availability zones enabled and:

  • Use zone-redundant storage (StandardSSD_ZRS) for PVC creation
  • or Use storage classes with volumeBindingMode: WaitForFirstConsumer for multi-zone clusters
  • Properly handle cross-zone pod scheduling without volume attachment failures
  • Ensure seamless operation without requiring manual intervention

Environment

  • Region: Japan East (japaneast)
  • Kubernetes Version: 1.33.2
  • Availability Zones: 1, 2, 3

torumakabe avatar Aug 22 '25 07:08 torumakabe

After recreating the cluster, the parameters were as expected. The reason isn’t clear, but since it’s resolved, I’ll close this.

Image

torumakabe avatar Aug 24 '25 02:08 torumakabe

Issue Recurrence with Comprehensive Evidence

Summary

The same issue has recurred on a newly created AKS cluster (created 2025-09-30), 2 months after the original report. This time, we have gathered evidence.

Environment

  • Region: Japan East (japaneast)
  • Kubernetes Version: 1.31.11
  • Cluster Creation: 2025-09-30
  • Issue Discovery: 2025-10-08
  • Affected Component: Cost Analysis Agent (ama-metrics addon)

Evidence 1: StorageClass Correctly Specifies ZRS

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: default
parameters:
  skuname: StandardSSD_ZRS  # ✅ Correct specification
volumeBindingMode: WaitForFirstConsumer

Evidence 2: CSI Driver Received and Processed ZRS Correctly

# From PersistentVolume
apiVersion: v1
kind: PersistentVolume
spec:
  csi:
    driver: disk.csi.azure.com
    volumeAttributes:
      skuname: StandardSSD_ZRS  # ✅ CSI driver has correct parameter

Evidence 3: CSI Driver Set Correct ZRS Topology

# From PersistentVolume nodeAffinity
nodeAffinity:
  required:
    nodeSelectorTerms:
    - matchExpressions:
      - key: topology.disk.csi.azure.com/zone
        operator: In
        values:
        - japaneast-1
        - japaneast-2
        - japaneast-3
        - ""  # 4-zone topology = v1.31.12+ ZRS behavior ✅

This proves the CSI driver executed the v1.31.12+ code path for ZRS disks correctly.

Evidence 4: Azure Disk API Created Wrong SKU?

// From Azure Disk resource
{
  "name": "pvc-2d4ca295-3556-4b93-a6e5-0e24dd19b1eb",
  "sku": {
    "name": "Standard_LRS"  // ❌ may be WRONG
  },
  "zones": null,
  "properties": {
    "diskState": "Unattached",
    "timeCreated": "2025-09-30T08:30:27Z"
  }
}

Critical Finding: Despite CSI driver requesting StandardSSD_ZRS, Azure created Standard_LRS.

Evidence 5: No Error Was Returned

# PVC Status
status:
  phase: Bound  # ✅ Shows successful binding

The PVC shows Bound status, meaning the disk creation appeared successful to Kubernetes. No error was propagated.

torumakabe avatar Oct 08 '25 02:10 torumakabe

I’m not sure whether this is a supported operation, but after deleting and recreating the cost-analysis-agent-victoria-metrics PVC, it came up as StandardSSD_ZRS. Are there any conditions or known issues that could cause it to end up as Standard_LRS instead?

torumakabe avatar Oct 08 '25 02:10 torumakabe

@kaysieyu, what is the expected behavior when enabling the cost analysis add-on in a cluster with availability zones enabled? Should it default to the ZRS disk rather than LRS?

julia-yin avatar Oct 09 '25 20:10 julia-yin

Any updates? Whenever the Pod is recreated, such as during cluster updates, it stops due to volume issues, so it’s not viable for production use.

torumakabe avatar Nov 14 '25 02:11 torumakabe

Any updates? Whenever the Pod is recreated, such as during cluster updates, it stops due to volume issues, so it’s not viable for production use.

torumakabe avatar Dec 14 '25 23:12 torumakabe

This issue has been automatically marked as stale because it has not had any activity for 30 days. It will be closed if no further activity occurs within 7 days of this comment. Please review @kaysieyu.

This issue will now be closed because it hasn't had any activity for 7 days after stale. @torumakabe feel free to comment again on the next 7 days to reopen or open a new issue after that time if you still have a question/issue or suggestion.

Reopen Request: Issue Still Reproducible with Evidence

This issue was closed by the stale bot without any technical resolution from the Azure team. The problem is still reproducible as of January 2026.

Environment

  • Region: Japan East
  • Kubernetes Version: 1.33.2
  • Cluster Creation: 2026-01-22

Current Evidence

1. Pod stuck in ContainerCreating (25+ hours)

NAME                                   READY   STATUS              RESTARTS   AGE
cost-analysis-agent-546c469f47-2pvl6   0/3     ContainerCreating   0          25h

2. StorageClass correctly specifies ZRS

parameters:
  skuname: StandardSSD_ZRS  # ✅ Correct
volumeBindingMode: WaitForFirstConsumer

3. CSI Driver processed ZRS correctly (PV shows correct config)

csi:
  volumeAttributes:
    skuname: StandardSSD_ZRS  # ✅ CSI received correct parameter
nodeAffinity:
  # ✅ Multi-zone topology for ZRS
  values: [japaneast-1, japaneast-2, japaneast-3, japaneast-4, ""]

4. Azure Disk API created WRONG SKU

{
  "sku": "Standard_LRS",  // ❌ Should be StandardSSD_ZRS
  "zones": null
}

5. Attachment failure (zone mismatch)

Disk cannot be attached to the VM because it is not in zone '2'.

Root Cause Analysis

The CSI Driver correctly requests StandardSSD_ZRS, but Azure Disk API silently creates Standard_LRS without returning an error. The PVC shows Bound status, masking the failure until pod scheduling.

Impact

  • Production blocker: Pod fails after every cluster upgrade or node rotation
  • Silent failure: No error is surfaced until attachment time
  • No workaround: Users cannot override managed addon PVC settings

Request

Please reopen this issue. The stale bot closure does not reflect technical resolution—@kaysieyu never responded to the technical questions raised in October 2025.

cc: @julia-yin

torumakabe avatar Jan 26 '26 02:01 torumakabe

We hit the same problem and ask to reopen this. It is still unresolved.

What we saw (AKS, Kubernetes 1.33, system pool across 3 zones)

cost-analysis-agent stayed Pending after the system pool moved to availability zones. The add-on's PVC (cost-analysis-agent-victoria-metrics, kube-system) was bound to a single-zone StandardSSD_LRS disk pinned to one zone. No system node was left in that zone. Deleting the PVC and the pending pod let the add-on re-create it, and the agent came back. We lost the metrics history. The new disk is single-zone again, so this will happen again. Why it keeps coming back

Our system pool has 2 nodes over 3 zones and takes node-image upgrades. Any upgrade that leaves no system node in the disk's zone strands the agent. Cost data stops until someone notices. We cannot change the add-on's storage class. A manual change does not survive the add-on's reconciliation. What would fix it for us (either one)

The add-on provisions its metrics disk as StandardSSD_ZRS, so it attaches in any zone. A supported setting for the volume's storage class that survives reconciliation. WaitForFirstConsumer alone does not help after the disk exists. The disk stays in its first zone.

We also have a Microsoft support case open for this. The product group has been engaged, but we have no status or work item to follow. Could a maintainer say whether a fix is planned, and link the tracking item?

msci-horvrud avatar Nov 17 '26 14:11 msci-horvrud