Skip to content

Instantly share code, notes, and snippets.

@gbaeke
Created January 9, 2022 13:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbaeke/8b3ec20da98c6d579e0ac43113d1853e to your computer and use it in GitHub Desktop.
Save gbaeke/8b3ec20da98c6d579e0ac43113d1853e to your computer and use it in GitHub Desktop.
Azure Container Apps - Revisions

Azure Container Apps: Revisions

Deploy with Bicep

param image string = 'ghcr.io/gbaeke/super:1.0.5'

resource la 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
  name: 'la-aca' 
  location: resourceGroup().location
  properties: {
    retentionInDays: 30
    sku: {
      name: 'PerGB2018'
    }
  }
}


resource env 'Microsoft.Web/kubeEnvironments@2021-02-01' = {
  name: 'myenv'
  location: resourceGroup().location
  properties: {
    // not recognized but type is required
    type: 'managed'
    internalLoadBalancerEnabled:false
    appLogsConfiguration: {
      destination: 'log-analytics'
      logAnalyticsConfiguration: {
        customerId: la.properties.customerId
        sharedKey: la.listKeys().primarySharedKey
      }
    }
    }
  }

  resource frontContainerApp 'Microsoft.Web/containerApps@2021-03-01' = {
    name: 'front'
    location: resourceGroup().location
    kind: 'containerapp'
    properties: {
      kubeEnvironmentId: env.id
      configuration: {
        ingress: {
          external: true
          targetPort: 8080
        }
      }
      template: {
        containers: [
          {
            image: image
            name: 'super'
            env: [
              {
                name: 'WELCOME'
                value: 'Welcome to Container Apps'
              }
            ]
          }
        ]
        scale: {
          minReplicas: 0
          maxReplicas: 10
          rules: [
            {
            name: 'http-rule'
            http: {
              metadata: {
                concurrentRequests: '5'
              }
            }
            }
          ]
        }
      }
    }
  }

To deploy the above to a resource group rg-aca, run:

az group create -n rg-aca -l northeurope

az deployment group create -n aca-deploy \
  -g rg-aca \
  --template-file ./main.bicep

Revisions

The above template deploys the front container app. If it is the first deployment, you automatically get a revision. The name of the revision is front--SOMETHINGRANDOM.

You can control the revision suffix from Bicep (or ARM) with revisionSuffix in the template section. In Bicep:

template: {
    revisionSuffix: 'rev2'
    containers: [...]

The above would result in revision name front--rev2.

Traffic splitting

To control traffic to revisions, use the traffic section in configuration. With front--rev1 deployed, we can deploy a new version and configure a traffic split with 80% to rev1 and 20% to the latest revision like so:

configuration: {
    activeRevisionsMode: 'multiple'
    ingress: {
        external: true
        targetPort: 8080
        traffic: [
        {
            revisionName: 'front--rev1'
            weight: 80
        }
        {
            latestRevision: true
            weight: 20
        }
        ]

    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment