f GCP : http NLB set up case ~ 迪貝之家

GCP : http NLB set up case

 


gcloud config set compute/zone us-east1-b 

gcloud config set compute/region us-east1


gcloud compute instance-templates create nginx-template \

   --region=us-east1 \

   --machine-type f1-micro \

   --network=default \

   --subnet=default \

   --tags=allow-health-check \

   --image-family=debian-9 \

   --image-project=debian-cloud \

--metadata=startup-script=\#\!\ /bin/bash$'\n'apt-get\ update$'\n'apt-get\ install\ -y\ nginx$'\n'service\ nginx\ start$'\n'sed\ -i\ --\ \'s/nginx/Google\ Cloud\ Platform\ -\ \'\"\$HOSTNAME\"\'/\'\ /var/www/html/index.nginx-debian.html 

 


gcloud compute instance-groups managed create nginx-group --base-instance-name=nginx --template=nginx-template --size=2 --zone=us-east1-b


gcloud compute firewall-rules create nginx-health-check \

    --network=default \

    --action=allow \

    --direction=ingress \

    --source-ranges=130.211.0.0/22,35.191.0.0/16 \

    --target-tags=allow-health-check \

    --rules=tcp:80

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

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

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





B: URL-MAP的規則: 定義封包應該要往那些VM 走

gcloud compute backend-services add-backend nginx-backend --instance-group nginx-group --global

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


---------------------------------------------------------------------

要到固定的Public IP

gcloud compute addresses create nginx-lb-ip     --ip-version=IPV4  --global

gcloud compute addresses describe nginx-lb-ip \

    --format="get(address)" \

    --global

------------------------------------------------------------------------


A: NLB FronEnd : Inernet 的封包送到這裡來

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

gcloud compute forwarding-rules create http-content-rule\

        --address=nginx-lb-ip\   <-綁定固定IP

        --global \

        --target-http-proxy=nginx-lb-proxy \  <-要轉到哪個backend 服務,參照URL-MAP

--ports=80

Internet -> A ->B

麻煩由下往上看

這是我的理解

有可能是錯的

這只是個很單純的Case

實際碰到的業務環境

可能不會這麼簡單

因為很多的VPC 會串在一起









A forwarding rule and its corresponding IP address represent the frontend configuration of a Google Cloud load balancer.