0

Challenge in attaching subnet and vnet configurations while creating azure container instances.

I am trying to create Azure container instances using the Azure SDK - Java/.Net. This container requires to communicate with components across different VMs. I was able to achieve this using Azure CLI commands with vnet and subnet configurations. But unable to replicate the same via SDK.

Code Snippet in Java

ContainerGroup containerGroup = azure.containerGroups().define(aciName).withRegion(Region.EUROPE_NORTH)
                    .withExistingResourceGroup(rgName).withLinux()
                    .withPrivateImageRegistry(registryServer, registryServerName, registryServerKey)
                    .defineVolume(volumeMountName).withExistingReadOnlyAzureFileShare(fileShareName)
                    .withStorageAccountName(storageAccountName).withStorageAccountKey(storageAccountKey).attach()
                    .defineContainerInstance(aciName).withImage(containerImageName).withExternalTcpPort(80)
                    .withVolumeMountSetting(volumeMountName, volumeMountPath).withCpuCoreCount(1)
                    .withMemorySizeInGB(1.5).withEnvironmentVariable("APP_PATH", volumeMountPath)
                    .withStartingCommandLine(commandLineArgs.toString()).attach().withDnsPrefix(aciName)
                    .withRestartPolicy(ContainerGroupRestartPolicy.NEVER).create();

Azure CLI

az container create --resource-group --name --image --cpu 1 --memory 1.5 --registry-login-server --registry-username --registry-password --azure-file-volume-share-name --azure-file-volume-account-name > --azure-file-volume-account-key --azure-file-volume-mount-path --restart-policy Never --e --subnet --subnet-address-prefix --vnet --vnet-name --subscription --command-line ""

Unable to attach the vnet and subnet configurations while creating azure container instances.

INDRAJITH EKANAYAKE
  • 3,894
  • 11
  • 41
  • 63

1 Answers1

0

Unfortunately, it seems that deploy ACI in Vnet is not supported in Java currently. You can take a look at the issue in Github.

If you take a look at the CLI command which can achieve it, then you will find the command actually use the Azure REST API to do that.

enter image description here

In the request, it set the container group property networkProfile with the subnet network profile. So if you really want to deploy the ACI in the Vnet, you could use the Azure REST API for Container Instance to achieve it in the Java code.

Charles Xu
  • 29,862
  • 2
  • 22
  • 39
  • Thanks a lot for the response. Is this option available with .Net? – Archana Ashwin May 13 '19 at 06:01
  • @ArchanaAshwin I just describe it for Java. But for ACI, all the language use the Azure REST API. So it's also available in .NET. – Charles Xu May 13 '19 at 06:20
  • Thanks Charles. Tried using the Azure REST API and it works. – Archana Ashwin May 13 '19 at 13:09
  • @ArchanaAshwin What's the reason you did not mark the answer when it helps you? – Charles Xu May 14 '19 at 08:51
  • Thanks for the help Charles. Facing difficulty in generating the access token for consuming the Azure Rest API to create a container group. Let me know for any pointers. – Archana Ashwin May 14 '19 at 13:28
  • @ArchanaAshwin You can take a look at [Service to service calls using client credentials](https://learn.microsoft.com/en-us/azure/active-directory/develop/v1-oauth2-client-creds-grant-flow). Or you just see the [Azure REST API Reference](https://learn.microsoft.com/en-us/rest/api/azure/). – Charles Xu May 15 '19 at 01:59
  • The references given above are very helpful. Thank you. – Archana Ashwin May 15 '19 at 06:42