Container Apps

Overview

The Container Apps builder is used to create Azure Container Apps.

  • Container Environment (Microsoft.Web/kubeEnvironments)
  • Container App (Microsoft.Web/containerApps)

Turn on Resource Provider

Before you deploy your container app, you need to turn on the Container Apps resource provider in your Azure subscription.

Get sure you have the following providers registered: Microsoft.Kubernetes and Microsoft.ContainerService.

Container Environment Builder

The Container Environment builder (containerEnvironment) defines settings for the Kubernetes envirionment that hosts the container apps.

KeywordPurpose
nameSets the name of the container environment.
log_analytics_instanceSpecifies a Log Analytics workspace where container logs should be sent. If none is provided, one will automatically be created.
internal_load_balancer_stateSets whether an internal load balancer should be used for load balancing traffic to container app replicas.
add_containerAdds a single container app to the environment.
add_containersAdds one or more container apps to the environment.

Also supports Tagging and Dependencies.

Container Apps Builder

The Container Apps builder (containerApp) is used to define one or more container apps to add to the container environment.

KeywordPurpose
nameSets the name of the container app.
add_identityAdds a managed identity to the the container app.
ingress_stateActivates or deactivates the ingress of the Azure Container App.
ingress_target_portActivates the ingress of the Azure Container App and sets the target port.
ingress_transportActivates the ingress of the Azure Container App and sets the transport mode.
system_identityActivates the system identity of the Azure Container App.
dapr_app_idSets the dapr app id for the app.
replicasSets the minimum and maximum replicas to scale the container app.
active_revision_modeIndicates whether multiple version of a container app can be active at once.
add_registry_credentialsAdds container image registry credentials for images in this container app, which are a list of server and usernames. Passwords are supplied as secure parameters.
reference_registry_credentialsAdds container image registry credentials for images in this container app in the form of a list of Azure resource ids.
add_containersAdds a list of containers to this container app. All containers in the app share resources and scaling.
add_simple_containerAdds a single container that references a public docker image and version.
add_secret_parameterAdds an application secret to the entire container app. This is passed as a secure parameter to the template, and an environment variable is automatically created which references the secret.
add_secret_parametersAdds application secrets to the entire container app. This is passed as secure parameters to the template, and environment variables are automatically created which reference the secret.
add_secret_expressionAs per add_secret_parameter, but the value is sourced from an ARM expression instead of as a parameter. Useful for e.g. storage keys etc.
add_secret_expressionsAs per add_secret_parameters, but the values are sourced from an ARM expressions instead of as parameters. Useful for e.g. storage keys etc.
add_env_variableAdds a static, plain text environment variable.
add_env_variablesAdds static, plain text environment variables.
Scale Rules

The Container App Builder supports a number of KEDA scale rules out of the box:

Scale Rule KeywordPurpose
add_http_scale_ruleAdds a scale rule for HTTP concurrent requests.
add_cpu_scale_ruleAdds a scale rule for CPU usage, either utilisation or average value.
add_memory_scale_ruleAdds a scale rule for Memory usage, either utilisation or average value.
add_servicebus_scale_ruleAdds a scale rule for service bus queues message count.
add_eventhub_scale_ruleAdds a scale rule for event hub events.
add_queue_scale_ruleAdds a scale rule for Azure Storage Queue length.
add_custom_scale_ruleAdds a custom scale rule. Provide an object that matches the KEDA specification.

The Azure Storage Queue Scale Rule integration is “smart” - provide a reference to the storage account, queue name and length threshold; all appropriate settings and secrets will be automatically configured for you.

Container Builder

The Container builder (container) is used to define one or more containers for a container app.

KeywordPurpose
nameSets the name of the container.
public_docker_imageSets a public container image.
private_docker_imageSets a private container image.
cpu_coresSpecifies the CPU cores allocated to the container (maximum 2.0).
memorySpecifies the memory in gigabytes allocated to the container (maximum 4.0).

Example

open Farmer
open Farmer.Builders
open Farmer.Arm

containerEnvironment {
    name "my-container-app"
    add_containers [
        containerApp {
            name "httpservice"
            activeRevisionsMode ActiveRevisionsMode.Single
            reference_registry_credentials [
                ContainerRegistry.registries.resourceId "myazurecontainerregistry"
            ]
            add_containers [
                container {
                    name "myservice1"
                    public_docker_image containerRegistryDomain containerRegistry "myimage1" version
                    memory 0.2<Gb>
                }
                container {
                    name "myservice2"
                    public_docker_image containerRegistryDomain containerRegistry "myimage2" version
                    cpu_cores 0.5<VCores>
                    memory 1.0<Gb>
                }
            ]
            replicas 1 5
            ingress_target_port 80us
            ingress_transport Auto
            dapr_app_id "httpservice"
            add_http_scale_rule "http-rule" { ConcurrentRequests = 100 }
        }
    ]
}