Create TCP/UDP Internal Load Balancer (ILB) on Google Cloud Platform (GCP) using managed and unmanaged instance groups
Creating Internal Load Balancer in Google Cloud Platform is easy and it is used to distribute the load across VM instances. In this guide we will see how to create TCP/UDP Load Balancer using managed and unmanaged instances.
Prerequisites:
1) Gcloud SDK must be installed in your local
2) Login to your designated gcp project
3) User or Service Account must have required IAM roles to create ILB
Create TCP/UDP ILB using Managed Instance group
Google’s managed instance group are the group of identical VM instances created using an instance template. These VM instances can be in different zones (regional) but with same region when multi zone is enabled while creating managed instance group(MIG). As by the name managed, this group has some important features like autoscaling, auto-healing, Rolling out updates.
To Create ILB, Follow the below steps sequentially
1) Create Managed Instance group using commandline or GUI or Google deployment manager or rest API
2) Create TCP heath check using below command line
gcloud compute health-checks create tcp <health-check-name> --description="Health check: TCP <port>" --check-interval=5s --timeout=5s --healthy-threshold=2 --unhealthy-threshold=2 --port=<port> --proxy-header=NONE --region=<health-check-region>
3) Create a backed service using below command line
gcloud compute backend-services create <backend-service-name> --load-balancing-scheme internal --health-checks <health-check-name> --protocol tcp --region <backend-service-region>
4) Assign the created managed instance group to the created backend service
gcloud compute backend-services add-backend <backend-service-name> --instance-group <instance-group-name> --instance-group-region=<instance-group-region> --region <backend-service-region>
5) Create a forwarding rule using below command line
gcloud compute forwarding-rules create <forwarding-rule-name> --load-balancing-scheme internal --address <ILB ip address> --ports <port> --subnet <full path of subnet> --region <forwarding rule region> --backend-service <backend-service-name>
Note: Managed instance group, backend service and forwarding rule must be in same region
Create TCP/UDP ILB using Unmanaged Instance group
An unmanaged instance group is a collection of user created/managed VM instances that are created in a same zone, VPC network, and subnet. Unmanaged instances will not have same instance template. We need to manually add user created/managed VM instances into unmanaged instance groups
To Create ILB, Follow the below steps sequentially
1) Assumed User created/managed instances are up and running. Then create Unmanaged instance group using below command line
gcloud compute instance-groups unmanaged create <instance-group-name-1> --zone=<zone1> gcloud compute instance-groups unmanaged create <instance-group-name-2> --zone=<zone2>
2) Add User created/managed instances to the created instance groups
gcloud compute instance-groups unmanaged add-instances <instance-group-name-1> --instances <instance-name-1>,<instance-name-2> --zone=<zone1> gcloud compute instance-groups unmanaged add-instances instance-group-name-2> --instances <instance-name-3>,<instance-name-4> --zone=<zone2>
Note: Unmanaged instance group will be created only with same zone instances
3) Verify User created/managed instances are grouped under unmanaged instance group by using below command line
gcloud compute instance-groups unmanaged list-instances <instance-group-name-1> --zone=<zone1> gcloud compute instance-groups unmanaged list-instances <instance-group-name-2> --zone=<zone2>
4) Create TCP heath check using below command line
gcloud compute health-checks create tcp <health-check-name> --description="Health check: TCP <port>" --check-interval=5s --timeout=5s --healthy-threshold=2 --unhealthy-threshold=2 --port=<port> --proxy-header=NONE --region=<health-check-region>
5) Create a backed service using below command line
gcloud compute backend-services create <backend-service-name> --load-balancing-scheme internal --health-checks <health-check-name> --protocol tcp --region <backend-service-region>
6) Assign the created unmanaged instance groups to the created backend service
gcloud compute backend-services add-backend <backend-service-name> --instance-group <instance-group-name-1> --instance-group-zone <instance-group-zone-1> --region <backend-service-region> gcloud compute backend-services add-backend <backend-service-name> --instance-group <instance-group-name-2> --instance-group-zone <instance-group-zone-2> --region <backend-service-region>Create a forwarding rule using below command line
7) Create a forwarding rule using below command line
gcloud compute forwarding-rules create <forwarding-rule-name> --load-balancing-scheme internal --address <ILB ip address> --ports <port> --subnet <full path of subnet> --region <forwarding rule region> --backend-service <backend-service-name>
Note: Unmanaged instance group, backend service and forwarding rule must be in same region