I have few instances in GCP and for administrative purposes I need to briefly connect in SSH and launch few commands. These instances do not have external IP in "normal" mode but for these brief maintenance I would like to assign ephemeral IP, do the maintenance and then remove them.
One can do this easily on the web interface (edit the instance change the NIC config to add ephemeral NAT IP) but I would like to avoid this since I have several instances... Am I missing something in gcloud documentation?
An ephemeral IP address is an IP address that doesn't persist beyond the life of the resource. For example, when you create an instance or forwarding rule without specifying an IP address, Google Cloud automatically assigns the resource an ephemeral IP address.
If no external address is configured on the instance, Cloud NAT can be used for IPv4 traffic. For information about identifying the internal and external IP address for your instances, see Locating the external and internal IP address for an instance.
Found it after some (too long) time exploring the deep part of gcloud documentation.
In the section dedicated to assign static external IP address to an instance (yes in the static part) it says in a small note:
"If you intend to use an ephemeral external IP address, you can skip this step, and Compute Engine will randomly assign an ephemeral external IP address."
https://cloud.google.com/compute/docs/ip-addresses/reserve-static-external-ip-address#ipassign
So the "key" word is to add an accessConfig to your instance like:
gcloud compute instances add-access-config [INSTANCE_NAME] \
--access-config-name "[ACCESS_CONFIG_NAME]"
In the example, there is a --address [IP_ADDRESS]
option to assign the static external IP but, as the note said, it is optional. Frankly, not easy to find!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With