examples/python/xds/README.md
The hostname example is a Hello World server whose response includes its hostname. It also supports health and reflection services. This makes it a good server to test infrastructure, like load balancing. This example depends on a gRPC version of 1.28.1 or newer.
cd grpc/examples/python/xds
virtualenv venv -p python3
source venv/bin/activate
pip install -r requirements.txt
python server.py
After configuring your xDS server to track the gRPC server we just started, create a bootstrap file as described in gRFC A27:
{
xds_servers": [
{
"server_uri": <string containing URI of xds server>,
"channel_creds": [
{
"type": <string containing channel cred type>,
"config": <JSON object containing config for the type>
}
]
}
],
"node": <JSON form of Node proto>
}
GRPC_XDS_BOOTSTRAP environment variable at the bootstrap file:export GRPC_XDS_BOOTSTRAP=/etc/xds-bootstrap.json
python client.py xds:///my-backend
Alternatively, grpcurl can be used to verify your server. If you don't have it,
install grpcurl. This will allow
you to manually test the service.
Be sure to set up the bootstrap file and GRPC_XDS_BOOTSTRAP as in the previous
section.
> grpcurl --plaintext -d '{"name": "you"}' localhost:50051
{
"message": "Hello you from rbell.svl.corp.google.com!"
}
> grpcurl --plaintext localhost:50051 list
grpc.health.v1.Health
grpc.reflection.v1alpha.ServerReflection
helloworld.Greeter
> grpcurl --plaintext -d '{"service": "helloworld.Greeter"}' localhost:50051
grpc.health.v1.Health/Check
{
"status": "SERVING"
}
> grpcurl --plaintext -d '{"service": ""}' localhost:50051
grpc.health.v1.Health/Check
{
"status": "SERVING"
}
Add the --secure true flag to the invocation outlined above.
python server.py --secure true
Add the --secure true flag to the invocation outlined above.
python client.py xds:///my-backend --secure true
From the gRPC workspace folder:
Client:
docker build -f examples/python/xds/Dockerfile.client -t "${xds-example-python-client-tag}" .
Server:
docker build -f examples/python/xds/Dockerfile.server -t "${xds-example-python-server-tag}" .
And then push the tagged image using docker push.