我正在尝试使用Azure管理API创建Kubernetes集群。

  var credentials = SdkContext.AzureCredentialsFactory
    .FromFile(Environment.GetEnvironmentVariable("AZURE_AUTH_LOCATION"));


  var azure = Azure
    .Configure()
    .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
    .Authenticate(credentials)
    .WithDefaultSubscription();

var kubernetesCluster = azure.KubernetesClusters.Define("aks").WithRegion(Region.EuropeWest)
        .WithNewResourceGroup("aksResourceGroup").WithLatestVersion().WithRootUsername("aksUsername")
        .WithSshKey(sshPublicKey).WithServicePrincipalClientId("clientId")
        .WithServicePrincipalSecret("secret").DefineAgentPool("ap").WithVirtualMachineCount(1)
        .WithVirtualMachineSize(ContainerServiceVirtualMachineSizeTypes.StandardA0).Attach()
        .WithDnsPrefix("dns-aks").Create();

在最后一行中,将引发CloudException消息:找不到Subscription []。

即使引发异常,也会创建资源组,但资源组为空。

我已使用带有该服务主体的Azure CLI登录并且已经运行
az account list

具有以下响应:
[
  {
    "cloudName": "AzureCloud",
    "id": "SUBSCRIPTION ID FROM EXCEPTION ABOVE",
    "isDefault": true,
    "name": "Pay-As-You-Go",
    "state": "Enabled",
    "tenantId": "xxx",
    "user": {
      "name": "xxxx",
      "type": "servicePrincipal"
    }
  }
]

应用程序注册位于Azure Active Directory>应用程序注册>所有应用程序中。我什至授予了所有可能的API的权限。

为了接收该异常消息,我做错了什么吗?

最佳答案

根据错误日志,您似乎没有为服务主体设置默认订阅。您可以使用az account set --subscription <name or id>进行设置。

如果仍然无法正常工作,建议您使用以下代码。

  var azure = Azure
    .Configure()
    .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
    .Authenticate(credentials)
    .withSubscription("subscription id")

注意:您应该在订阅级别上赋予服务主体所有者角色。看到这个link。但看来您已完成,但我建议您可以再次检查。

关于azure - 在Azure管理API中找不到订阅,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49615220/

10-11 06:43
查看更多