This sample shows how to use Apigee in front of your gRPC backends. For this example we will be using Cloud Run to host a gRPC server and configure it as a target server in Apigee. Apigee will act as a simple reverse proxy in front of the gRPC backend. For more detailed information on using gRPC proxies in Apigee, please refer to the official documentation.
-
Configure external access for API traffic to your Apigee X instance
-
Access to deploy proxies, create products, apps and developers in Apigee
-
Make sure the following tools are available in your terminal's $PATH (Cloud Shell has these preconfigured)
- gcloud SDK
- unzip
- curl
- jq
- npm
- docker
-
The following GCP APIs will be enabled:
- Cloud Run API
- Container Registry API
- Compute Engine API
-
Make sure that you have ONE the following permissions:
- Owner role
- Editor role
The following set of roles:
- Cloud Build Editor role
- Artifact Registry Admin role
- Storage Admin role
- Cloud Run Admin role
- Service Account User role
Use the following GCP CloudShell tutorial, and follow the instructions.
- Clone the
apigee-samplesrepo, and switch thegrpcdirectory
git clone https://github.com/GoogleCloudPlatform/apigee-samples.git
cd apigee-samples/grpc- Edit the
env.shfile and configure the following variables:
PROJECTthe project where your Apigee organization is locatedNETWORKthe VPC network where the PSC NEG will be deployedSUBNETthe VPC subnet where the PSC NEG will be deployed
Now source the env.sh file
source ./env.shLet's run the script that will create and deploy the resources necessary to test the gRPC functionality. This script will create the following:
- An External Loadbalancer with an HTTP2 backend
- Deploy a sample gRPC Greeter service to Cloud Run
- Deploy an API proxy, target server, developer, app and api product
Finally it tests that the deployment and configuration has been successful.
- Run the deploy.sh script:
./deploy.shTo manually test the proxy, make requests using grpcurl or another gRPC client:
grpcurl -H "x-apikey:$CLIENT_ID" -import-path $PWD/grpc-backend/examples/protos -proto helloworld.proto -d '{"name\":"Guest"}' <YOUR_APIGEE_GRPC_HOSTNAME>:443 helloworld.Greeter/SayHello"If you want to clean up the artifacts from this example in your Apigee Organization, first source your env.sh script, and then run
./clean-up.sh