I'm not sure why you are asking a question, when you already seem to have the answer too.
Each game server registers itself with the master server (or it's backup!) when it starts, and deregisters when it exits.
Over time the master server will check that each game server is still active, and deregister the ones that aren't.
Clients connect to the master server to get the list.
If you have a backup master, then you will need to get each query the list from the other and combine the lists - effectively, they act as a client does to get the list.