创建 Azure 容器实例时附加子网和 vnet 配置的挑战。
我正在尝试使用 Azure SDK - Java/.Net 创建 Azure 容器实例。该容器需要与不同虚拟机上的组件进行通信。我能够使用带有 vnet 和子网配置的 Azure CLI 命令来实现此目的。但无法通过 SDK 复制相同的内容。
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 ""
创建 Azure 容器实例时无法附加 vnet 和子网配置。
最佳答案
不幸的是,目前 Java 似乎不支持在 Vnet 中部署 ACI。你可以看看issue在 Github 中。
如果您查看可以实现此目的的 CLI 命令,您会发现该命令实际上使用 Azure REST API 来实现此目的。
在请求中,它使用子网网络配置文件设置容器组属性networkProfile
。因此,如果您确实想在 Vnet 中部署 ACI,则可以使用 Azure REST API for Container Instance在Java代码中实现它。
关于java - 如何使用 Azure SDK 在 java 中将私有(private) vnet 或子网附加到容器实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56056078/