Skip to content

Commit c8f7a39

Browse files
committed
Document setup for kubernetes (Fixes #257)
1 parent c831e80 commit c8f7a39

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

docs/en/client/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ There are a number of supported schemes, that you can use to determine the targe
6161
if an existing connection is shutdown/fails. \
6262
Example: `dns:///example.my.company` \
6363
Notice: There is also a `dns` resolver that is included in grpclb, that has a higher priority (`6`) than the default
64-
one and also supports `SVC` lookups.
64+
one and also supports `SVC` lookups. See also [Kubernetes Setup](../kubernetes.md).
6565
- `discovery` (Prio 6): \
6666
(Optional) Uses spring-cloud's `DiscoveryClient` to lookup appropriate targets. The connections will be refreshed
6767
automatically during `HeartbeatEvent`s. Uses the `gRPC.port` metadata to determine the port, otherwise uses the

docs/en/kubernetes.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Kubernetes Setup
2+
3+
The following section assumes that you have at least some knowledge about deploying an application to Kubernetes.
4+
For more details refer to the [official documentation](https://kubernetes.io/docs/home/)
5+
6+
Kubernetes (or more precisely most of kubernetes DNS provider's) expose enough information for grpc-java to resolve
7+
the addresses of services that run inside the cluter. Should also work for OKD/OpenShift.
8+
9+
There are a few things you should keep in mind here though.
10+
11+
1. Inside your (target's) deployment, make sure that you expose the port specified by `grpc.server.port`
12+
(defaults to `9090`)
13+
14+
````yaml
15+
[...]
16+
spec:
17+
containers:
18+
- name: my-grpc-server-app
19+
image: ...
20+
ports:
21+
- name: grpc # Use whatever name you want
22+
containerPort: 9090 # Use the same as `grpc.server.port` (prefer 80, 443 or 9090)
23+
[...]
24+
````
25+
26+
> **Note:** Container ports can be re-used by other deployments/pods, unless you use `hostPort`s.
27+
> So there is no reason not to use a default one.
28+
29+
2. Inside your (target's) service definition, you should map that port to your preferred port.
30+
31+
````yaml
32+
apiVersion: v1
33+
kind: Service
34+
metadata:
35+
name: my-grpc-server-app # This name is important
36+
namespace: example # This name might be important
37+
spec:
38+
selector:
39+
app: my-grpc-server-app
40+
ports:
41+
- name: grpclb # The name is important, if you wish to use DNS-SVC-Lookups (must be grpclb)
42+
port: 1234 # Remember this port number, unless you use DNS-SVC-Lookups (prefer 80, 443 or 9090)
43+
targetPort: grpc # Use the port name from the deployment (or just the port number)
44+
````
45+
46+
> **Note:** Service ports can be re-used by other services, unless you use `hostPort`s.
47+
> So there is no reason not to use a default one.
48+
49+
3. Inside your client application config, configure the channel address to refer to the service name:
50+
51+
````properties
52+
## Choose your matching variant
53+
# Same namespace (target port=80 or derived by DNS-SVC)
54+
grpc.clients.my-grpc-server-app.address=dns:///my-grpc-server-app
55+
# Same namespace (different port)
56+
grpc.clients.my-grpc-server-app.address=dns:///my-grpc-server-app:1234
57+
# Different namespace
58+
grpc.clients.my-grpc-server-app.address=dns:///my-grpc-server-app.example:1234
59+
# Different cluster
60+
grpc.clients.my-grpc-server-app.address=dns:///my-grpc-server-app.example.svc.cluster.local:1234
61+
# Format
62+
grpc.clients.my-grpc-server-app.address=dns:///<serviceName>[.<namespace>[.<clusterAddress>]][:<service-port>]
63+
````
64+
65+
> **Note:** DNS-SVC lookups require the `grpclb` dependency to be present and the service's port name to be `grpclb`.
66+
> Refer to grpc's official docs for more details.

0 commit comments

Comments
 (0)