xref: /aosp_15_r20/external/grpc-grpc-java/examples/example-xds/README.md (revision e07d83d3ffcef9ecfc9f7f475418ec639ff0e5fe)
1*e07d83d3SAndroid Build Coastguard WorkergRPC XDS Example
2*e07d83d3SAndroid Build Coastguard Worker================
3*e07d83d3SAndroid Build Coastguard Worker
4*e07d83d3SAndroid Build Coastguard WorkerThe XDS example consists of a Hello World client and a Hello World server capable of
5*e07d83d3SAndroid Build Coastguard Workerbeing configured with the XDS management protocol. Out-of-the-box the client
6*e07d83d3SAndroid Build Coastguard Workerbehaves the same the hello-world version and the server behaves similar to the
7*e07d83d3SAndroid Build Coastguard Workerexample-hostname but with a required dependency on xDS.
8*e07d83d3SAndroid Build Coastguard Worker
9*e07d83d3SAndroid Build Coastguard Worker__XDS support is incomplete and experimental, with limited compatibility. It
10*e07d83d3SAndroid Build Coastguard Workerwill be very hard to produce a working environment just by this example. Please
11*e07d83d3SAndroid Build Coastguard Workerrefer to documentation specific for your XDS management server and
12*e07d83d3SAndroid Build Coastguard Workerenvironment.__
13*e07d83d3SAndroid Build Coastguard Worker
14*e07d83d3SAndroid Build Coastguard Worker### Build the example
15*e07d83d3SAndroid Build Coastguard Worker
16*e07d83d3SAndroid Build Coastguard WorkerBuild the XDS hello-world example client & server. From the `grpc-java/examples/examples-xds`
17*e07d83d3SAndroid Build Coastguard Workerdirectory:
18*e07d83d3SAndroid Build Coastguard Worker```
19*e07d83d3SAndroid Build Coastguard Worker$ ../gradlew installDist
20*e07d83d3SAndroid Build Coastguard Worker```
21*e07d83d3SAndroid Build Coastguard Worker
22*e07d83d3SAndroid Build Coastguard WorkerThis creates the scripts `build/install/example-xds/bin/xds-hello-world-client` and
23*e07d83d3SAndroid Build Coastguard Worker`build/install/example-xds/bin/xds-hello-world-server`.
24*e07d83d3SAndroid Build Coastguard Worker
25*e07d83d3SAndroid Build Coastguard Worker### Run the example without using XDS Credentials
26*e07d83d3SAndroid Build Coastguard Worker
27*e07d83d3SAndroid Build Coastguard WorkerTo use XDS, you should first deploy the XDS management server in your deployment environment
28*e07d83d3SAndroid Build Coastguard Workerand know its name. You need to set the `GRPC_XDS_BOOTSTRAP` environment variable (preferred) or if that is not set then
29*e07d83d3SAndroid Build Coastguard Workerthe `io.grpc.xds.bootstrap` java system property to point to the gRPC XDS bootstrap file (see
30*e07d83d3SAndroid Build Coastguard Worker[gRFC A27](https://github.com/grpc/proposal/blob/master/A27-xds-global-load-balancing.md#xdsclient-and-bootstrap-file) for the
31*e07d83d3SAndroid Build Coastguard Workerbootstrap format). This is needed by both `build/install/example-xds/bin/xds-hello-world-client`
32*e07d83d3SAndroid Build Coastguard Workerand `build/install/example-xds/bin/xds-hello-world-server`.
33*e07d83d3SAndroid Build Coastguard Worker
34*e07d83d3SAndroid Build Coastguard Worker1. To start the XDS-enabled example server on its default port of 50051, run:
35*e07d83d3SAndroid Build Coastguard Worker```
36*e07d83d3SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
37*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/example-xds/bin/xds-hello-world-server
38*e07d83d3SAndroid Build Coastguard Worker```
39*e07d83d3SAndroid Build Coastguard Worker
40*e07d83d3SAndroid Build Coastguard Worker2. In a different terminal window, run the XDS-enabled example client:
41*e07d83d3SAndroid Build Coastguard Worker```
42*e07d83d3SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
43*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/example-xds/bin/xds-hello-world-client "xds world" xds:///yourServersName
44*e07d83d3SAndroid Build Coastguard Worker```
45*e07d83d3SAndroid Build Coastguard WorkerThe first command line argument (`xds world`) is the name you wish to include in
46*e07d83d3SAndroid Build Coastguard Workerthe greeting request to the server and the second argument
47*e07d83d3SAndroid Build Coastguard Worker(`xds:///yourServersName`) is the target to connect to using the `xds:` target
48*e07d83d3SAndroid Build Coastguard Workerscheme.
49*e07d83d3SAndroid Build Coastguard Worker
50*e07d83d3SAndroid Build Coastguard Worker### Run the example with xDS Credentials
51*e07d83d3SAndroid Build Coastguard Worker
52*e07d83d3SAndroid Build Coastguard WorkerThe above example used plaintext (insecure) credentials as explicitly provided by the client and server
53*e07d83d3SAndroid Build Coastguard Workercode. We will now demonstrate how the code can authorize use of xDS provided credentials by using
54*e07d83d3SAndroid Build Coastguard Worker`XdsChannelCredentials` on the client side and using `XdsServerCredentials` on the server side.
55*e07d83d3SAndroid Build Coastguard WorkerThis code is enabled by providing an additional command line argument.
56*e07d83d3SAndroid Build Coastguard Worker
57*e07d83d3SAndroid Build Coastguard Worker1. On the server side, add `--xds-creds` on the command line to authorize use of xDS security:
58*e07d83d3SAndroid Build Coastguard Worker```
59*e07d83d3SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
60*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/example-xds/bin/xds-hello-world-server --xds-creds
61*e07d83d3SAndroid Build Coastguard Worker```
62*e07d83d3SAndroid Build Coastguard Worker
63*e07d83d3SAndroid Build Coastguard Worker2. Similarly, add `--xds-creds` on the command line when you run the xDS client:
64*e07d83d3SAndroid Build Coastguard Worker```
65*e07d83d3SAndroid Build Coastguard Worker$ export GRPC_XDS_BOOTSTRAP=/path/to/bootstrap.json
66*e07d83d3SAndroid Build Coastguard Worker$ ./build/install/example-xds/bin/xds-hello-world-client --xds-creds "xds world" xds:///yourServersName
67*e07d83d3SAndroid Build Coastguard Worker```
68*e07d83d3SAndroid Build Coastguard Worker
69*e07d83d3SAndroid Build Coastguard WorkerIn this case, if the xDS management server is configured to provide mTLS credentials (for example) to the client and
70*e07d83d3SAndroid Build Coastguard Workerserver, then they will use these credentials to create an mTLS channel to authenticate and encrypt.
71