How to add a current VM to another cloud service without having to rebuild the vm in Azure? - azure

We have a few servers in Azure that are running the same service. We would like them to be part of the same availability set. How do you add these servers together in the same availability set if they were not created in the same cloud service when they were created?
It looks like I would need to rebuild these VM's? If so that kinda sucks.
Please let me know if anyone knows a better way.
Thanks in advance.

Once a VM is created, it can't join an availability set.
However, the image for the VM is available in storage. So, new VMs can be spun up, using the image, this time adding them to the set. And rebuilding the VM from scratch is not needed.
Edit:
I've used the method above to bring up a VM, but I had forgotten that if your VM is running already, capture is the way to go. I'd suggest these steps:
Capture the image of your current VM. This will run sysprep on it, so you will want to be careful with it. (spin up a test VM and play with the steps until you feel confident to move to a production box)
Then when you create a new VM, specify your captured image and your availability set. Then the machine will come up with all your services running in the new set.

Related

Azure scaleset storage | update app code | Add an existing VM to a new scale-set

I have three questions that I couldn't get a clear answer for in the documentation I visited.
1- In case I deployed a VM scale-set with auto-scaling and I had a VM that was scaled-in (according to the set policy) then it remained active for a while and after that, it was scaled-out after the utilization got back to normal. My question here is what happens to the data generated by the VM that was scaled in, then out (ex: logs) in case I was using Managed storage. Noting that the aim here is to persist important data (app logs...)?
2- As per what I understood from the documentation in order to update your app code for example (using SCM ex Git) on all the scale set nodes you will need the help of an automation tool (ex: ansible), or you'll need to update the custom image and redeploy it to the scale set. Is there a more centralized way that I missed?
3- Is there a way to add an existing VM to a new scale set other than converting it to a base image?
thanks in advance.
A1. If you do not set the persistent storage, then the scale in will just delete the instance without persisting the data in the VM.
A2. There is no other way to update your code, the best way is to change your VM image. Or use storage to store your code and then mount the storage to your VMSS. For example, the
Azure file share.
A3. No, you can't add other existing VMs to VMSS. It's impossible.

sync files between azure scale set vms

i am a newbie and am planning to host iis server for my client in azure with auto-scale functionality.
we will test modules and update once in a week in iis server, my question is how to sync the files between vms while on auto-scaling and if we can use auto-scale only for identicals vms, then please suggest me the solution for this scenario. we will start min 2 max 10 vms in auto-scale.
Regards,
Kumar B
I first would ask why a VM, things do get more complicated using VMs. Scale Set would help support this however you still will have issues when you want to deploy new code. You said IIS so I am presuming Windows. Desired State Configuration is a great choice you can make a PowerShell script that will "configure" your VM for you, and potentially pull in any code updates. This is also where things like chef/puppet/salt can come into play to ensure the server is configured.
You could look at creating a custom image that every time you deploy new code gets baked into the image. Then you are basically doing a rolling update where you spin up a new server and then destroy one until they all have been updated. Technically this could be done, either way, just if they are baked into the image you would have a quicker start time.
https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-deploy-app
https://adamtheautomator.com/azure-vm-scale-sets-powershell/
Automatic - VMs may be rebooted in a random order even taking all VMs temporarily down at the same time.
Rolling - The scale set deploys updates to instances in batches with an optional pause time between batches.
Manual - Nothing happens to existing VMs when an update is initiated.
What files are you trying to sync if they are not code files, Azure Files would be a great fit as that supports SMB or you could just use cloud storage.
You can deploy your application to a virtual machine scale set using desired state configuration. See: https://learn.microsoft.com/en-us/azure/virtual-machine-scale-sets/virtual-machine-scale-sets-deploy-app
Not what you asked, but you should consider why you are hosting your app in IIS on VMs. If you are using Azure, then Azure App Service may be a better fit. See: https://learn.microsoft.com/en-us/azure/app-service/

Deploy a nodejs application on azure vm

I am trying to deploy a nodejs app on azure vm but I keep reading that the vm machine can crash or restart.
So lets say I opened the vm and installed nodejs and all the required tools I need then I get my code from github and started it, now every thing is running okay.
I am wondering what would happen if the vm restarted/crashed? Will the tools I downloaded and my code be lost? how can I make the vm when it start to redownload the tools, setup the environment, download my code then run it?
Azure Virtual Machines use Azure Blobs to back the OS disk VHD, as well as any attached data disk VHD. So, for those disks, everything is durable, regardless whether the VM is running or not (or crashes).
VMs also provide temporary storage on ephemeral disks. Assume anything placed on these temporary disks can, and will, disappear upon crash/restart.
So if you install any type of code libraries, apps, etc. on OS or attached disks, things remain in place unless you decommission the VM (and related storage), or delete it yourself.
Lots of documentation around Azure Virtual Machines and Storage, which can provide additional details.

Azure VM Capture (Process Overview)

I am planning to capture my VM image in Azure to create a copy for VM deployments (I am using this to deploy multiple VM or any redeployment scenarios).
Will any data/ configurations lost during the process? Be it application wise or server. I am expecting it to work just as simple as copy and paste functionality no Gotchas. Everything within this VM is critical to my clients (Customized apps/ web services etc.)
P/S: I have done my research here: https://azure.microsoft.com/en-us/documentation/articles/virtual-machines-capture-image-windows-server/
It says it will delete my VM once I have captured the image, now this is where I am very worried about.
Process of capturing the VM will preserve the installed applications, data and most settings. However, it does clear a few things like the computer name, network settings etc, so that the same image could be used to create multiple VMs later on.
Also, this process will delete your existing VM. You have to create a new VM using the image.
If you are unsure about any required settings that may be lost in this process, strong recommendation is to create a backup of the existing VM before you begin. You can do that by doing AzCopy of all the vhds on the VM (OS and Data disks). You could delete the backup after verifying the image deployments.
There are two ways of creating Virtual Images:
Without deprovisioning it: Source VM is not destroyed. You should switch if off to avoid problems. If you create a VM from image their hostnames will clash. The idea is using this capture method for backups.
After running waagennt -deprovision on it: Source VM is destroyed in the process. You can create many VMs with no problem.This is probably what you want to do. Don't worry is harmless, apart of destroying source VM. You can always create a VM from that image. The idea is using this capture method for creating a base image and then have some kind of process to create and destroy servers (Auto Scaling).
For example you create a web server for your app and instantiate more VMs in peak times.
What does waagent exactly deprovision?
waagent -deprovision command clears some configuration on the machine. Exactly:
This command will attempt to clean the system and make it suitable for
re-provisioning. This operation performs the following tasks:
Removes SSH host keys (if Provisioning.RegenerateSshHostKeyPair is 'y' in the configuration file)
Clears nameserver configuration in /etc/resolv.conf Removes the root user's password from /etc/shadow (if
Provisioning.DeleteRootPassword is 'y' in the configuration file)
Removes cached DHCP client leases Resets host name to localhost.localdomain
Deletes the last provisioned user account (obtained from /var/lib/waagent) and associated data.
Apart of this nothing will be touch on your server.

how can I configure availability sets in azure?

I am not very familiar with this in azure.
I created one centos vm, I created an availability set, in order to enable auto scaling I need to create another VM in the same availability set.
so I will create another vm, with the same image.
So, these 2 vms will replicate each other? if I install something in one VM, will it be replicated automatically to the other vm?, should I use only one of the vms as the starter point to install and configure things?
or should I do everything manually on each VM? Example, if I open port 80 in one I should do it in another?, if I install magento in one, I should install it in the other?
Azure will not replicate your VMs automatically. There are some manual steps involved:
You need to prepare one VM as a starter point.
Then you manually clone VMs up to a maximum number that you will need.
Make sure all they are in the same availability set.
Set up auto scaling
Now Azure will scale automatically by turning some of your VMs on and off. When VM is turned off, you will only incur storage costs for it. And storage in Azure is almost free.
To answer your first question: How to configure availability set
I created a post covering this on How to guard your application from azure outages
Use the quick create to stand up a VM of your choice
Once the instance is running click on the configure tab and create a new availability set
Click save
Saving will force a shut down, reconfigure, startup process
Once the VM comes back online you can create a 2nd VM
Using the create from gallery option, click through all the create screens until you get to the configure virtual machine screen (screen 4 at the moment)
Select the cloud service that was created with your first VM (availability sets require the VM's to run in the same cloud service)
Then select the availability set you created for the first VM
Finish the creation of your second VM
You can now see the linked VM's in the same availability set by clicking on the configure tab for any VM in the availability set you created. It will list all VMs in a given availability set inside the details of the VM

Resources