Configuring Load Balancer in GCP Shared VPC

1. Pick a VIP address, the VIP you choose shouldn’t overlap with existing subnetwork range configured in the VPC in use or in the customer on prem. network connected to the VPC.

From the EMS, for each eNode, add the VIP as an alias IP address, needed for the eNode to accept traffic designated to the VIP IP address:

2. Set VIP and eNodes list in variables, assuming the VIP address is 172.22.0.1 and eNodes are enode-01, enode-02 and enode-03:
$ VIP="172.22.0.1/32"
$ ENODES="enode-01,enode-02,enode-03"


Execute the following to configure VIP and force startup script reload:

$ cat >> configure_vip.sh <<EOF
> #!/bin/bash
> ip address add ${VIP} dev eth0
> EOF


$ for ENODE in ${ENODES//,/ }; do gcloud compute instances add-metadata  $ENODE --metadata-from-file startup-script=configure_vip.sh; done;


3. Login to each eNode instance from EMS and execute the following commands, on each eNode to force startup script rerun:

$ google_metadata_script_runner --script-type startup
$ journalctl -u google-startup-scripts.service


4. using the network admin role of the shared vpc, create routes with the same weight for each eNode

using the VIP address for destination range, for example on VPC network named my-shared-vpc, use the following gcloud command.
$ VIP="172.22.0.1/32"$ SHARED_VPC_NAME="my-shared-vpc"$ declare -a ENODES=("enode-01 "enode-02" "enode-03")
$ declare -a ENODES_IPS=("enode-01-internal-ip" "enode-02-internal-ip" "enode-03-internal-ip")$ NUM_NODES=${#ENODES[@]}$ for ((i=0; i<NUM_NODES; i++)); do gcloud compute routes create el-route-${ENODES[$i]} --destination-range=$VIP --next-hop-address=${ENODES_IPS[$i]} --network=$SHARED_VPC_NAME; done;


When adding a new eNode- repeat steps 2-4

When removing an existing eNode- delete the corresponding route to stop traffic from trying to reach the removed eNode

S
Snir is the author of this solution article.

Did you find it helpful? Yes No

Send feedback
Sorry we couldn't be helpful. Help us improve this article with your feedback.