Route to k8s service port minecraft or mc-router

This commit is contained in:
Geoff Bourne 2022-10-23 22:13:51 -05:00
parent 25575c1176
commit 5884ad12cb
No known key found for this signature in database
GPG Key ID: FA2F6C35D87E88ED
2 changed files with 6 additions and 7 deletions

View File

@ -111,12 +111,9 @@ To test out this example, I added these two entries to my "hosts" file:
## Using Kubernetes Service auto-discovery
When running `mc-router` as a Kubernetes Pod and you pass the `--in-kube-cluster` command-line argument, then
it will automatically watch for any services annotated with
- `mc-router.itzg.me/externalServerName` : The value of the annotation will be registered as the external hostname Minecraft clients would used to connect to the
routed service. The service's clusterIP and target port are used as the routed backend. You can use more hostnames by splitting them with comma.
- `mc-router.itzg.me/defaultServer` : The service's clusterIP and target port are used as the default if
no other `externalServiceName` annotations applies.
When running `mc-router` as a Kubernetes Pod and you pass the `--in-kube-cluster` command-line argument, then it will automatically watch for any services annotated with
- `mc-router.itzg.me/externalServerName` : The value of the annotation will be registered as the external hostname Minecraft clients would used to connect to the routed service. The service's clusterIP and target port are used as the routed backend. You can use more hostnames by splitting them with comma.
- `mc-router.itzg.me/defaultServer` : The service's clusterIP and target port are used as the default if no other `externalServiceName` annotations applies.
For example, start `mc-router`'s container spec with
@ -148,6 +145,8 @@ metadata:
"mc-router.itzg.me/externalServerName": "external.host.name,other.host.name"
```
mc-router will pick the service port named either `minecraft` or `mc-router`. If neither port names exist, it will use port value 25565.
## Example Kubernetes deployment
[This example deployment](docs/k8s-example-auto.yaml)

View File

@ -232,7 +232,7 @@ func (w *k8sWatcherImpl) buildDetails(service *core.Service, externalServiceName
clusterIp := service.Spec.ClusterIP
port := "25565"
for _, p := range service.Spec.Ports {
if p.Name == "mc-router" {
if p.Name == "mc-router" || p.Name == "minecraft" {
port = strconv.Itoa(int(p.Port))
}
}