0

Background: If i understand correctly InboundNATPools are used to map a range of external ports each to a specific VM on a VMSS behind a LB. e.g. {LB_IP:p1,LB_IP:p2, ...} => {VM1:p0,VM2:p0, ...}

Question: How can a VM (i.e. app) discover it's assigned external port? e.g. in the example above the right port from {p1,p2,..}

A possible approach: i'm considering using an external service which'll listen for connections on a well known port and when a connection is established respond with the source port. I'm reluctant to use it since it means maintaining another service.

Extra details: i'm running on Service Fabric and the protocol for the port is TCP.

Identical unanswered question: Retrieve Azure load balancer NAT port for Azure VM in C# didn't get a valid answer, i hope to resurface the issue.

Omzaks
  • 41
  • 6

1 Answers1

1

Presuming your scaleset IDs are contiguous, you could use

curl -H Metadata:true "http://169.254.169.254/metadata/instance?api-version=2017-12-01"

which will give you the nodename in the format of nodename_0

adding the number after the _ to the start port of the load balancer should give you the port

Its very hacky, and I really hope there is a better solution!

Personally I preferred to provide VPN access, so that those ports could be accessed directly from the internal VNET

Michael B
  • 11,887
  • 6
  • 38
  • 74
  • 1
    the name can also be retrieved in service using Environment.GetEnvironmentVariable("Fabric_NodeName") but i'd prefer a less hacky solution - thanks! – Omzaks Jun 12 '18 at 14:06