0

Problem: Given N instances launched as part of VMSS, I would like my application code on each azure instance to discover the IP address of the other peer instances. How do I do this?

The overall intent is to cluster the instances so, as to provide active passive HA or keep the configuration in sync.

Seems like there is some support for REST API based querying : https://learn.microsoft.com/en-us/rest/api/virtualmachinescalesets/

Would like to know any other way to do it, i.e. either python SDK or instance meta data URL etc.

rahul gupta
  • 238
  • 1
  • 4
  • 11

2 Answers2

1

The RestAPI you mentioned has a Python SDK, the "azure-mgmt-compute" client https://learn.microsoft.com/python/api/azure.mgmt.compute.compute.computemanagementclient

Laurent Mazuel
  • 3,422
  • 13
  • 27
1

One way to do this would be to use instance metadata. Right now instance metadata only shows information about the VM it's running on, e.g.

curl -H Metadata:true "http://169.254.169.254/metadata/instance/compute?api-version=2017-03-01"
{"compute":
{"location":"westcentralus","name":"imdsvmss_0","offer":"UbuntuServer","osType":"Linux","platformFaultDomain":"0","platformUpdateDomain":"0",
"publisher":"Canonical","sku":"16.04-LTS","version":"16.04.201703300","vmId":"e850e4fa-0fcf-423b-9aed-6095228c0bfc","vmSize":"Standard_D1_V2"},
"network":{"interface":[{"ipv4":{"ipaddress":[{"ipaddress":"10.0.0.4","publicip":"52.161.25.104"}],"subnet":[{"address":"10.0.0.0","dnsservers":[],"prefix":"24"}]},
"ipv6":{"ipaddress":[]},"mac":"000D3AF8BECE"}]}}

You could do something like have each VM send the info to a listener on VM#0, or to an external service, or you could combine this with Azure Files, and have each VM output to a common share. There's an Azure template proof of concept here which outputs information from each VM to an Azure File share.. https://github.com/Azure/azure-quickstart-templates/tree/master/201-vmss-azure-files-linux - every VM has a mountpoint which contains info written by every VM.

sendmarsh
  • 1,046
  • 7
  • 11