Skip to content

Commit 9258315

Browse files
authored
Merge pull request #403 from yidongnan/docs/kubernetes
Document setup for kubernetes
2 parents a0974c8 + 6bac0a8 commit 9258315

File tree

3 files changed

+86
-13
lines changed

3 files changed

+86
-13
lines changed

docs/en/client/configuration.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,31 @@ grpc.client.__name__.address=static://localhost:9090
5252
There are a number of supported schemes, that you can use to determine the target server (Priorities 0 (low) - 10
5353
(high)):
5454

55-
- `static` (Prio 4):
56-
A simple static list of IPs (both v4 and v6), that can be use connect to the server (Supports `localhost`).
55+
- `static` (Prio 4): \
56+
A simple static list of IPs (both v4 and v6), that can be use connect to the server (Supports `localhost`). \
5757
Example: `static://192.168.1.1:8080,10.0.0.1:1337`
58-
- [`dns`](https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L66) (Prio 5):
58+
- [`dns`](https://github.com/grpc/grpc-java/blob/master/core/src/main/java/io/grpc/internal/DnsNameResolver.java#L66)
59+
(Prio 5): \
5960
Resolves all addresses that are bound to the given DNS name. The addresses will be cached and will only be refreshed
60-
if an existing connection is shutdown/fails. More options such as `SVC` lookups (useful for kubernetes) can be enabled
61-
via system properties.
62-
Example: `dns:///example.my.company`
63-
- `discovery` (Prio 6):
61+
if an existing connection is shutdown/fails. \
62+
Example: `dns:///example.my.company` \
63+
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. See also [Kubernetes Setup](../kubernetes.md).
65+
- `discovery` (Prio 6): \
6466
(Optional) Uses spring-cloud's `DiscoveryClient` to lookup appropriate targets. The connections will be refreshed
6567
automatically during `HeartbeatEvent`s. Uses the `gRPC.port` metadata to determine the port, otherwise uses the
66-
service port.
68+
service port. \
6769
Example: `discovery:///service-name`
68-
- `self` (Prio 0):
70+
- `self` (Prio 0): \
6971
The self address or scheme is a keyword that is available, if you also use `grpc-server-spring-boot-starter` and
7072
allows you to connect to the server without specifying the own address/port. This is especially useful for tests
71-
where you might want to use random server ports to avoid conflicts.
73+
where you might want to use random server ports to avoid conflicts. \
7274
Example: `self` or `self:self`
73-
- `in-process`:
75+
- `in-process`: \
7476
This is a special scheme that will bypass the normal channel factory and will use the `InProcessChannelFactory`
75-
instead. Use it to connect to the [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver).
77+
instead. Use it to connect to the [`InProcessServer`](../server/configuration.md#enabling-the-inprocessserver). \
7678
Example: `in-process:foobar`
77-
- *custom*:
79+
- *custom*: \
7880
You can define custom
7981
[`NameResolverProvider`s](https://javadoc.io/page/io.grpc/grpc-all/latest/io/grpc/NameResolverProvider.html) those
8082
will be picked up, by either via Java's `ServiceLoader` or from spring's application context and registered in

docs/en/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ customization you need for your project.
2727
- [Version Overview](versions.md)
2828
- [Spring Boot Actuator / Metrics Support](actuator.md)
2929
- [Brave-Tracing / Spring Cloud Sleuth Support](brave.md)
30+
- [Kubernetes Setup](kubernetes.md)
3031
- [Benchmarking](benchmarking.md)
3132
- [Contributing](contributions.md)

docs/en/kubernetes.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.
67+
68+
----------
69+
70+
[<- Back to Index](index.md)

0 commit comments

Comments
 (0)