| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
parent directory.. | ||||
It is assumed that you have a working Python environment and a Google Cloud account and SDK configured.
Install dependencies using virtualenv:
virtualenv -p python3 env
source env/bin/activate
pip install -r requirements.txtTest running the code, optional:
# Run the server:
python greeter_server.py
# Open another command line tab and enter the virtual environment:
source env/bin/activate
# In the new command line tab, run the client:
python greeter_client.pyThe gRPC Services have already been generated. If you change the proto, or just wish to regenerate these files, run:
python -m grpc_tools.protoc -I protos --python_out=. --grpc_python_out=. protos/helloworld.protoGenerate the out.pb from the proto file:
python -m grpc_tools.protoc --include_imports --include_source_info -I protos protos/helloworld.proto --descriptor_set_out out.pbEdit, api_config.yaml. Replace MY_PROJECT_ID with your project id.
Deploy your service config to Service Management:
gcloud service-management deploy out.pb api_config.yaml
# The Config ID should be printed out, looks like: 2017-02-01r0, remember this
# Set your project ID as a variable to make commands easier:
GCLOUD_PROJECT=<Your Project ID>
# Print out your Config ID again, in case you missed it:
gcloud service-management configs list --service hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.googAlso get an API key from the Console's API Manager for use in the client later. (https://console.cloud.google.com/apis/credentials)
Enable the Cloud Build API:
gcloud service-management enable cloudbuild.googleapis.comBuild a docker image for your gRPC server, and store it in your Registry:
gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/python-grpc-hello:1.0 .Either deploy to GCE (below) or GKE (further down).
Enable the Compute Engine API:
gcloud service-management enable compute-component.googleapis.comCreate your instance and ssh in:
gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server
gcloud compute ssh grpc-hostSet some variables to make commands easier:
GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google")
SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog
SERVICE_CONFIG_ID=<Your Config ID>Pull your credentials to access Container Registry, and run your gRPC server container:
/usr/share/google/dockercfg_update.sh
docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/python-grpc-hello:1.0Run the Endpoints proxy:
docker run --detach --name=esp \
-p 80:9000 \
--link=grpc-hello:grpc-hello \
gcr.io/endpoints-release/endpoints-runtime:1 \
-s ${SERVICE_NAME} \
-v ${SERVICE_CONFIG_ID} \
-P 9000 \
-a grpc://grpc-hello:50051Back on your local machine, get the external IP of your GCE instance:
gcloud compute instances listRun the client:
python greeter_client.py --host=<IP of GCE Instance>:80 --api_key=<API Key from Console>Cleanup:
gcloud compute instances delete grpc-hostCreate a cluster. You can specify a different zone than us-central1-a if you want:
gcloud container clusters create my-cluster --zone=us-central1-aEdit container-engine.yaml. Replace SERVICE_NAME, SERVICE_CONFIG_ID, and GCLOUD_PROJECT with your values:
SERVICE_NAME is equal to hellogrpc.endpoints.GCLOUD_PROJECT.cloud.goog, replacing GCLOUD_PROJECT with your project ID.
SERVICE_CONFIG_ID can be found by running the following command, replacing GCLOUD_PROJECT with your project ID.
gcloud service-management configs list --service hellogrpc.endpoints.GCLOUD_PROJECT.cloud.googDeploy to GKE:
kubectl create -f ./container-engine.yamlGet IP of load balancer, run until you see an External IP:
kubectl get svc grpc-helloRun the client:
python greeter_client.py --host=<IP of GKE LoadBalancer>:80 --api_key=<API Key from Console>Cleanup:
gcloud container clusters delete my-cluster --zone=us-central1-a| Back | FazBrowse Home | New Git URL |