this is my first time ever creating a network load balancer, well, i know the gist of it but i havent really created one. i got the opportunity to create one from a google cloud labs, so maybe these commands are specifically for gcp but yeah, you will get the idea of it eventually.
tagstcp:80 to those instanceswell yeah, basically just go ahead and create some similar instances with a tags so that yall can use all this three instances in a “group”. the gcloud command is something like this
gcloud compute instances create www1 \ --zone=Zone \ --tags=network-lb-tag \ --machine-type=e2-small \ --image-family=Debian image ID \ --image-project=debian-cloud \ --metadata=startup-script='#!/bin/bash apt-get update apt-get install apache2 -y service apache2 restart echo "<h3>Web Server: www1</h3>" | tee /var/www/html/index.html'well basically just create 2 more and youre done
tcp:80 to those instancessince we are using gcp, i think by default the 80 port is disabled? so we have to enable it so that our vms can communicate with the lb itself
gcloud compute firewall-rules create www-firewall-network-lb \ --target-tags network-lb-tag --allow tcp:80well, a load balancer needs an ip so that they can communicate with the user and the vms itself right? so lets create one
gcloud compute addresses create network-lb-ip-1 \ --region Regionthe last thing you need to do is to create pool and forwarding pool
gcloud compute target-pools create www-pool \ --region Region --http-health-check basic-checkand then add the instances to the pool
gcloud compute target-pools add-instances www-pool \ --instances www1,www2,www3lastly create a forwarding pool so that the traffic can be directed to the backend services
gcloud compute forwarding-rules create www-rule \ --region Region \ --ports 80 \ --address network-lb-ip-1 \ --target-pool www-pooland voila, a basic load balancer is created. obviously, in production, it will not be as simple as this me thinks. but by creating this, you will get the big idea on how load balancer really works rather than just says “oh it distributes traffic”. you know what really needed to create one and whats going on the background.