Skip to content

Instantly share code, notes, and snippets.

@vfarcic
Last active January 17, 2022 23:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vfarcic/013f959bdb69fe893768ce1f1960d9e1 to your computer and use it in GitHub Desktop.
Save vfarcic/013f959bdb69fe893768ce1f1960d9e1 to your computer and use it in GitHub Desktop.
# Source: https://gist.github.com/013f959bdb69fe893768ce1f1960d9e1
#############################################################################
# Azure Container Apps: Containers As A Service (CaaS) Flavor Of Serverless #
# https://youtu.be/iV7WrsxExdY #
#############################################################################
# Referenced videos:
# - Discussing The Real Expectations For Serverless Deployments: https://youtu.be/TvzPvj18N88
#########
# Setup #
#########
git clone https://github.com/vfarcic/azure-container-apps-demo
cd azure-container-apps-demo
# Install `az` (https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
az login
##############################
# Setup Azure Container Apps #
##############################
az extension add \
--source https://workerappscliextension.blob.core.windows.net/azure-cli-extension/containerapp-0.2.0-py2.py3-none-any.whl \
--yes
az provider register \
--namespace Microsoft.Web
export RESOURCE_GROUP=dot-$(date +%Y%m%d%H%M%S)
export LOCATION=canadacentral
az group create \
--name $RESOURCE_GROUP \
--location $LOCATION
export LOG_WORKSPACE="dot-logs"
export CA_ENV="dot-env"
az monitor log-analytics workspace create \
--resource-group $RESOURCE_GROUP \
--workspace-name $LOG_WORKSPACE
export LOG_WORKSPACE_CLIENT_ID=$(\
az monitor log-analytics \
workspace show \
--query customerId \
--resource-group $RESOURCE_GROUP \
--workspace-name $LOG_WORKSPACE \
--out tsv)
export LOG_WORKSPACE_CLIENT_SECRET=$(\
az monitor log-analytics \
workspace get-shared-keys \
--query primarySharedKey \
-g $RESOURCE_GROUP \
-n $LOG_WORKSPACE \
--out tsv)
########################################
# Environments In Azure Container Apps #
########################################
az containerapp env create \
--name $CA_ENV \
--resource-group $RESOURCE_GROUP \
--logs-workspace-id $LOG_WORKSPACE_CLIENT_ID \
--logs-workspace-key $LOG_WORKSPACE_CLIENT_SECRET \
--location $LOCATION
#################################
# Creating Azure Container Apps #
#################################
az containerapp create \
--name dot \
--resource-group $RESOURCE_GROUP \
--environment $CA_ENV \
--image vfarcic/devops-toolkit-series:2.7.0 \
--target-port 80 \
--ingress external \
--query configuration.ingress.fqdn \
--cpu 0.5 \
--memory 0.25Gi \
--max-replicas 3
az containerapp create \
--name dot \
--resource-group $RESOURCE_GROUP \
--environment $CA_ENV \
--image vfarcic/devops-toolkit-series:2.7.0 \
--target-port 80 \
--ingress external \
--query configuration.ingress.fqdn \
--cpu 0.25 \
--memory 0.5Gi \
--max-replicas 3
# Open it in a browser
az containerapp delete \
--name dot \
--resource-group $RESOURCE_GROUP
###########################################
# ARM Manifests With Azure Container Apps #
###########################################
az containerapp create --help
cat dot.json
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file dot.json \
--parameters \
environment=$CA_ENV \
tag=2.7.0
# Change the `maxReplicas` value to `10` in `dot.json`
az deployment group create \
--resource-group $RESOURCE_GROUP \
--template-file dot.json \
--parameters \
environment=$CA_ENV \
tag=2.7.0
##########################################
# Observing Azure Container Applications #
##########################################
az containerapp list --output table
az containerapp show \
--name dot \
--resource-group $RESOURCE_GROUP \
--output yaml
# Open the address in a browser to see the container app.
az containerapp delete \
--name dot \
--resource-group $RESOURCE_GROUP
az containerapp create \
--name dot \
--resource-group $RESOURCE_GROUP \
--environment $CA_ENV \
--image vfarcic/devops-toolkit-series:2.7.0 \
--target-port 80 \
--ingress external \
--query configuration.ingress.fqdn \
--cpu 0.25 \
--memory 0.5Gi \
--max-replicas 10
# Replace `[...]` with the application address (FQDN)
export APP_ADDR=[...]
# Open the address in a browser to see the container app.
az monitor log-analytics query \
--workspace $LOG_WORKSPACE_CLIENT_ID \
--analytics-query "ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'dot' | project ContainerAppName_s, Log_s, TimeGenerated | take 3" \
--out table
################################
# Scaling Azure Container Apps #
################################
# Install `ddosify` CLI from https://github.com/ddosify/ddosify/releases
ddosify -t "https://$APP_ADDR" \
-n 1000 -d 60 -l incremental
#########################################
# Updating Azure Container Applications #
#########################################
az containerapp update \
--name dot \
--resource-group $RESOURCE_GROUP \
--image vfarcic/devops-toolkit-series:3.0.0
# Progressive delivery (https://docs.microsoft.com/en-us/azure/container-apps/revisions-manage?tabs=bash#traffic-splitting)
az containerapp update \
--name dot \
--resource-group $RESOURCE_GROUP \
--image vfarcic/devops-toolkit-series:4.0.0
az containerapp revision list \
--name dot \
--resource-group $RESOURCE_GROUP \
--output table
# Wait for a while
az containerapp revision list \
--name dot \
--resource-group $RESOURCE_GROUP \
--output table
###########
# Destroy #
###########
az group delete --name $RESOURCE_GROUP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment