c# - 有没有办法使用最新的 .NET Core SDK 在 Azure 中创建具有诊断和身份配置的容器组

标签 c# .net azure .net-core f#

问题是使用带有 nuget 的 .NET SDK 在 Azure 中创建具有身份和日志分析诊断功能的容器组

  • Microsoft.Azure.Management.Fluent
  • Microsoft.Azure.Management.ContainerInstance
  • Microsoft.Azure.Management.ContainerInstance.Fluent

所以问题是:

  1. 有没有办法在 Azure 中创建容器组,并使用最新的 .NET Core SDK Fluent API 指定身份和诊断?

或者

  • 有没有办法使用最新的 .NET Core SDK 在 Azure 中创建普通构造函数构建的容器组?
  • 有很多使用 Fluent API 的示例,例如。

    // Create the container group
    var containerGroup = azure.ContainerGroups.Define(containerGroupName)
        .WithRegion(azureRegion)
        .WithExistingResourceGroup(resourceGroupName)
        .WithLinux()
        .WithPublicImageRegistryOnly()
        .WithoutVolume()
        .DefineContainerInstance(containerGroupName + "-1")
            .WithImage(containerImage)
            .WithExternalTcpPort(80)
            .WithCpuCoreCount(1.0)
            .WithMemorySizeInGB(1)
            .Attach()
        .WithDnsPrefix(containerGroupName)
        .Create();
    

    尽管如此,我还没有找到一种方法来声明此容器组的身份或诊断。

    另一方面,我找到了一种使用类构造函数创建 ContainerGroup 对象的方法(是的,我的代码在 F# 中):

    // Create containers
    let containers =
        [| minCount .. maxCount |]
        |> Array.map (fun i ->
            Container(
                name = (sprintf "%s-%i" containerName i),
                image = image, 
                resources = resources, 
                EnvironmentVariables = envVariables))
    
    // Create container group for containers
    let containerGroup =
        ContainerGroup(
            containers = containers, 
            osType = "linux", 
            name = groupName, 
            location = location, 
            identity = identity, // missing from fluent
            imageRegistryCredentials = imageCredentials, 
            restartPolicy = restartType, 
            diagnostics = diag) // missing from fluent
    

    但是,对于这些普通构造函数构建的对象,我还没有找到在 Azure 中创建它们的方法。

    最佳答案

    我能够使用程序集 Microsoft.Azure.Management.ContainerInstance 中的 ContainerInstanceManagementClient 函数将普通构造函数构建的对象发送到 azure。

    let creds = SdkContext.AzureCredentialsFactory.FromServicePrincipal(client, key, tenant, AzureEnvironment.AzureGlobalCloud)
    let client = new ContainerInstanceManagementClient(creds)
    client.SubscriptionId <- subscriptionId
    let _ =
        client.ContainerGroups.CreateOrUpdate(
            resourceGroupName = rgName,
            containerGroupName = name,
            containerGroup = containerGroup) // Container group from the question
    

    关于c# - 有没有办法使用最新的 .NET Core SDK 在 Azure 中创建具有诊断和身份配置的容器组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56488597/

    相关文章:

    c# - StringBuilder 与字符串构造函数 - 字符

    c# - 如何使用 CreateTimerQueueTimer 在 C# 中创建高分辨率计时器?

    c# - 在 ASP.NET 中实现数据绑定(bind)的正确方法

    c# - 根据 PhPbb 数据库验证用户

    c# - 如何退出所有正在运行的线程?

    asp.net - Azure - Application Insights 端到端事务未显示所有 SQL 查询?

    c# - 如何使用 Azure 上的 MVC2 应用程序管理和发布数据库?

    .net - 通过 WCF 服务传递和检索带有方法的类

    c# - 每个 C# 控制台应用程序打印 "The system cannot find the path specified"

    css - 外部 CSS 显示在 head 标签中,而不是单独的文件中