【问题标题】:Is it possible to create Azure container service(ACS) through Rest API?是否可以通过 Rest API 创建 Azure 容器服务(ACS)?
【发布时间】:2016-07-11 06:57:35
【问题描述】:

我需要使用单个 azure rest api 创建 Azure 容器服务。 是否可以?如果是,请帮助我

【问题讨论】:

    标签: azure azure-resource-manager


    【解决方案1】:

    是的,如果您只需要一个完全没有虚拟机的容器。以下 PowerShell 脚本调用此类 REST API。

    Add-Type -Path 'C:\Program Files\Microsoft Azure Active Directory Connect\Microsoft.IdentityModel.Clients.ActiveDirectory.dll'
    
    $tenantID = "<the tenant ID of your Subscription>"
    $loginEndpoint = "https://login.windows.net/"
    $managementResourceURI = "https://management.core.windows.net/"
    $redirectURI = New-Object System.Uri ("urn:ietf:wg:oauth:2.0:oob")
    $clientID = "1950a258-227b-4e31-a9cf-717495945fc2"
    $subscriptionID = "<your subscription id>"
    
    $authString = $loginEndpoint + $tenantID
    
    $authenticationContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext ($authString, $false)
    
    $promptBehaviour = [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto
    
    $userIdentifierType = [Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifierType]::RequiredDisplayableId
    
    $userIdentifier = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier ("<your azure account>", $userIdentifierType)
    
    $authenticationResult = $authenticationContext.AcquireToken($managementResourceURI, $clientID, $redirectURI, $promptBehaviour, $userIdentifier); 
    
    # construct authorization header for the REST API.
    $authHeader = $authenticationResult.AccessTokenType + " " + $authenticationResult.AccessToken
    $headers = @{"Authorization"=$authHeader; "Content-Type"="application/json"}
    
    # Invoke the REST API.
    Invoke-RestMethod -Method PUT -Uri "https://management.azure.com/subscriptions/$subscriptionID/resourceGroups/<the resource group>/providers/Microsoft.ContainerService/containerServices/<the container>?api-version=2016-03-30" -Headers $headers -infile containerService.json
    

    对于 containerService.json,这里是一个 DCOS 容器的示例。

    {
      "name": "containerservice-mooncaketeam",
      "type": "Microsoft.ContainerService/ContainerServices",
      "location": "eastasia",
      "properties": {
        "orchestratorProfile": {
          "orchestratorType": "DCOS"
        },
        "masterProfile": {
          "count": 1,
          "dnsPrefix": "jackstestmgmt",
        },
        "agentPoolProfiles": [
          {
            "name": "agentpools",
            "count": 1,
            "vmSize": "Standard_D1",
            "dnsPrefix": "jackstestagents",
          }
        ],
        "linuxProfile": {
          "ssh": {
            "publicKeys": [
              {
                "keyData": "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQEArgPsnnGrA2gbmXKEd0O1zWGmiRhfBgmGugAwC7IGcm71RjqoISHz0MKZyJbt/gvX6BKogdCAaN1rDisuOMSsd7LonkURtOJV3RszdAKtk3o+tBtrJy1RhGOIA76/5XQWaCFgoiQGGwF9KYn9VnwjwcQki2OOZIq1YJAkrZxgkNPkMKjVlmsyGJJkpSHyIpzVqZWOYVFP8mon8kll+ZUec+tPK+RYxNZQadxvUzRMvCGdHCGT274KpgnP0FgemrS9/SCJCHW4qZawANp8uBrjLwSTstqmA1uJddZ3RPZu+BgZ68EihF0wG3GsvB4tV0fBYnxRiElYn+FdaZlYbZDobw=="
              }
            ]
          },
          "adminUsername": "admin"
        }
      }
    }
    

    此 REST API 将创建 1 个容器服务、1 个可用性集、3 个网络安全组和 2 个公共 IP 地址。

    【讨论】:

      猜你喜欢
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 2019-01-23
      • 1970-01-01
      相关资源
      最近更新 更多