Specify Revision weight for Azure Container Apps App during deployment - azure

right now i work on a pipeline to deploy our microservices to an azure-container-apps environment.
The deployment is done via azure-pipelines, since we use a TFS on prem i need to deploy new versions in a pipeline step with azure cli. For that i use the following command:
az containerapp update
--name my-service
--resource-group rg-sample
--image sample.azurecr.io/my-service:8440
--min-replicas 1
--max-replicas 10
This works perfectly new revisions get published and receive all the traffic, and that is exactly the problem im facing.
I know i can activate revisions with the az containerapp revision activate, but the containerapp update command automatically activates the latest revision with a weight of 100%, at least that is what i can see when i review changes with the azure portal.
Im looking for a way to deploy new revisions with azure cli, but with the limitation that the latest revision which was at 100% percent traffic before the deployment, stays there until i say via azure cli switch over to that revision.
Has anyone an idea how to archive that?
Best Erik

If your app is in multiple revision mode, you can:
# Make sure your app is in multiple revision mode
$ az containerapp revision set-mode \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--mode multiple
# Get the current "latestRevision"
$ LATEST_REVISION=$(az containerapp show \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--query properties.latestRevisionName)
# Explicitly set 100% to the latestRevision by name
$ az containerapp ingress traffic set \
--name $APP_NAME \
--resource-group $RESOURCE_GROUP \
--revision-weight $LATEST_REVISION=100
> [
> {
> "latestRevision": true, # New revisions will get 0% by default
> "weight": 0
> },
> {
> "revisionName": "appname--84yjetr",
> "weight": 100
> }
> ]

Related

Private AKS is not able to find the path of my local files to do a deployment through Helm

I'm currently trying to deploy my helm charts through my private aks cluster. However, I'm unable to do anything since it can't find the path of my local directory.
This is the command that I'm running:
az aks command invoke \
--resource-group aharo-aks-appgateway01 \
--name aharo-aks02 \
--command "helm install haro ./haro_files_helm_chart"
This is the error message that I'm getting
command started at 2023-01-06 22:49:46+00:00, finished at 2023-01-06 22:49:46+00:00 with exitcode=1
Error: INSTALLATION FAILED: path "./haro_files_helm_chart" not found
To prove that this type of commands can work, I tried one from the Microsoft Documentation:
az aks command invoke \
--resource-group aharo-aks-appgateway01 \
--name aharo-aks02 \
--command "helm repo add bitnami https://charts.bitnami.com/bitnami && helm repo update && helm install my-release bitnami/nginx"
What else can I do to find the path of my directory? Do you know if I could be missing any configuration on my cluster?
When you are passing the helm install command to the AKS VMs, the VMs(nodes) will be looking for ./haro_files_helm_chart in their filesystem not the machine that is running the command, hence the path not found error.
In the example you shared, the node is installing a helm chart that it is downloading first.
To resolve the issue, you should attach the directory of the helm chart with the az aks command invoke as documented here. Below is the part you need:
You can also attach all files in the current directory. For example:
az aks command invoke \
--resource-group myResourceGroup \
--name myAKSCluster \
--command "kubectl apply -f deployment.yaml configmap.yaml -n default" \
--file .
For example, I created a chart called "test-chart" and installed it using helm create test-chart. The chart would be created in the current directory im in:
$ls
test-chart
Then run the same command shared above and just change the command (without changing the directory):
az aks command invoke \
--resource-group myResourceGroup \
--name myAKSCluster \
--command "helm install test-chart-override-name test-chart" \
--file .
The answer for this is the following:
az aks command invoke \
--resource-group aharo-aks-appgateway01 \
--name aharo-aks02 \
--command "helm install haro . "
Anoother workaround is uploading your helm charts to your container registry & then, you will have to download them and install them directly like the example from microsoft:
az aks command invoke \
--resource-group aharo-aks-appgateway01 \
--name aharo-aks02 \
--command "helm repo add bitnami https://charts.bitnami.com/bitnami && helm repo update && helm install my-release bitnami/nginx"

Creating vm using azure cli

I'm learning azure for 2 weeks now, I'm curious about creating vm on the cli. For example if I want to create a vm in a region with a specific size using cli, but it turns out that the size isn't available so I want the script to auto select another size with the same specs that I chose in the first place but I don't know how. This is my script now:
az group create --name TestingVM --location eastus
az vm create \
--resource-group TestingVM \
--name TestingVM \
--image Debian \
--admin-username aloha \
--size Standard_F8s_v2 \
--location eastus \
--admin-password *somepassword*
thanks!

How to activate settings in the web app when deployed as deployment-container-image-name

