使用 Rest 的 Azure 容器服务 API
Azure Container Service using Rest API
我想用特定 Orchestrator Kubernetes 集群的资源组和集群创建 azure 容器。
我知道使用 CLI 是可行的,但我想使用 Azure Rest API 的容器服务从 link 此处给出
docs.microsoft.com/en-us/rest/api/container-service/containerservices/createorupdate
在 AAD 中注册了我的应用程序并授予了所需的权限。
根据 link
获得访问令牌并向 api 发出请求
PUT management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}?api-version =2017-01-31
但我收到错误
{
"error": {
"code": "InvalidResource"
"message": "The resource definition is invalid."
}
}
我知道当请求正文中没有任何内容时我们会收到此错误。
所以我真正的问题是我是否想使用 API 请求创建具有资源组和集群的容器服务。
请求正文
{
"id": "myCluster",
"name": "myCluster",
"type": "Microsoft.ContainerService/containerServices",
"location": "southindia",
"tags": {
"tag": "test"
},
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes"
},
"servicePrincipalProfile": {
"clientId": "<clientid>,
"secret": "<secret>"
},
"masterProfile": {
"count": 1,
"dnsPrefix": "testabc"
},
"agentPoolProfiles": {
"name": "agentPool1234",
"count": 2,
"vmSize": "Standard_A1",
"dnsPrefix": "testabcagents"
},
"linuxProfile": {
"adminUsername": "kubeadmin",
"ssh": {
"publicKeys": [
{
"keyData": "sshkey"
}
]
}
}
}
}
获得响应
{
"code": "BadRequest",
"message": "An error has occurred in subscription <subscriptionid>, resourceGroup: tobeDeletedResourceGroup request: OrchestratorType has unknown orchestrator: ."
}
请帮我解决这个问题
agentPoolProfiles 应该是 json 个对象的数组。我从 azure-cli's mock unit tests 中提取了这个示例,以帮助您提供一个参考框架。
https://gist.github.com/bacongobbler/470b8d139536144edf91174916ec4036
Azure REST API 文档中缺少两件事。
1) 它需要像这样的 orchestratorRelease 版本和 orchestratorType。 "orchestratorProfile": {
"orchestratorType": "Kubernetes",
"orchestratorRelease": "1.7"
}
2) 下一个错误是 Properties.MasterProfile.VMSize 中缺少 vmSize。
所以我在 json
添加了以下更新
"masterProfile": {
"count": 1,
"dnsPrefix": "testabc",
"vmSize": "Standard_D2_v2"
}
文档中缺少这 2 个重要的 json 参数,这非常令人惊讶和恼火。
我想用特定 Orchestrator Kubernetes 集群的资源组和集群创建 azure 容器。
我知道使用 CLI 是可行的,但我想使用 Azure Rest API 的容器服务从 link 此处给出
docs.microsoft.com/en-us/rest/api/container-service/containerservices/createorupdate
在 AAD 中注册了我的应用程序并授予了所需的权限。
根据 link
获得访问令牌并向 api 发出请求PUT management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}?api-version =2017-01-31 但我收到错误
{
"error": {
"code": "InvalidResource"
"message": "The resource definition is invalid."
}
}
我知道当请求正文中没有任何内容时我们会收到此错误。
所以我真正的问题是我是否想使用 API 请求创建具有资源组和集群的容器服务。
请求正文
{
"id": "myCluster",
"name": "myCluster",
"type": "Microsoft.ContainerService/containerServices",
"location": "southindia",
"tags": {
"tag": "test"
},
"properties": {
"orchestratorProfile": {
"orchestratorType": "Kubernetes"
},
"servicePrincipalProfile": {
"clientId": "<clientid>,
"secret": "<secret>"
},
"masterProfile": {
"count": 1,
"dnsPrefix": "testabc"
},
"agentPoolProfiles": {
"name": "agentPool1234",
"count": 2,
"vmSize": "Standard_A1",
"dnsPrefix": "testabcagents"
},
"linuxProfile": {
"adminUsername": "kubeadmin",
"ssh": {
"publicKeys": [
{
"keyData": "sshkey"
}
]
}
}
}
}
获得响应
{
"code": "BadRequest",
"message": "An error has occurred in subscription <subscriptionid>, resourceGroup: tobeDeletedResourceGroup request: OrchestratorType has unknown orchestrator: ."
}
请帮我解决这个问题
agentPoolProfiles 应该是 json 个对象的数组。我从 azure-cli's mock unit tests 中提取了这个示例,以帮助您提供一个参考框架。
https://gist.github.com/bacongobbler/470b8d139536144edf91174916ec4036
Azure REST API 文档中缺少两件事。 1) 它需要像这样的 orchestratorRelease 版本和 orchestratorType。 "orchestratorProfile": { "orchestratorType": "Kubernetes", "orchestratorRelease": "1.7" } 2) 下一个错误是 Properties.MasterProfile.VMSize 中缺少 vmSize。 所以我在 json
添加了以下更新"masterProfile": { "count": 1, "dnsPrefix": "testabc", "vmSize": "Standard_D2_v2" }
文档中缺少这 2 个重要的 json 参数,这非常令人惊讶和恼火。