java - 如何使用 Azure SDK 在 java 中将私有(private) vnet 或子网附加到容器实例?

标签 java azure-container-instances azure-sdk private-subnet

创建 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 来实现此目的。

enter image description here

在请求中,它使用子网网络配置文件设置容器组属性networkProfile。因此,如果您确实想在 Vnet 中部署 ACI,则可以使用 Azure REST API for Container Instance在Java代码中实现它。

关于java - 如何使用 Azure SDK 在 java 中将私有(private) vnet 或子网附加到容器实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56056078/

相关文章:

powershell - Azure CDN - 通过资源管理 API 的自定义域 SSL

python - Azure Spot 实例创建问题

java - 评估公式并从单元格中删除公式

java - 如何用Flutter/Dart编写异步getter?

java - SoftHSM 无法获取证书

java - 禁止获取 p2 存储库索引

docker - 如何将字体添加到Windows Docker容器/图像?

azure - 如何将命令传递给 terraform(Azure ACI + osm 切片服务器)

azure - 如何将 HTTP 网关置于 Azure 容器实例之上?

azure - 强制 Azure CosmosDB Java SDK 读取最新值