I have deployed a "Container Image" on to Web App Service with the following command.
az webapp create --name Dev-App --plan Dev-AppServicePlan \
--resource-group Dev \
--deployment-container-image-name ...devcontainerregistry.azurecr.io/app-node:latest
After the app was successfully deploment I need to change some Environment variables via the following commands.
az webapp config appsettings set --name Dev-App --resource-group Dev \
--settings MONGO_DSN='mongodb://cosmosdb...'
az webapp config appsettings set --name Dev-App --resource-group Dev \
--settings REDIS_URI='...dev.redis.cache.windows.net:6380...'
az webapp log config --name Dev-App --resource-group Dev \
--docker-container-logging filesystem
Now I have updated and restarted the Web App but it looks like the Image is not redeployed or at least the Environment variables are not there.
az webapp update --name Dev-App --resource-group Dev
az webapp restart --name Dev-App --resource-group Dev
I looked with log tail to the logs but the logs are also not changed. What I mean with "not changed" is that the log output is stucked to the Timestamp "2021-01-13T13:21:31.100Z" even when I restart the Web App.
az webapp log tail --name Dev-App --resource-group Dev
In this Articles from MS is described that a restart should be enough but then should also the log output should be changed.
2: Redeploy a container to Azure App Service after making changes
Configure a custom container for Azure App Service
Any hint how to activate the new settings in the custom image setup or trigger a redeployment?
FYI: I have also created a question in the azure community.
https://learn.microsoft.com/en-us/answers/questions/230584/how-to-activate-settings-in-the-web-app-when-deplo.html
It seems you want to updates the environment variables just like add them in the command:
docker run --name container_name image -e env_var1 -e env_var2
The Azure CLI command just sets the environment variables for the Web App service, you can see them in the Kudu, but it's not the same result as the docker run command.
I recommend you use the docker-compose to deploy your image to the Web App service. Here is the example for the docker-compose. You can update the environment variables in the environment option of the docker-compose file in the portal. Then it will restart again and refresh the logs. And the variables you added will also take effect.
Well the solution for my problem was that I change the registry from "Private Registry" to "Azure Container Registry" in the "container settings" page after running the following command
az webapp create --name Dev-App \
--plan Dev-AppServicePlan \
--resource-group chat-Dev \
--deployment-container-image-name devcontainerregistry.azurecr.io/chat-node:latest
I have put the acr data into the fields and activated the "Continous Deployment"
After this change every settings change triggers a restart and the ENV Variables was in the new instance.

Unable to deploy Azure Function with Premium Service Plan

When I try to create a FunctionApp Premium Plan using the following commands:
# Create a Resource Group
az group create \
--name $rg_name \
--location $az_loc
# Create a Function App Storage Account
az storage account create \
--name $fa_storage_name \
--resource-group $rg_name \
--location $az_loc \
--sku Standard_LRS
# Create a Premium plan
az functionapp plan create \
--name $fap_name \
--resource-group $rg_name \
--location $az_loc \
--sku P2v2
I receive an error:
The requested app service plan cannot be created in the current
resource group because it is hosting Linux apps. Please choose a
different resource group or create a new one.
I also tried the sku EP2 with same result. The SKU's are really hard to find in the docs(!). Does anyone know which sku's work with Linux Azure Functions and what I might be missing here?
This is common error.
The solution is to create a new Resourse Group and put the function app in.
The problem comes from the conflict between azure function plan based on windows and based on linux.
Create a new Resource group is the only way, and notice to separate function based on linux and windows in your development.
Here is what ended up working for me. Note the --is-linux true flag in az functionapp plan create and the --plan flag in az functionapp create:
# Create a Premium plan
az functionapp plan create \
--name $fap_name \
--is-linux true \
--resource-group $rg_name \
--location $az_loc \
--sku EP2
# Create Function App (container for Azure Function)
#--consumption-plan-location $az_loc \
az functionapp create \
--name $fa_name \
--resource-group $rg_name \
--storage-account $fa_storage_name \
--plan $fap_name \
--os-type Linux \
--runtime python \
--runtime-version 3.7 \
--subscription $az_sub \
--functions-version 2
There is a current limitation where Windows and Linux apps cannot exist in the same resource group.
https://learn.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro#limitations
Therefore, it was failing when deploying a Windows resource and worked when --is-linux was set to true

Setting up tags on resource creation stage through Azure CLI

One can create a resource in Azure through Azure CLI commands:
az functionapp create \
--name "function-name" \
--resource-group "resource-group-name" \
--storage-account "gl0unique0storage0name"
and later - as the next step - in a separate command set tags:
az resource tag --tags "environment=development" \
--name "function-name" \
--resource-group "resource-group-name"
this will set tag "environment" with the value "development".
If one enforces a policy to subscription to have a certain tag on every resource.
One must set tags on creation.
Documentation says that it is possible through ARM templates.
Q1 (complex): How can I set tags on any resource type creation step through Azure CLI?
Q2: Can I do this at least for Azure Function because documentation says that I can?
When I tried to followed docs - linked in Q2, with this command:
az functionapp create \
--name "function-name" \
--resource-group "resource-group-name" \
--storage-account "gl0unique0storage0name" \
--tags "environment=development"
I got this error:
az: error: unrecognized arguments: --tags environment=development
Q1 (complex): How can I set tags on any resource type creation step through Azure CLI?
AFAIK, you can use the Azure Policy to do that, follow this doc: Apply tag and its default value.
Sample for CLI:
# Create the Policy Definition (Subscription scope)
definition=$(az policy definition create --name 'apply-default-tag-value' --display-name 'Apply tag and its default value' --description 'Applies a required tag and its default value if it is not specified by the user' --rules 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/apply-default-tag-value/azurepolicy.rules.json' --params 'https://raw.githubusercontent.com/Azure/azure-policy/master/samples/built-in-policy/apply-default-tag-value/azurepolicy.parameters.json' --mode All)
# Set the scope to a resource group; may also be a subscription or management group
scope=$(az group show --name 'YourResourceGroup')
# Set the Policy Parameter (JSON format)
policyparam='{ "tagName": { "value": "costCenter" }, "tagValue": { "value": "headquarter" } }'
# Create the Policy Assignment
assignment=$(az policy assignment create --name 'apply-default-tag-value' --display-name 'Apply tag and its default value Assignment' --scope `echo $scope | jq '.id' -r` --policy `echo $definition | jq '.name' -r` --params "$policyparam")
Q2: Can I do this at least for Azure Function because documentation says that I can?
Yes, you can, the command looks fine, make sure you use the latest version CLI, or you can try the command below az functionapp create -g joywebapp -p joyplan -n joytest1111 -s joystoragev2 --tags 'environment=development', it works fine on my side.

Resources