Azure Container Service using Rest API

972 views Asked by At

I would like to create azure container with resource group and cluster of specific Orchestrator Kubernetes cluster.

I know by using CLI its possible but I want to do this using Azure Rest API's for Container service from link given here

learn.microsoft.com/en-us/rest/api/container-service/containerservices/createorupdate

Registered my app in AAD and gave required permissions.

Got access token and making request to below api as per link

PUT management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ContainerService/containerServices/{containerServiceName}?api-version=2017-01-31 but I am getting error as

{
"error":  {
"code": "InvalidResource"
"message": "The resource definition is invalid."
}
}

I understand we get this error when there is nothing in request body.

So my real question here is if I want to create container service with resource group and cluster using API request.

Request Body

    {
  "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"
          }
        ]
      }
    }
  }
}

Response getting

{
    "code": "BadRequest",
    "message": "An error has occurred in subscription <subscriptionid>, resourceGroup: tobeDeletedResourceGroup request: OrchestratorType has unknown orchestrator: ."
    }

Please help me out on this

2

There are 2 answers

0
Bhushan Gholave On BEST ANSWER

Two things are missing from Azure REST API documentation. 1) It requires version of orchestratorRelease with orchestratorType like this. "orchestratorProfile": { "orchestratorType": "Kubernetes", "orchestratorRelease": "1.7" } 2) Next error i got about missing vmSize in Properties.MasterProfile.VMSize. So I have added following updates to json

"masterProfile": { "count": 1, "dnsPrefix": "testabc", "vmSize": "Standard_D2_v2" }

Its very surprising and annoying that documentation is missing these 2 important json parameters.

1
bacongobbler On

agentPoolProfiles should be an array of json objects. I pulled this example from azure-cli's mock unit tests to help give you a frame of reference.

https://gist.github.com/bacongobbler/470b8d139536144edf91174916ec4036