Voiced by Amazon Polly |
Introduction
Google Cloud Load Balancing is a powerful and flexible solution for distributing traffic across multiple backend instances. In this blog, we will explore Network Endpoint Groups (NEGs), their role in load balancing, and how we configured them in our recent lab experiment.
Stand out from the competition. Upskill with Google Cloud Certifications.
- Certified Instructors
- Real-world Projects
What are Network Endpoint Groups (NEGs)?
Network Endpoint Groups (NEGs) are a crucial component in Google Cloud that allow load balancers to route traffic to specific endpoints, such as Cloud Run services, Cloud Functions, or App Engine instances. Unlike traditional backend instance groups, NEGs enable granular traffic routing and better integration with serverless computing.
Types of NEGs:
- Zonal NEGs – Used for VM instances with specific network interfaces.
- Internet NEGs – Used for backend services hosted outside Google Cloud.
- Serverless NEGs – Used for Cloud Run, App Engine, and Cloud Functions.
Why Use NEGs?
- Fine-grained traffic control: NEGs allow routing traffic to individual services rather than entire instance groups.
- Multi-region support: NEGs enable distribution of traffic across multiple regions for better availability.
- Serverless integration: They seamlessly integrate with Cloud Run, App Engine, and Cloud Functions.
- Optimized performance: Load balancing decisions can be made closer to the request origin, reducing latency.
Lab Exercise: Configuring a Load Balancer with NEGs
Objective
To create an external HTTP Load Balancer with serverless NEGs as backends for routing traffic to multiple Cloud Run services.
Steps Performed
- Create Cloud Run Services
We deployed two Cloud Run services in different regions:
# Deploy service in us-central1
1 |
gcloud run deploy hello-world-us --region=us-central1 --platform=managed –allow-unauthenticated --image=gcr.io/cloudrun/hello |
# Deploy service in asia-south1
1 |
gcloud run deploy hello-world-asia --region=asia-south1 --platform=managed –allow unauthenticated --image=gcr.io/cloudrun/hello |
- Create Serverless NEGs
# Create NEG for us-central1
1 |
gcloud compute network-endpoint-groups create hello-neg --region=us-central1 --network-endpoint-type=serverless --cloud-run-service=hello-world-us |
# Create NEG for asia-south1
1 |
gcloud compute network-endpoint-groups create hello1-neg --region=asia-south1 --network-endpoint-type=serverless --cloud-run-service=hello-world-asia |
- Create Backend Services and Attach NEGs
# Create backend service for us-central1
1 |
gcloud compute backend-services create backend-service-1 --global --protocol=HTTP |
1 |
gcloud compute backend-services add-backend backend-service-1 --global --network-endpoint-group=hello-neg --network-endpoint-group-region=us-central1 |
# Create backend service for asia-south1
1 |
gcloud compute backend-services create backend-service-2 --global --protocol=HTTP |
1 |
gcloud compute backend-services add-backend backend-service-2 --global --network-endpoint-group=hello1-neg --network-endpoint-group-region=asia-south1 |
- Create URL Map and HTTP Proxy
# Create URL map
1 |
gcloud compute url-maps create cloud-run-url-map --default-service=backend-service-1 |
# Create HTTP proxy
1 |
gcloud compute target-http-proxies create cloud-run-http-proxy --url-map=cloud-run-url-map |
- Create a Global Forwarding Rule
1 |
gcloud compute forwarding-rules create cloud-run-fw-rule --global --target-http-proxy=cloud-run-http-proxy --ports=80 |
- Test the Load Balancer
Once the setup was complete, we obtained the external IP of the forwarding rule and tested it using a browser or cURL command:
curl http://[EXTERNAL_IP]
Observations
- We observed that traffic was correctly distributed between the two Cloud Run services based on regional availability.
- The Load Balancer provided a single entry point for multiple backend services hosted in different regions.
- By using NEGs, we achieved a serverless, scalable, and efficient load-balancing solution.
Conclusion
NEGs provide a powerful mechanism to integrate Google Cloud Load Balancing with serverless and hybrid environments. Our lab experiment demonstrated how NEGs can be used to route traffic efficiently between multiple Cloud Run services deployed across different regions. By leveraging NEGs, organizations can optimize performance, improve availability, and achieve a seamless user experience.
Next Steps
- Explore additional routing configurations using URL maps.
- Implement health checks for backend services.
- Enable logging and monitoring
Get your new hires billable within 1-60 days. Experience our Capability Development Framework today.
- Cloud Training
- Customized Training
- Experiential Learning
About CloudThat
CloudThat is a leading provider of Cloud Training and Consulting services with a global presence in India, the USA, Asia, Europe, and Africa. Specializing in AWS, Microsoft Azure, GCP, VMware, Databricks, and more, the company serves mid-market and enterprise clients, offering comprehensive expertise in Cloud Migration, Data Platforms, DevOps, IoT, AI/ML, and more.
CloudThat is the first Indian Company to win the prestigious Microsoft Partner 2024 Award and is recognized as a top-tier partner with AWS and Microsoft, including the prestigious ‘Think Big’ partner award from AWS and the Microsoft Superstars FY 2023 award in Asia & India. Having trained 650k+ professionals in 500+ cloud certifications and completed 300+ consulting projects globally, CloudThat is an official AWS Advanced Consulting Partner, Microsoft Gold Partner, AWS Training Partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, AWS GenAI Competency Partner, Amazon QuickSight Service Delivery Partner, Amazon EKS Service Delivery Partner, AWS Microsoft Workload Partners, Amazon EC2 Service Delivery Partner, Amazon ECS Service Delivery Partner, AWS Glue Service Delivery Partner, Amazon Redshift Service Delivery Partner, AWS Control Tower Service Delivery Partner, AWS WAF Service Delivery Partner, Amazon CloudFront, Amazon OpenSearch, AWS DMS, AWS Systems Manager, Amazon RDS, and many more.
WRITTEN BY Laxmi Sharma
Comments