| 1 |
gRPC Hostname Example |
| 2 |
===================== |
| 3 |
|
| 4 |
The hostname example is a Hello World server whose response includes its |
| 5 |
hostname. It also supports health and reflection services. This makes it a good |
| 6 |
server to test infrastructure, like load balancing. This example depends on a |
| 7 |
gRPC version of 1.28.1 or newer. |
| 8 |
|
| 9 |
### Run the Server |
| 10 |
|
| 11 |
1. Navigate to this directory: |
| 12 |
|
| 13 |
```sh |
| 14 |
cd grpc/examples/python/xds |
| 15 |
``` |
| 16 |
|
| 17 |
2. Run the server |
| 18 |
|
| 19 |
```sh |
| 20 |
virtualenv venv -p python3 |
| 21 |
source venv/bin/activate |
| 22 |
pip install -r requirements.txt |
| 23 |
python server.py |
| 24 |
``` |
| 25 |
|
| 26 |
### Run the Client |
| 27 |
|
| 28 |
1. Set up xDS configuration. |
| 29 |
|
| 30 |
After configuring your xDS server to track the gRPC server we just started, |
| 31 |
create a bootstrap file as desribed in [gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md): |
| 32 |
|
| 33 |
``` |
| 34 |
{ |
| 35 |
xds_servers": [ |
| 36 |
{ |
| 37 |
"server_uri": <string containing URI of xds server>, |
| 38 |
"channel_creds": [ |
| 39 |
{ |
| 40 |
"type": <string containing channel cred type>, |
| 41 |
"config": <JSON object containing config for the type> |
| 42 |
} |
| 43 |
] |
| 44 |
} |
| 45 |
], |
| 46 |
"node": <JSON form of Node proto> |
| 47 |
} |
| 48 |
``` |
| 49 |
|
| 50 |
2. Point the `GRPC_XDS_BOOTSTRAP` environment variable at the bootstrap file: |
| 51 |
|
| 52 |
``` |
| 53 |
export GRPC_XDS_BOOTSTRAP=/etc/xds-bootstrap.json |
| 54 |
``` |
| 55 |
|
| 56 |
3. Run the client: |
| 57 |
|
| 58 |
``` |
| 59 |
python client.py xds:///my-backend |
| 60 |
``` |
| 61 |
|
| 62 |
### Verifying Configuration with a CLI Tool |
| 63 |
|
| 64 |
Alternatively, `grpcurl` can be used to verify your server. If you don't have it, |
| 65 |
install [`grpcurl`](https://github.com/fullstorydev/grpcurl/releases). This will allow |
| 66 |
you to manually test the service. |
| 67 |
|
| 68 |
Be sure to set up the bootstrap file and `GRPC_XDS_BOOTSTRAP` as in the previous |
| 69 |
section. |
| 70 |
|
| 71 |
1. Verify the server's application-layer service: |
| 72 |
|
| 73 |
```sh |
| 74 |
> grpcurl --plaintext -d '{"name": "you"}' localhost:50051 |
| 75 |
{ |
| 76 |
"message": "Hello you from rbell.svl.corp.google.com!" |
| 77 |
} |
| 78 |
``` |
| 79 |
|
| 80 |
2. Verify that all services are available via reflection: |
| 81 |
|
| 82 |
```sh |
| 83 |
> grpcurl --plaintext localhost:50051 list |
| 84 |
grpc.health.v1.Health |
| 85 |
grpc.reflection.v1alpha.ServerReflection |
| 86 |
helloworld.Greeter |
| 87 |
``` |
| 88 |
|
| 89 |
3. Verify that all services are reporting healthy: |
| 90 |
|
| 91 |
```sh |
| 92 |
> grpcurl --plaintext -d '{"service": "helloworld.Greeter"}' localhost:50051 |
| 93 |
grpc.health.v1.Health/Check |
| 94 |
{ |
| 95 |
"status": "SERVING" |
| 96 |
} |
| 97 |
|
| 98 |
> grpcurl --plaintext -d '{"service": ""}' localhost:50051 |
| 99 |
grpc.health.v1.Health/Check |
| 100 |
{ |
| 101 |
"status": "SERVING" |
| 102 |
} |
| 103 |
``` |
| 104 |
|
| 105 |
### Running with Proxyless Security |
| 106 |
|
| 107 |
#### Run the Server with Secure Credentials |
| 108 |
|
| 109 |
Add the `--secure true` flag to the invocation outlined above. |
| 110 |
|
| 111 |
```sh |
| 112 |
python server.py --secure true |
| 113 |
``` |
| 114 |
|
| 115 |
#### Run the Client with Secure Credentials |
| 116 |
|
| 117 |
Add the `--secure true` flag to the invocation outlined above. |
| 118 |
|
| 119 |
3. Run the client: |
| 120 |
|
| 121 |
``` |
| 122 |
python client.py xds:///my-backend --secure true |
| 123 |
``` |