microsoft/aspire · error

Found AKS clusters named ' ' in subscription ' ' (resource…

Error message

Found {resourceGroups.Length} AKS clusters named '{clusterName}' in subscription '{subscriptionId}' (resource groups: {string.Join(", ", resourceGroups)}). Specify which one to use by calling AsExistingInResourceGroup on the resource.

What it means

The resource-group lookup query matched more than one AKS cluster with the same name in the subscription (clusters can share names across resource groups). Aspire refuses to pick one arbitrarily - kubeconfig credentials would silently target an unrelated cluster - so it throws and asks the developer to disambiguate via AsExistingInResourceGroup.

Solutions

  1. Call AsExistingInResourceGroup("<resource-group>") on the AzureKubernetesEnvironmentResource to pin the exact resource group.
  2. Rename one of the duplicate clusters (or delete the stale one) so the name is unique in the subscription.
  3. Verify which duplicates are legitimate with `az aks list --query "[?name=='<clusterName>'].{name:name,rg:resourceGroup}" -o table`.
  4. Use distinct cluster names per environment/branch to prevent recurrence.

Example fix

// before
var aks = builder.AddAzureKubernetesEnvironment("aks");

// after
var aks = builder.AddAzureKubernetesEnvironment("aks")
    .AsExistingInResourceGroup("my-cluster-rg");
Defensive patterns

Strategy: validation

Validate before calling

// disambiguate before running the pipeline
var aks = builder.AddAzureKubernetesEnvironment("aks")
    .AsExistingInResourceGroup("my-cluster-rg");

Prevention

When it happens

Trigger: resourceGroup property queried when `az resource list` returns 2+ resource groups for the same AKS cluster name in the resolved subscription, and the AzureKubernetesEnvironmentResource was not explicitly bound to a resource group with AsExistingInResourceGroup.

Common situations: Dev/test environments reusing the same cluster name in multiple resource groups (e.g. per-branch RGs); re-created clusters where the old RG still exists; shared team subscription with duplicate names from different people.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/a2b4681b4dd25841. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Kubernetes/AzureKubernetesEnvironmentResource.AksPipeline.cs:931

        // With '-o tsv' the query emits one resource group per matching cluster, newline separated:
        //   my-rg
        //   other-rg
        // A cluster name is only unique within a resource group, not within a subscription, so the
        // query can legitimately return several rows. Picking one would silently deploy into, and
        // hand back credentials for, an unrelated cluster.
        var resourceGroups = result.StandardOutput
            .Split('\n', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);

        if (resourceGroups.Length == 0)
        {
            throw new InvalidOperationException(
                $"Could not resolve resource group for AKS cluster '{clusterName}'. " +
                "Ensure Azure provisioning has completed.");
        }

        if (resourceGroups.Length > 1)
        {
            throw new InvalidOperationException(
                $"Found {resourceGroups.Length} AKS clusters named '{clusterName}' in subscription " +
                $"'{subscriptionId}' (resource groups: {string.Join(", ", resourceGroups)}). " +
                "Specify which one to use by calling AsExistingInResourceGroup on the resource.");
        }

        return resourceGroups[0];
    }

    /// <summary>
    /// Fetches the kubeconfig content for the cluster from the Azure CLI.
    /// </summary>
    /// <remarks>
    /// <paramref name="runAzCommandAsync"/> is injected so tests can verify that the credential
    /// fetch is scoped to the deployment subscription without invoking the real az CLI.
    /// </remarks>
    internal static async Task<string> FetchKubeConfigAsync(
        string azPath,
        string subscriptionId,

View on GitHub (pinned to 25830f84bd)