Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save constantlycoding/d81977d90be93f8b729977848e90cc08 to your computer and use it in GitHub Desktop.

Select an option

Save constantlycoding/d81977d90be93f8b729977848e90cc08 to your computer and use it in GitHub Desktop.
Set up GCP load balancers

Create load balancer

gcloud compute forwarding-rules create nginx-lb \
         --region us-central1 \
         --ports=80 \
         --target-pool nginx-pool

Check

gcloud compute forwarding-rules list

Create health check

gcloud compute http-health-checks create http-basic-check

Create HTTP service, map port

gcloud compute instance-groups managed \
       set-named-ports nginx-group \
       --named-ports http:80

Create backend service

gcloud compute backend-services create nginx-backend \
      --protocol HTTP --http-health-checks http-basic-check --global

Add instance group to backend service

gcloud compute backend-services add-backend nginx-backend \
    --instance-group nginx-group \
    --instance-group-zone us-central1-a \
    --global

Create URL map

gcloud compute url-maps create web-map \
    --default-service nginx-backend

Create HTTP proxy

gcloud compute target-http-proxies create http-lb-proxy \
    --url-map web-map

Create forwarding rule

gcloud compute forwarding-rules create http-content-rule \
        --global \
        --target-http-proxy http-lb-proxy \
        --ports 80

Check

gcloud compute forwarding-rules list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment