From 22d3583dbe3d1b4bc6ac4fdcd146f883b384d62f Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Fri, 19 Nov 2021 21:04:05 +0100 Subject: [PATCH 1/2] added mc-router will route based on domain name --- mc-router.yaml | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++ vanilla.yaml | 2 ++ 2 files changed, 81 insertions(+) create mode 100644 mc-router.yaml diff --git a/mc-router.yaml b/mc-router.yaml new file mode 100644 index 0000000..46b0a3c --- /dev/null +++ b/mc-router.yaml @@ -0,0 +1,79 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: mc-router +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: services-watcher +rules: +- apiGroups: [""] + resources: ["services"] + verbs: ["watch","list"] +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: mc-router-services-watcher +subjects: +- kind: ServiceAccount + name: mc-router + namespace: default +roleRef: + kind: ClusterRole + name: services-watcher + apiGroup: rbac.authorization.k8s.io +--- +apiVersion: v1 +kind: Service +metadata: + name: mc-router +spec: + type: NodePort + ports: + - targetPort: web + name: web + port: 8080 + nodePort: 30580 + - targetPort: proxy + name: proxy + port: 25565 + nodePort: 30565 + selector: + run: mc-router +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + run: mc-router + name: mc-router +spec: + selector: + matchLabels: + run: mc-router + strategy: + type: Recreate + template: + metadata: + labels: + run: mc-router + spec: + serviceAccountName: mc-router + containers: + - image: itzg/mc-router:latest + name: mc-router + args: ["--api-binding", ":8080", "--in-kube-cluster"] + ports: + - name: proxy + containerPort: 25565 + - name: web + containerPort: 8080 + resources: + requests: + memory: 50Mi + cpu: "100m" + limits: + memory: 100Mi + cpu: "250m" diff --git a/vanilla.yaml b/vanilla.yaml index 58a5917..1559218 100644 --- a/vanilla.yaml +++ b/vanilla.yaml @@ -4,6 +4,8 @@ metadata: name: mc-vanilla labels: app: mc-vanilla + annotations: + "mc-router.itzg.me/externalServerName": "oasis.learn.study" spec: ports: - port: 25565 From 565f82cc377d9978e6b4e411e23cd00665deac8a Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sat, 20 Nov 2021 12:20:15 +0100 Subject: [PATCH 2/2] make mc-router work on GCP --- README.md | 24 ++++++++++++++++++++---- mc-router.yaml | 13 +++---------- vanilla.yaml | 2 +- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 0bbce6d..d631d66 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,14 @@ Follow https://github.com/vorburger/LearningKubernetes-CodeLabs/blob/develop/doc gcloud container clusters get-credentials cluster1 --project=oasis-learn-study --region=europe-west4 pwgen -s 101 1 | kubectl create secret generic mc-vanilla --from-file=rcon=/dev/stdin - kubectl apply -f vanilla.yaml - kubectl get service mc-vanilla + kubectl apply -f . + kubectl get service mc-router -You can connect to your Minecraft Server at the `EXTERNAL-IP` shown. +You can connect to your Minecraft Server by mapping a hostname such as `oasis.learn.study` to the `EXTERNAL-IP` shown +by the last command above in your local `/etc/hosts` file. You could also add a 2nd Minecraft server (which you also need to +register in your local `/etc/hosts` file again e.g. as this `test2.learn.study`, unless you have DNS) like this: + + sed 's/mc-vanilla/test2/g' vanilla.yaml | sed 's/oasis.learn.study/test2.learn.study/' | kubectl apply -f - ### Debug @@ -26,6 +30,14 @@ To troubleshoot & debug startup issues, use: kubectl describe pod mc-vanilla-0 kubectl logs -f mc-vanilla-0 + kubectl logs -f mc-router-... + +### Fixed IP address + +Navigate to https://console.cloud.google.com/networking/addresses/list and click _Reserve_ to turn +the _Ephemeral External IP address_ of the `mc-router` service of type `LoadBalancer` into a fixed static IP, +which you can use in a DNS entry. Further background e.g. on https://cloud.google.com/kubernetes-engine/docs/tutorials/configuring-domain-name-static-ip. + ### RCON You can use an [RCON](https://wiki.vg/RCON) client such as [`rcon-cli`](https://github.com/itzg/rcon-cli) to connect to the admin console: (But please note that the RCON protocol is not encrypted, meaning that your passwords are transmitted in plain text to the server. A future version of this project may include a more secure web-based admin console, instead.) @@ -58,6 +70,8 @@ because the PV/PVC-to-PD association will be lost; you would have to manually fi kubectl exec mc-vanilla-0 -- bash -c 'echo $RCON_PASSWORD' + kubectl exec -it mc-vanilla-0 -- bash + **BEWARE** that YAML changes to `env`ironment variables of `itzg/minecraft-server` container will NOT affect existing servers with the image, because many of it's startup parameter environment variables are written into the persistent `/data/server.properties` only when the `StatefulSet` PV is automatically created the first time. To remove that (and **loose your world data**) we have to delete the PVC (which also deletes the PD): kubectl delete pvc mc-data-mc-vanilla-0 @@ -124,7 +138,9 @@ Using _Shared Classes_, on a persistent volume, may help further (TBD). `kubectl exec mc-vanilla-0 -- mc-monitor export-for-prometheus -servers localhost` - [ ] Scale Down StatefulSet to 0 when no Players for N minutes, query via monitoring! -- [ ] Two servers, with https://github.com/itzg/mc-router/tree/master/docs; no template, just simple sed/rpl +- [ ] Wildcard DNS - how-to? +- [ ] Add default server, a simple empty world with a shield saying "Wrong server name" (from git, without PV) +- [X] Two servers, with https://github.com/itzg/mc-router/tree/master/docs; no template, just simple sed/rpl - [ ] Templating, simply using Xtend, from literal objects, later YAML, into files in git - for now (see below). Not kpt, Helm, nor Kustomize or CUE or Flux or Nix. - [ ] gRPC CreateServer ^^^ at runtime with Service Account diff --git a/mc-router.yaml b/mc-router.yaml index 46b0a3c..90de008 100644 --- a/mc-router.yaml +++ b/mc-router.yaml @@ -30,18 +30,13 @@ kind: Service metadata: name: mc-router spec: - type: NodePort ports: - - targetPort: web - name: web - port: 8080 - nodePort: 30580 - targetPort: proxy name: proxy port: 25565 - nodePort: 30565 selector: run: mc-router + type: LoadBalancer --- apiVersion: apps/v1 kind: Deployment @@ -62,14 +57,12 @@ spec: spec: serviceAccountName: mc-router containers: - - image: itzg/mc-router:latest + - image: itzg/mc-router:1.13.0 name: mc-router - args: ["--api-binding", ":8080", "--in-kube-cluster"] + args: ["--in-kube-cluster"] ports: - name: proxy containerPort: 25565 - - name: web - containerPort: 8080 resources: requests: memory: 50Mi diff --git a/vanilla.yaml b/vanilla.yaml index 1559218..70931d7 100644 --- a/vanilla.yaml +++ b/vanilla.yaml @@ -16,7 +16,7 @@ spec: name: rcon selector: app: mc-vanilla - type: LoadBalancer + type: ClusterIP --- apiVersion: apps/v1 kind: StatefulSet pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy