Google Cloud Resolve VM host name to Google Cloud DNS host names

google-cloud-dnsgoogle-cloud-platformgoogle-compute-engine

I'm setting up an OpenShift cluster in Google Cloud and have a bunch of VM's spun up. I also have a Google Cloud DNS zone where I have registered the hostnames of the VM's I've set up. I want to be able to reference all the VM's by the hostnames I've configured in my Google Cloud DNS zone and not by the local names Google Cloud Platform gives them. How do I go about doing that please?

I've tried editing resolv.conf (they are all Centos 7 Linux VMs) but that doesn't work and I understand that gets overwritten every DHCP lease renewal anyway.

To explain in more detail, I'll use 1 VM as an example.
I have a VM called 'nat-gateway'. It's 'hostname -f' is nat-gateway.c.MyProjectName.internal and I can ping it using both nat-gateway and it's fqdn nat-gateway.c.MyProjectName.internal. On my Cloud DNS zone, called cloud.abc.gcp I have created an A record for nat-gateway and I want to be able to ping it using nat-gateway.cloud.abc.gcp. So for all my VMs I want to ping them by their corresponding cloud.abc.gcp hostnames.

Your help would be very much appreciated, thank you.

Best Answer

The short answer is yes. It is possible.

The long answer is that this is not the intended use of Cloud DNS. but here are the steps to make it behave almost like you want:

  1. On your Cloud DNS create the A record pointing to the Internal IP of your nat-gateway (as an example: 10.128.0.3)

    Side note, you can reserve an Internal IP address when creating a VM or promoting an in-use ephemeral internal IP address to a static address since the A record is pointing to its Internal IP.

  2. Wait for the Cloud DNS propagate the A record and ping the nat-gateway.cloud.abc.gcp hostname.

Results:

  1. If within the same VPC and the firewall allows ping, it will resolve the Cloud DNS hostname as the FQDN nat-gateway.c.MyProjectName.internal and it will ping normally.

  2. If outside the VPC but connected to it using a VPN or VPC Peering (example: Project A VPC A is connected to Project B VPC B using a VPN tunnel and all firewalls and routes apply, one instance can reach another form the other network using the Cloud DNS hostname resolved as Internal IP address)

  3. If the machine trying to ping is not connected to the VPC of your nat-gateway, it will resolve the hostname as the reserved IP address but not be able to reach it (expected behavior).

Finally, Cloud DNS will not resolve the FQDN nat-gateway.c.MyProjectName.internal directly, but to the IP associated to it and when used in the same VPC the IP will be resolved again by the internal DNS of the VPC as the FQDN nat-gateway.c.MyProjectName.internal.

Related Topic