Please check out the Namenode HA architecture with key objects in processing HDFS client requests.

Where does this query go first? I mean, how does the client know that namenode is active?
It does not matter for the client / driver which namenode is active. because we are requesting HDFS with the identifier nameservice, not the node name namenode. nameservice will automatically forward client requests to the active namenode .
Example : hdfs://nameservice_id/rest/of/the/hdfs/path
Explanation:
How does this hdfs://nameservice_id/ and what is confs in it?
In hdfs-site.xml file
Create a name service by adding id to it (here nameservice_id is mycluster )
<property> <name>dfs.nameservices</name> <value>mycluster</value> <description>Logical name for this new nameservice</description> </property>
Now provide the namenode identifiers to determine the namenodes in the cluster
dfs.ha.namenodes.[$nameservice ID] :
<property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> <description>Unique identifiers for each NameNode in the nameservice</description> </property>
Then associate the namenode identifiers with the nodes of the namenode node
dfs.namenode.rpc-address.[$nameservice ID].[$name node ID]
<property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>machine1.example.com:8020</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>machine2.example.com:8020</value> </property>
After that, specify the Java class that HDFS clients use to communicate with the Active NameNode, so that the DFS client uses this class to determine which NameNode performs client requests .
<property> <name>dfs.client.failover.proxy.provider.mycluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property>
Finally, after these configuration changes, the HDFS URL will be the same.
hdfs://mycluster/<file_lication_in_hdfs>
To answer your question, I have selected several configurations . please check the detailed documentation on how Namenodes, Journalnodes, and Zookeeper machines form Namenode HA in HDFS.