【问题标题】:Subscription could not be found in Azure Management API在 Azure 管理 API 中找不到订阅
【发布时间】:2018-04-02 16:46:03
【问题描述】:

我正在尝试使用 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 并显示消息:找不到订阅 []。

即使抛出异常,也会创建资源组但它是空的。

我已经使用带有该服务主体的 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 的权限。

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

【问题讨论】:

    标签: azure kubernetes azure-container-service azure-management


    【解决方案1】:

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

    如果还是不行,建议你使用下面的代码。

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

    注意:您应该在订阅级别赋予您的服务主体所有者角色。请参阅此link。不过好像你已经做到了,但我建议你可以再检查一下。

    【讨论】:

    • 我已尝试使用 Azure CLI 创建另一个服务主体,我已按照您所说的设置订阅。服务主体是所有者。 imgur.com/a/6vNzx 。仍然抛出异常。
    • 您是否尝试使用.withSubscription("subscription id") 设置订阅ID?
    • 是的。来自异常的内部响应属性我得到 {“code”:“BadRequest”,“message”:“找不到订阅 c83fbcef-1664-4ccf-bf94-439b37XXXXXX。” }
    • 如何设置授权文件,看来你配置有问题。检查此链接github.com/Azure/azure-libraries-for-net/blob/master/AUTH.md
    • 或在 GitHub 上查看 project。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-17
    • 1970-01-01
    • 2022-10-18
    • 1970-01-01
    • 1970-01-01
    • 2016-09-12
    • 1970-01-01
    相关资源
    最近更新 更多