Modify network tags for instance in startup & shutdown scripts

374 views
Skip to first unread message

Ash N

unread,
Mar 28, 2018, 7:47:42 PM3/28/18
to gce-discussion
Hi,

I want to add a network tag in the startup script, and remove the same network tag in the shutdown script, so that the instance is instantly added/removed from load balancer routing.

Is it possible to add and remove network tags in the startup and shutdown scripts of an instance?

What's the best & simplest way to go about doing what I'm trying?

Thanks.

Ash N

unread,
Mar 29, 2018, 1:21:32 AM3/29/18
to gce-discussion
I got it working:

#!/bin/bash

INSTANCE_NAME
=$(curl http://metadata.google.internal/computeMetadata/v1/instance/name -H "Metadata-Flavor: Google")
INSTANCE_ZONE
=$(curl http://metadata.google.internal/computeMetadata/v1/instance/zone -H "Metadata-Flavor: Google")
gcloud compute instances add
-tags $INSTANCE_NAME --tags=tcp-lb --zone=$INSTANCE_ZONE

gcloud requires 'Compute Engine: Read/Write' permission for Cloud API access.

Although, I'm unsure how much of an impact will it have for load balancer routing, as I'm guessing LB will automatically route based on instance state (started/stopped) and health checks.

Navi Aujla (Google Cloud Support)

unread,
Mar 29, 2018, 1:32:19 PM3/29/18
to gce-discussion
Hello Ash,

You got the right command to add the network tags to the instance. Same way you can use following command in the script to remove the tags:

gcloud compute instances remove-tags [INSTANCE_NAME] --tags tag-1,tag-2 --zone ZONE 

Load Balancing routing is not impacted by the network-tags applied on the instances. You can check the documentation[1][2] for more information on the load balancing and routing decision based on the type of the load balancer in use. 

"Network tags[3] are used by networks to identify which Compute Engine virtual machine (VM) instances are subject to certain firewall rules and network routes."

Here is the documentation[4] for more information on using network tags in creating routes.  

Ash N

unread,
Mar 29, 2018, 9:32:28 PM3/29/18
to gce-discussion
Thanks, so it looks like network tags are not suitable for load balancing.

Besides health checks and instance state (started/stopped), are there any other programmable options to instantly include & exclude instances from being load balanced?

Navi Aujla (Google Cloud Support)

unread,
Mar 30, 2018, 10:12:47 AM3/30/18
to gce-discussion
Hello Ash, 

Depending upon the Load balancer type, algorithm works differently. For HTTP(s) load balancer, Balancing mode can be configured which can be based on CPU Utilization or Rate requests per second (RPS). For network load balancer algorithm, refer to this documentation link

There is also a feature request in place to configure load balancer to distribute traffic to instance group bu percentage. You can "Star" this feature request to show your interest. 

I would recommend you to go through the documentation for the load balancers for more information on the load balancing algorithm, component and their functionality. 
Reply all
Reply to author
Forward
0 new messages