Here’s how to display a list of application load balancers.
aws elbv2 describe-load-balancers --profile --region us-east-1 |
Here’s how to display classic load balancers.
aws elb describe-load-balancers --profile --region us-east-1 |
cloud engineer
by Ulysses
Here’s how to display a list of application load balancers.
aws elbv2 describe-load-balancers --profile --region us-east-1 |
aws elbv2 describe-load-balancers --profile --region us-east-1
Here’s how to display classic load balancers.
aws elb describe-load-balancers --profile --region us-east-1 |
aws elb describe-load-balancers --profile --region us-east-1
by Ulysses
Here’s how to display a list of Google Cloud forwarding rules.
gcloud compute forwarding-rules list |
gcloud compute forwarding-rules list
If you want global only.
gcloud compute forwarding-rules --global |
gcloud compute forwarding-rules --global
Or just local regions only.
gcloud compute forwarding-rules --filter="region:( us-central us-west1 )" |
gcloud compute forwarding-rules --filter="region:( us-central us-west1 )"
by Ulysses
Here’s the AWS CLI to register instances to a load balancer.
aws elb register-instances-with-load-balancer \ --load-balancer-name my-load-balancer \ --instances i-xxxxxxxxxxx i-xxxxxxxxxxx i-xxxxxxxxxxx |
aws elb register-instances-with-load-balancer \ --load-balancer-name my-load-balancer \ --instances i-xxxxxxxxxxx i-xxxxxxxxxxx i-xxxxxxxxxxx
by Ulysses
I ran into an issue with Google Compute Engine TCP internal load balancer. The targets are unhealthy although all configs were correct installed. At one time the targets were working, but somehow they became unhealthy. In the end, 3 things needed to be checked.
You will need to change the server’s IP from DHCP to static to add ILB VIP.
by Ulysses
Here’s how to setup a Network Load Balancer in GCP.
Setup your instances.
# Instance 1 gcloud compute instances create www1 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www1</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 2 gcloud compute instances create www2 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www2</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 3 gcloud compute instances create www3 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www3</h1></body></html>' | tee /var/www/html/index.html EOF" |
# Instance 1 gcloud compute instances create www1 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www1</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 2 gcloud compute instances create www2 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www2</h1></body></html>' | tee /var/www/html/index.html EOF" # Instance 3 gcloud compute instances create www3 \ --image-family debian-9 \ --image-project debian-cloud \ --zone us-central1-b \ --tags network-lb-tag \ --metadata startup-script="#! /bin/bash sudo apt-get update sudo apt-get install apache2 -y sudo service apache2 restart echo '<!doctype html><html><body><h1>www3</h1></body></html>' | tee /var/www/html/index.html EOF"
Create a firewall to allow external traffic to reach port 80.
gcloud compute firewall-rules create www-firewall-network-lb \ --target-tags network-lb-tag --allow tcp:80 |
gcloud compute firewall-rules create www-firewall-network-lb \ --target-tags network-lb-tag --allow tcp:80
Configure your network load balancer.
# Create an external IP address. gcloud compute addresses create network-lb-ip-1 \ --region us-central1 # Add a legacy HTTP health check. gcloud compute http-health-checks create basic-check # Add a target pool. gcloud compute target-pools add-instances www-pool \ --instances www1,www2,www3 \ --instances-zone us-central1-b # Add a forwarding rule. gcloud compute forwarding-rules create www-rule \ --region us-central1 \ --ports 80 \ --address network-lb-ip-1 \ --target-pool www-pool # Lookup external IP address. gcloud compute forwarding-rules describe www-rule \ --region us-central1 |
# Create an external IP address. gcloud compute addresses create network-lb-ip-1 \ --region us-central1 # Add a legacy HTTP health check. gcloud compute http-health-checks create basic-check # Add a target pool. gcloud compute target-pools add-instances www-pool \ --instances www1,www2,www3 \ --instances-zone us-central1-b # Add a forwarding rule. gcloud compute forwarding-rules create www-rule \ --region us-central1 \ --ports 80 \ --address network-lb-ip-1 \ --target-pool www-pool # Lookup external IP address. gcloud compute forwarding-rules describe www-rule \ --region us-central1
Finally, use the curl command to send traffic to the NLB external IP address.
while true; do curl -m1 [IP_ADDRESS]; done |
while true; do curl -m1 [IP_ADDRESS]; done
by Ulysses
You can use the curl command to test if your load balancer is working as expected. The curl command will alternately and randomly access several instances in your load balancer. If you have 3 instances behind your load balancer, it will be cycled across all 3. The -m1 command means max time is set to 1 second.
while true; do curl -m1 [IP_ADDRESS]; done |
while true; do curl -m1 [IP_ADDRESS]; done
by Ulysses
Test if the GCP Load Balancer is working by sending a curl command from the backend VM.
Assume the load balancer IP address is 10.1.2.99, and the VM is called vm-a1.
curl http://10.1.2.99 |
curl http://10.1.2.99
The end result is …
Page served from: vm-a1 |
Page served from: vm-a1
Make sure there’s an entry in the local table that matches the IP of the load balancer.
ip route show table local | grep 10.1.2.99 |
ip route show table local | grep 10.1.2.99
If not, add it.
ip route add to local 10.1.2.99/32 dev eth0 proto 66 |
ip route add to local 10.1.2.99/32 dev eth0 proto 66