grpc-gke-nlb-tutorial
grpc-gke-nlb-tutorial copied to clipboard
gRPC load-balancing on GKE using Envoy
Using Envoy to load-balance gRPC services on GKE
This repository contains the code used in the tutorial Using Envoy Proxy to load-balance gRPC services on GKE.
This tutorial demonstrates how to expose multiple gRPC services deployed on Google Kubernetes Engine (GKE) via a single external IP address using Network Load Balancing and Envoy Proxy. The tutorial uses Envoy Proxy to highlight some of the advanced features it provides for gRPC.
Quick start
-
Create a self-signed TLS certificate and private key:
openssl req -x509 -newkey rsa:4096 -nodes -sha256 -days 365 \ -keyout privkey.pem -out cert.pem -extensions san \ -config \ <(echo "[req]"; echo distinguished_name=req; echo "[san]"; echo subjectAltName=DNS:grpc.example.com ) \ -subj '/CN=grpc.example.com'
-
Create a Kubernetes Secret called
envoy-certs
that contains the self-signed TLS certificate and private key:kubectl create secret tls envoy-certs --key=privkey.pem --cert=cert.pem \ --dry-run=client --output=yaml | kubectl apply --filename -
-
Build the container images for the sample apps
echo-grpc
andreverse-grpc
, and deploy all the resources in this repository to a Kubernetes cluster, using Skaffold:export SKAFFOLD_DEFAULT_REPO=gcr.io/$(gcloud config get-value core/project) skaffold run
Test the solution
-
Install
grpcurl
:go install github.com/fullstorydev/grpcurl/cmd/grpcurl@latest
If you don't have the Go distribution installed, you can instead download a binary release.
-
Get the external IP address of the
envoy
Kubernetes Service and store it in an environment variable:EXTERNAL_IP=$(kubectl get service envoy \ --output=jsonpath='{.status.loadBalancer.ingress[0].ip}')
-
Send a request to the
echo-grpc
sample app:grpcurl -d '{"content": "echo"}' -proto echo-grpc/api/echo.proto \ -authority grpc.example.com -cacert cert.pem -v \ $EXTERNAL_IP:443 api.Echo/Echo
-
Send a request to the
reverse-grpc
sample app:grpcurl -d '{"content": "reverse"}' -proto reverse-grpc/api/reverse.proto \ -authority grpc.example.com -cacert cert.pem -v \ $EXTERNAL_IP:443 api.Reverse/Reverse
Cleaning up
-
Delete the Kubernetes resources:
skaffold delete kubectl delete secret tls envoy-certs
-
Delete the container images from Container Registry:
gcloud container images list-tags gcr.io/$GOOGLE_CLOUD_PROJECT/echo-grpc \ --format 'value(digest)' | xargs -I {} gcloud container images delete \ --force-delete-tags --quiet gcr.io/$GOOGLE_CLOUD_PROJECT/echo-grpc@sha256:{} gcloud container images list-tags gcr.io/$GOOGLE_CLOUD_PROJECT/reverse-grpc \ --format 'value(digest)' | xargs -I {} gcloud container images delete \ --force-delete-tags --quiet gcr.io/$GOOGLE_CLOUD_PROJECT/reverse-grpc@sha256:{}
Disclaimer
This is not an officially supported Google product.