我需要使用单个azure rest api创建Azure容器服务。 可能吗?如果是的话,请帮帮我
答案 0 :(得分:2)
是的,如果您只需要一个没有虚拟机的容器。以下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地址。