1

I've two servers with ephemeral external ips.

ServerA ServerB

and I've one Static external IP address (A.B.C.D), which is currently attached to ServerA.

ServerA is my primary loadbalancer, and ServerB is my secondary. How can I use a floating IP on Google Cloud.

Do I need to use gcloud? Is this a good solution?

Example command of failover:

gcloud config set project project-name
gcloud compute instances delete-access-config ServerA --access-config-name 'External NAT
gcloud compute instances delete-access-config ServerB --access-config-name 'External NAT'
gcloud compute instances add-access-config ServerB --address A.B.C.D
1
  • 1
    Support for Virtual IP/Floating IP in GCE is currently not available. Feature request is already created. You can refer to this link to subscribe for the updates. The workaround for now would be to use the GCE Load balancer
    – Faizan
    Feb 16, 2017 at 21:31

2 Answers 2

3

Posting my comment as an answer for other users looking at this thread:

Support for Virtual IP/Floating IP in GCE is currently not available. Feature request is already created. You can refer to this link to subscribe for the updates. The workaround for now would be to use the GCE Load balancer

1

Google recently changed and allowed the use of floating IP's and this is described..

The solution comes down to the 2 lines of code below at the end between ----- and -----, not accounting for the creation of the ip-fallover network where you will launch your instances

#!/bin/bash
export CLOUDSDK_PYTHON=/opt/rh/python27/root/usr/bin/python2.7
export PATH=/opt/rh/python27/root/usr/bin:$PATH
export token=$(gcloud auth print-identity-token)
export instance_name=$(curl -H "Authorization: Bearer $token" -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/name")
export instance_zone=$(curl -H "Authorization: Bearer $token" -s -H "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/zone" | awk -F '/' '{ print $NF }')

export vip=10.11.12.13/32 
ip ad del $vip dev eth0

gcloud compute routes delete floating --quiet

gcloud compute routes create floating  --destination-range $vip --network ip-failover --priority 500 --next-hop-instance-zone $instance_zone --next-hop-instance $instance_name --quiet
ip ad ad $vip dev eth0

For a more complete walk through of what needs to be done, look at option 4 of the link below.
https://cloud.google.com/solutions/best-practices-floating-ip-addresses

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .