Search code examples
metadatagoogle-compute-enginehostnamefqdn

Configuring FQDN for GCE instance on startup


I am trying to start a google compute engine (GCE) instance with a pre-configured FQDN. We are intending to run an application that is licensed based on the contents of /etc/hosts.

I am starting the instances using the Google Cloud SDK utility - gcloud.

I have tried setting the "hostname" key using the metadata option like so:

gcloud compute instances create mynode (standard opts) --metadata hostname=mynode.example.com

Whenever I log into the developer console, under computer, instances, I can see hostname under "Custom metadata". This appears to be a new, custome key - it has no impact on what:

http://metadata.google.internal/computeMetadata/v1/instance/hostname

returns.

I have also tried setting "instance/hostname" like the below, which causes a parsing error when using gcloud.

--metadata instance/hostname=mynode.example.com

I have successfully used the startup scripts functionality of the metadata server to run a startup script that parses the new, internal IP address of the newly created instance, updated /etc/hosts. This appears to work but doesn't feel "like the google way".

Can I configure the FQDN (specifically, a domain name, as the instance name is always the hostname) of an instance, during instance creation, using the metaserver functionality?


Solution

  • According to this article 'hostname' is part of the default metadata entries that provide information about your instance and it is NOT possible to manually edit any of the default metadata pairs. You can also take a look at this video from the Google Team. Within the first few minutes it is mentioned that you cannot modify default metadata pairs. As such, it does not seem like you can specify the hostname upon instance creation other than through the use of a start-up script like you've done already. It is also worth mentioning that the hostname you've specified will get deleted and auto-synced by the metadata server upon reboot unless you're using a start-up script or something that would modify it every time.

    If what you're currently doing works for what you're trying to accomplish, it might be the only workaround to your scenario.