How to fix 400 Client Error in managed_clusters.create_or_update?

Samuel.Yan 61 Reputation points
2021-10-06T05:59:05.693+00:00

I want to use python sdk to create kubernetes cluster with some custom settings.

The az command is:

az aks create --name ips-cluster-uogbsm1632030000 -g ips-cluster-uogbsm1632030000_group --vm-set-type AvailabilitySet --network-plugin azure --load-balancer-sku Standard --node-vm-size Standard_B2s --max-pods 100 --node-count 2

And this is my python code:

cluster_params = ss = {
    'dns_prefix': 'ips',
    'tags': {},
    'kubernetes_version': '1.20.9',
    'agent_pool_profiles': [{
        'name': 'agent-pool',
        'count': 2,
        'vm_size': 'Standard_B2s',
        'os_disk_size_gb': 128,
        'storage_profile': 'ManagedDisks',
        'max_pods': 100,
        'min_count': 1,
        'max_count': 100,
        'os_type': 'Linux',
        'type': 'AvailabilitySet',
        'enable_auto_scaling': False,
        'mode': 'System'
    }],
    'service_principal_profile': {'client_id': '6a619736-XXXX-XXXX-XXXX-XXXXXXXXXXXX',
                                  'secret': 'XXX-XXX-XXXX'},
    'network_profile': {'network_plugin': 'azure', 'service_cidr': '10.0.0.0/16', 'dns_service_ip': '10.0.0.10',
                        'docker_bridge_cidr': '172.17.0.1/16'}, 'location': 'eastasia'}

managed_cluster_create = container_client.managed_clusters.create_or_update(
    resource_group_name='ips-cluster-uogbsm1632030000_group',
    resource_name='ips-cluster-uogbsm1632030000',
    parameters=cluster_params
)
managed_cluster_create.wait()

But I get a 400 error and there is no more detail about my post data.

msrestazure.azure_exceptions.CloudError: 400 Client Error: Bad Request for url

Note:my api version is 2018-03-31.

Questions:

1 How to check my cluster config for variable cluster_params, is there a tool?

2 And is there a api to call az command.

client =Xxx.Client()
response = client.execute('az aks create ...')
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
1,975 questions
0 comments No comments
{count} votes

Accepted answer
  1. SRIJIT-BOSE-MSFT 4,331 Reputation points Microsoft Employee
    2021-10-06T07:39:34.85+00:00

    @Samuel.Yan , thank you for your question.

    1 How to check my cluster config for variable cluster_params, is there a tool?

    At the time of writing, there is no out-of-box tool to validate AKS python SDK method parameters. However, in this particular case, you might want to check out the azure.mgmt.containerservice.v2021_08_01.operations.managedclustersoperations begin_create_or_update method's inputs and their formats.

    The parameters Parameter to the method should be a ManagedCluster object with the following Constructor:

    ManagedCluster(*, location: str, tags: typing.Union[typing.Dict[str, str], NoneType] = None, sku: typing.Union[_ForwardRef('ManagedClusterSKU'), NoneType] = None, extended_location: typing.Union[_ForwardRef('ExtendedLocation'), NoneType] = None, identity: typing.Union[_ForwardRef('ManagedClusterIdentity'), NoneType] = None, kubernetes_version: typing.Union[str, NoneType] = None, dns_prefix: typing.Union[str, NoneType] = None, fqdn_subdomain: typing.Union[str, NoneType] = None, agent_pool_profiles: typing.Union[typing.List[_ForwardRef('ManagedClusterAgentPoolProfile')], NoneType] = None, linux_profile: typing.Union[_ForwardRef('ContainerServiceLinuxProfile'), NoneType] = None, windows_profile: typing.Union[_ForwardRef('ManagedClusterWindowsProfile'), NoneType] = None, service_principal_profile: typing.Union[_ForwardRef('ManagedClusterServicePrincipalProfile'), NoneType] = None, addon_profiles: typing.Union[typing.Dict[str, _ForwardRef('ManagedClusterAddonProfile')], NoneType] = None, pod_identity_profile: typing.Union[_ForwardRef('ManagedClusterPodIdentityProfile'), NoneType] = None, node_resource_group: typing.Union[str, NoneType] = None, enable_rbac: typing.Union[bool, NoneType] = None, enable_pod_security_policy: typing.Union[bool, NoneType] = None, network_profile: typing.Union[_ForwardRef('ContainerServiceNetworkProfile'), NoneType] = None, aad_profile: typing.Union[_ForwardRef('ManagedClusterAADProfile'), NoneType] = None, auto_upgrade_profile: typing.Union[_ForwardRef('ManagedClusterAutoUpgradeProfile'), NoneType] = None, auto_scaler_profile: typing.Union[_ForwardRef('ManagedClusterPropertiesAutoScalerProfile'), NoneType] = None, api_server_access_profile: typing.Union[_ForwardRef('ManagedClusterAPIServerAccessProfile'), NoneType] = None, disk_encryption_set_id: typing.Union[str, NoneType] = None, identity_profile: typing.Union[typing.Dict[str, _ForwardRef('UserAssignedIdentity')], NoneType] = None, private_link_resources: typing.Union[typing.List[_ForwardRef('PrivateLinkResource')], NoneType] = None, disable_local_accounts: typing.Union[bool, NoneType] = None, http_proxy_config: typing.Union[_ForwardRef('ManagedClusterHTTPProxyConfig'), NoneType] = None, security_profile: typing.Union[_ForwardRef('ManagedClusterSecurityProfile'), NoneType] = None, public_network_access: typing.Union[str, _ForwardRef('PublicNetworkAccess'), NoneType] = None, **kwargs)  
    

    You can find the begin_create_or_update method definition here.

    2 And is there a api to call az command.

    client =Xxx.Client()  
    response = client.execute('az aks create ...')  
    

    Azure CLI is a client side command-line tool (written using Azure Python SDK) which can make REST API calls to the Azure Resource Manager

    The definition for Azure CLI's aks_create method in /azure-cli/azure/cli/command_modules/acs/custom.py is as detailed here. Thus, in the end it will go back to using the Azure Python SDK.

    ----------

    Hope this helps.

    Please "Accept as Answer" if it helped, so that it can help others in the community looking for help on similar topics.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful