skip to Main Content

I’m currently having a PHP application running in an Azure VM, now I have moved that setup to a VMSS and Load Balancer and having a VM as staging. But now, when the developer make a change each time, They will do that to the staging VM and I will take a snapshot of the image and update the VMSS image with the new version of the image. This is really a bad process. So I thought to have Azure DevOps in place to take care of the deployment. But I couldn’t figure out how we can deploy to VMSS instances. I have seen the Microsoft Documentation, but didn’t help much.

My idea towards it is deploying the application to the staging VM and take the image and update the VMSS all in CD pipeline process with CLI scripts.

I need some one to check whether my idea is correct or is there any better solution. If you need any further details or clarification to help me, please let me know.

2

Answers


  1. The exact answer depends on Linux or Windows.

    Images can be useful. If your PHP app has a bunch of dependencies that have to be installed/configued and rarely change then baking this into an image can speed things up. However for the application itself it likely makes more sense to install the app after deploying the image. If your app rarely changes maybe it makes sense to then update the image to make your scaling faster.

    Check out:

    https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-deploy-app

    Login or Signup to reply.
    • If you would like to host your PHP app on the instances of Azure VMSS and deploy the application onto all instances instead of updating the VM image, you can install the extension Azure Pipeline Agent For Linux which will configure each instance of the VMSS to be a target in the deployment group, so that we can use deployment group job in a release pipeline to roll out the deployment.

      enter image description here

    • If you would like to deploy app on one of the VMSS instances and capture a new VM image based on this instance and then update the image reference for your VMSS resource, you may test the steps below.

    1. In my case, I have configured one of the VMSS instances (azvmss-ub000000) as a self-hosted agent to deploy app via the agent job running on it;
    2. After the app is deployed on azvmss-ub000000, I run the Azure CLI commands to capture new VM image based on its managed disk; here is the sample script from the AzureCLI pipeline task running on MS-hosted agents; kindly note that you may leverage other methods to capture VM image and update the image reference and then integrate the commands into release pipeline; in all cases, please use the VMSS resource in test environment to examine the workflow in order to avoid missing data on your VMs from production environment;
      echo "1. Query the managed disk id of instance 0;"
      instance_os_disk_resourceId=$(az vmss list-instances --resource-group rg-azvm-linux --name azvmss-ubuntu-22.04 --query "[?instanceId=='0'].storageProfile.osDisk.managedDisk.id" -o tsv)
      echo instance_os_disk_resourceId is $instance_os_disk_resourceId
      
      echo "2. Create new VM image based on the managed disk;"
      new_image_id=$(az image create --resource-group rg-azvmimages --name azvmimage-ubuntu22.04-$(date).r$(Release.ReleaseId) --source $instance_os_disk_resourceId --os-type Linux --hyper-v-generation V2 --query "id" -o tsv)
      echo new_image_id is $new_image_id
      
      echo "3. Update the VMSS image reference with new image id;"
      az vmss update --resource-group rg-azvm-linux  --name azvmss-ubuntu-22.04 --set virtualMachineProfile.storageProfile.imageReference.id=$new_image_id
      
      echo "4. Upgrade instance 1 after the image reference is updated."
      az vmss update-instances --resource-group rg-azvm-linux --name azvmss-ubuntu-22.04 --instance-ids 1
      

      enter image description here

    By the way, you may also consider hosting your app on Azure App Services or AKS; Azure DevOps Services have corresponding tasks for deployment.

    Build and test PHP apps – Azure Pipelines | Microsoft Learn

    Deploy to Azure Kubernetes Service with Azure Pipelines – Azure Kubernetes Service | Microsoft Learn

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search