gpt4 book ai didi

azure - 如何使用.Net Fluent SDK设置Azure容器实例重启策略

转载 作者:行者123 更新时间:2023-12-02 23:46:41 26 4
gpt4 key购买 nike

使用 .Net Fluent Management SDK 创建 Azure 容器实例时如何配置重启策略?我是否遗漏了一些明显的东西,或者 SDK 是否落后于该功能?

                _azure.ContainerGroups.Define(containerGroupName)
.WithRegion(Region.USEast)
.WithExistingResourceGroup("my-resource-group")
.WithLinux()
.WithPrivateImageRegistry("myreg.azurecr.io", "registry", "XXXXXXXXXXXXX")
.WithoutVolume()
.DefineContainerInstance(containerGroupName)
.WithImage("my-image/tag")
.WithoutPorts()
.WithCpuCoreCount(4)
.WithMemorySizeInGB(0.5)
.WithEnvironmentVariable("containerGroup", containerGroupName)
.Attach()
.Create();

谢谢

最佳答案

How do I configure the restart policy when creating an Azure Container Instance using the .Net Fluent Management SDK?

根据Fluent SDK我发现我们可以使用以下代码设置重启策略

containerGroup.Inner.RestartPolicy = ContainerRestartPolicy.Always;

演示代码:

var containerGroup = _azure.ContainerGroups.Define(containerGroupName)
.WithRegion(Region.USEast)
.WithExistingResourceGroup("my-resource-group")
.WithLinux()
.WithPrivateImageRegistry("myreg.azurecr.io", "registry", "XXXXXXXXXXXXX")
.WithoutVolume()
.DefineContainerInstance(containerGroupName)
.WithImage("my-image/tag")
.WithoutPorts()
.WithCpuCoreCount(4)
.WithMemorySizeInGB(0.5)
.WithEnvironmentVariable("containerGroup", containerGroupName)
.Attach()
.Create();

containerGroup.Inner.RestartPolicy = ContainerRestartPolicy.Always;

注意:我发现 ContainerRestartPolicy 只有一个默认值always,我没有在我这边测试它。我不确定其他值 Never 和 OnFailure 是否有效

如果 ContainerInstanceManagementClient 是可能的,我们可以使用 ContainerInstanceManagementClient 创建 Azure 容器实例

ContainerInstanceManagementClient client = new ContainerInstanceManagementClient(new TokenCredentials(token));

var containerGroup = new ContainerGroupInner
{
Location = "xx",
Containers = new List<Container>(),
ImageRegistryCredentials = new List<ImageRegistryCredential>(),
RestartPolicy = "xxx"

};

var groupInner = client.ContainerGroups.CreateOrUpdateAsync("resourceGroup", "containerGroupName", containerGroupInner).Result;

关于azure - 如何使用.Net Fluent SDK设置Azure容器实例重启策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47906725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com