|
| 1 | +# Endpoints Getting Started with gRPC & Java Quickstart |
| 2 | + |
| 3 | +It is assumed that you have a working gRPC and Java environment. |
| 4 | + |
| 5 | +1. Build the code: |
| 6 | + |
| 7 | + ``` |
| 8 | + ./gradlew build |
| 9 | + ``` |
| 10 | +
|
| 11 | +1. Test running the code, optional: |
| 12 | +
|
| 13 | + ``` |
| 14 | + # In the background or another terminal run the server: |
| 15 | + java -jar server/build/libs/server.jar |
| 16 | +
|
| 17 | + # Check the client parameters: |
| 18 | + java -jar client/build/libs/client.jar --help |
| 19 | +
|
| 20 | + # Run the client |
| 21 | + java -jar client/build/libs/client.jar --greetee 'Endpoints!' |
| 22 | + ``` |
| 23 | +
|
| 24 | +1. Generate the `out.pb` from the proto file. |
| 25 | +
|
| 26 | + ``` |
| 27 | + protoc --include_imports --include_source_info api/src/main/proto/helloworld.proto --descriptor_set_out out.pb |
| 28 | + ``` |
| 29 | +
|
| 30 | +1. Edit, `api_config.yaml`. Replace `MY_PROJECT_ID` with your project id. |
| 31 | +
|
| 32 | +1. Deploy your service config to Service Management: |
| 33 | +
|
| 34 | + ``` |
| 35 | + gcloud service-management deploy out.pb api_config.yaml |
| 36 | + # The Config ID should be printed out, looks like: 2017-02-01r0, remember this |
| 37 | +
|
| 38 | + # set your project to make commands easier |
| 39 | + GCLOUD_PROJECT=<Your Project ID> |
| 40 | +
|
| 41 | + # Print out your Config ID again, in case you missed it |
| 42 | + gcloud service-management configs list --service hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog |
| 43 | + ``` |
| 44 | +
|
| 45 | +1. Also get an API key from the Console's API Manager for use in the client later. (https://console.cloud.google.com/apis/credentials) |
| 46 | +
|
| 47 | +1. Build a docker image for your gRPC server, store in your Registry |
| 48 | +
|
| 49 | + ``` |
| 50 | + gcloud container builds submit --tag gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 . |
| 51 | + ``` |
| 52 | +
|
| 53 | +1. Either deploy to GCE (below) or GKE (further down) |
| 54 | +
|
| 55 | +### GCE |
| 56 | +
|
| 57 | +1. Create your instance and ssh in. |
| 58 | +
|
| 59 | + ``` |
| 60 | + gcloud compute instances create grpc-host --image-family gci-stable --image-project google-containers --tags=http-server |
| 61 | + gcloud compute ssh grpc-host |
| 62 | + ``` |
| 63 | +
|
| 64 | +1. Set some variables to make commands easier |
| 65 | +
|
| 66 | + ``` |
| 67 | + GCLOUD_PROJECT=$(curl -s "http://metadata.google.internal/computeMetadata/v1/project/project-id" -H "Metadata-Flavor: Google") |
| 68 | + SERVICE_NAME=hellogrpc.endpoints.${GCLOUD_PROJECT}.cloud.goog |
| 69 | + SERVICE_CONFIG_ID=<Your Config ID> |
| 70 | + ``` |
| 71 | +
|
| 72 | +1. Pull your credentials to access Container Registry, and run your gRPC server container |
| 73 | +
|
| 74 | + ``` |
| 75 | + /usr/share/google/dockercfg_update.sh |
| 76 | + docker run -d --name=grpc-hello gcr.io/${GCLOUD_PROJECT}/java-grpc-hello:1.0 |
| 77 | + ``` |
| 78 | +
|
| 79 | +1. Run the Endpoints proxy |
| 80 | +
|
| 81 | + ``` |
| 82 | + docker run --detach --name=esp \ |
| 83 | + -p 80:9000 \ |
| 84 | + --link=grpc-hello:grpc-hello \ |
| 85 | + gcr.io/endpoints-release/endpoints-runtime:1 \ |
| 86 | + -s ${SERVICE_NAME} \ |
| 87 | + -v ${SERVICE_CONFIG_ID} \ |
| 88 | + -P 9000 \ |
| 89 | + -a grpc://grpc-hello:50051 |
| 90 | + ``` |
| 91 | +
|
| 92 | +1. Back on your local machine, get the external IP of your GCE instance. |
| 93 | +
|
| 94 | + ``` |
| 95 | + gcloud compute instances list |
| 96 | + ``` |
| 97 | +
|
| 98 | +1. Run the client |
| 99 | +
|
| 100 | + ``` |
| 101 | + java -jar client/build/libs/client.jar --host <IP of GCE Instance>:80 --api_key <API Key from Console> |
| 102 | + ``` |
| 103 | +
|
| 104 | +### GKE |
| 105 | +
|
| 106 | +1. Create a cluster |
| 107 | +
|
| 108 | + ``` |
| 109 | + gcloud container clusters create my-cluster |
| 110 | + ``` |
| 111 | +
|
| 112 | +1. Edit `container-engine.yaml`. Replace `SERVICE_NAME`, `SERVICE_CONFIG_ID`, and `GCLOUD_PROJECT` with your values. |
| 113 | +
|
| 114 | +1. Deploy to GKE |
| 115 | +
|
| 116 | + ``` |
| 117 | + kubectl create -f ./container-engine.yaml |
| 118 | + ``` |
| 119 | +
|
| 120 | +1. Get IP of load balancer, run until you see an External IP. |
| 121 | +
|
| 122 | + ``` |
| 123 | + kubectl get svc grpc-hello |
| 124 | + ``` |
| 125 | +
|
| 126 | +1. Run the client |
| 127 | +
|
| 128 | + ``` |
| 129 | + java -jar client/build/libs/client.jar --host <IP of GKE LoadBalancer>:80 --api_key <API Key from Console> |
| 130 | + ``` |
0 commit comments