From a7229355bfe1cfc2d510587c97590152f4b81b07 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 23 Oct 2022 22:18:10 -0500 Subject: [PATCH] Route to k8s service port minecraft or mc-router (#135) --- README.md | 11 +++++------ server/k8s.go | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 1e92d42..77107d2 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/server/k8s.go b/server/k8s.go index 2ce9e55..4d9ddf5 100644 --- a/server/k8s.go +++ b/server/k8s.go @@ -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)) } }