• Stars
    star
    338
  • Rank 124,931 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Routes Minecraft client connections to backend servers based upon the requested server address

GitHub issues Docker Pulls test GitHub release Discord Buy me a coffee

Routes Minecraft client connections to backend servers based upon the requested server address.

Usage

  -api-binding host:port
    	The host:port bound for servicing API requests (env API_BINDING)
  -auto-scale-up
      Increase Kubernetes StatefulSet Replicas (only) from 0 to 1 on respective backend servers when accessed (env AUTO_SCALE_UP)
  -connection-rate-limit int
    	Max number of connections to allow per second (env CONNECTION_RATE_LIMIT) (default 1)
  -cpu-profile string
    	Enables CPU profiling and writes to given path (env CPU_PROFILE)
  -debug
    	Enable debug logs (env DEBUG)
  -in-kube-cluster
    	Use in-cluster Kubernetes config (env IN_KUBE_CLUSTER)
  -kube-config string
    	The path to a Kubernetes configuration file (env KUBE_CONFIG)
  -in-docker-swarm
      Use in-swarm Docker config (env IN_DOCKER_SWARM)
  -docker-timeout
      Timeout configuration in seconds for the Docker Swarm integration (env DOCKER_TIMEOUT) (default 0)
  -docker-refresh-interval
      Refresh interval in seconds for the Docker Swarm integration (env DOCKER_REFRESH_INTERVAL) (default 15)
  -mapping string
    	Comma-separated mappings of externalHostname=host:port (env MAPPING)
  -metrics-backend string
    	Backend to use for metrics exposure/publishing: discard,expvar,influxdb (env METRICS_BACKEND) (default "discard")
  -metrics-backend-config-influxdb-addr string
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_ADDR)
  -metrics-backend-config-influxdb-database string
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_DATABASE)
  -metrics-backend-config-influxdb-interval duration
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_INTERVAL) (default 1m0s)
  -metrics-backend-config-influxdb-password string
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_PASSWORD)
  -metrics-backend-config-influxdb-retention-policy string
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_RETENTION_POLICY)
  -metrics-backend-config-influxdb-tags value
    	any extra tags to be included with all reported metrics (env METRICS_BACKEND_CONFIG_INFLUXDB_TAGS)
  -metrics-backend-config-influxdb-username string
    	 (env METRICS_BACKEND_CONFIG_INFLUXDB_USERNAME)
  -port port
    	The port bound to listen for Minecraft client connections (env PORT) (default 25565)
  -routes-config string
        The path to the routes config file (env ROUTES_CONFIG)
  -version
    	Output version and exit (env VERSION)

REST API

  • GET /routes (with Accept: application/json)

    Retrieves the currently configured routes

  • POST /routes (with Content-Type: application/json)

    Registers a route given a JSON body structured like:

    {
      "serverAddress": "CLIENT REQUESTED SERVER ADDRESS",
      "backend": "HOST:PORT"
    }
  • POST /defaultRoute (with Content-Type: application/json)

    Registers a default route to the given backend. JSON body is structured as:

    {
      "backend": "HOST:PORT"
    }
  • DELETE /routes/{serverAddress}

    Deletes an existing route for the given serverAddress

Docker Multi-Architecture Image

The multi-architecture image published at Docker Hub supports amd64, arm64, and arm32v6 (i.e. RaspberryPi).

Docker Compose Usage

The following diagram shows how the example docker-compose.yml configures two Minecraft server services named vanilla and forge, which also become the internal network aliases. Notice those services don't need their ports exposed since the internal networking allows for the inter-container access.

The router service is only one of the services that needs to exposed on the external network. The --mapping declares how the hostname users will enter into their Minecraft client will map to the internal services.

To test out this example, I added these two entries to my "hosts" file:

127.0.0.1 vanilla.example.com
127.0.0.1 forge.example.com

Routing Configuration

The routing configuration allows routing via a config file rather than a command. You need to set -routes-config or ROUTES_CONFIG env variable. The following shows a JSON file for routes config, where default-server can also be null or omitted:

{
  "default-server": "vanilla:25565",
  "mappings": {
    "vanilla.example.com": "vanilla:25565",
    "forge.example.com": "forge:25565"
  }
}

Kubernetes Usage

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.

For example, start mc-router's container spec with

image: itzg/mc-router
name: mc-router
args: ["--in-kube-cluster"]

and configure the backend minecraft server's service with the annotation:

apiVersion: v1
kind: Service
metadata:
  name: mc-forge
  annotations:
    "mc-router.itzg.me/externalServerName": "external.host.name"

you can use multiple host names:

apiVersion: v1
kind: Service
metadata:
  name: mc-forge
  annotations:
    "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

  • Declares an mc-router service that exposes a node port 25565
  • Declares a service account with access to watch and list services
  • Declares --in-kube-cluster in the mc-router container arguments
  • Two "backend" Minecraft servers are declared each with an "mc-router.itzg.me/externalServerName" annotation that declares their external server name(s)
kubectl apply -f https://raw.githubusercontent.com/itzg/mc-router/master/docs/k8s-example-auto.yaml

Notes

  • This deployment assumes two persistent volume claims: mc-stable and mc-snapshot
  • I extended the allowed node port range by adding --service-node-port-range=25000-32767 to /etc/kubernetes/manifests/kube-apiserver.yaml

Auto Scale Up

The -auto-scale-up flag argument makes the router "wake up" any stopped backend servers, by changing replicas: 0 to replicas: 1.

This requires using kind: StatefulSet instead of kind: Service for the Minecraft backend servers.

It also requires the ClusterRole to permit get + update for statefulsets & statefulsets/scale, e.g. like this (or some equivalent more fine-grained one to only watch/list services+statefulsets, and only get+update scale):

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: services-watcher
rules:
- apiGroups: [""]
  resources: ["services"]
  verbs: ["watch","list"]
- apiGroups: ["apps"]
  resources: ["statefulsets", "statefulsets/scale"]
  verbs: ["watch","list","get","update"]

Docker Swarm Usage

Using Docker Swarm Service auto-discovery

When running mc-router in a Docker Swarm environment you can pass the --in-docker-swarm command-line argument and it will poll the Docker API periodically to find all the running services for minecraft instances. To enable discovery you have to set the mc-router.host label on the service. These are the labels scanned:

  • mc-router.host: Used to configure the hostname the Minecraft clients would use to connect to the server. The service endpoint will be used as the routed backend. You can use more than one hostname by splitting it with a comma.
  • mc-router.port: This value must be set to the port the Minecraft server is listening on. The default value is 25565.
  • mc-router.default: Set this to a truthy value to make this server the deafult backend. Please note that mc-router.host is still required to be set.
  • mc-router.network: Specify the network you are using for the router if multiple are present in the service. You can either use the network ID, it's full name or an alias.

Example Docker Swarm deployment

Refer to this example docker-compose.yml to see how to configure two different Minecraft servers and a mc-router instance. Notice how you don't have to expose the Minecraft instances ports, but all the containers are required to be in the same network.

Development

Building locally with Docker

docker build -t mc-router .

Build locally without Docker

After installing Go and doing a go mod download to install all required prerequisites, just like the Dockerfile does, you can:

make test # go test -v ./...
go build ./cmd/mc-router/

Skaffold

For "in-cluster development" it's convenient to use https://skaffold.dev. Any changes to Go source code will trigger a go build, new container image pushed to registry with a new tag, and refresh in Kubernetes with the image tag used in the deployment transparently updated to the new tag and thus new pod created pulling new images, as configured by skaffold.yaml:

skaffold dev

When using Google Cloud (GCP), first create a Docker Artifact Registry, then add the Artifact Registry Reader Role to the Compute Engine default service account of your GKE clusterService Account (to avoid error like "container mc-router is waiting to start: ...-docker.pkg.dev/... can't be pulled"), then use e.g. gcloud auth configure-docker europe-docker.pkg.dev or equivalent one time (to create a ~/.docker/config.json), and then use e.g. --default-repo=europe-docker.pkg.dev/YOUR-PROJECT/YOUR-ARTIFACT-REGISTRY option for skaffold dev.

Performing snapshot release with Docker

docker run -it --rm \
  -v ${PWD}:/build -w /build \
  -v /var/run/docker.sock:/var/run/docker.sock \
  goreleaser/goreleaser \
  release --snapshot --rm-dist

Related Projects

More Repositories

1

docker-minecraft-server

Docker image that provides a Minecraft Server that will automatically download selected version at startup
Shell
7,144
star
2

docker-minecraft-bedrock-server

Containerized Minecraft Bedrock Dedicated Server with selectable version
Shell
756
star
3

minecraft-server-charts

Smarty
260
star
4

docker-mc-backup

Provides a side-car container to backup itzg/minecraft-server world data
Shell
190
star
5

mc-monitor

Monitor the status of Minecraft servers and provides Prometheus exporter and Influx line protocol output
Go
165
star
6

docker-bungeecord

A BungeeCord server to use in conjunction with itzg/minecraft-server
Shell
143
star
7

rcon-cli

A little RCON cli based on james4k's RCON library for golang
Go
122
star
8

docker-rcon-web-admin

A Docker image that runs rcon-web-admin
Dockerfile
69
star
9

saml-auth-proxy

Provides a SAML SP authentication proxy for backend web services
Go
42
star
10

react-mui-login-register

A user login/register React component styled with Material UI that includes options to use an authentication provider
JavaScript
41
star
11

restify

Enables REST-like access to HTML pages by scraping and parsing them into JSON.
Go
37
star
12

mc-image-helper

This tool does the complicated bits for the itzg/minecraft-server image
Java
27
star
13

mc-server-runner

A container entry point to manage graceful shutdown of a Minecraft server
Go
26
star
14

easy-add

A utility for easily adding a file from a downloaded archive during Docker builds
Go
22
star
15

mc-status

A web application that serves up a little REST API to query and convey the status of Minecraft servers using the native MC protocol
Java
18
star
16

go-flagsfiller

Bring your own struct and make Go's flag package pleasant to use
Go
15
star
17

redis-stomp-relay

This Spring Boot application implements a STOMP relay that delegates to Redis pub/sub.
Java
14
star
18

haproxy-gen

Generate an haproxy.cfg file for multi-domain proxying
Go
12
star
19

websocket-stomp-user-queues

A little Spring Boot application to demonstrate the use of several technologies and techniques
Java
11
star
20

kidsbank-js

kids bank is a totally virtual way for parents and kids to keep track of allowance, etc
Java
11
star
21

rcon-hub

Provides an SSH server that enables rcon connections to configured game servers
Go
10
star
22

entrypoint-demoter

Container entry point that can demote uid and gid from environment variables or matching directory
Go
9
star
23

kube-metrics-exporter

Simple application that accesses the Kubernetes metrics API and exports the pod metrics for Prometheus scraping
Go
6
star
24

docker-minecraft-docs

Documentation hub for all the itzg Docker Minecraft images
5
star
25

web-debug-server

A very minimal web server that responds with a page containing the request headers and content
Go
5
star
26

mc-modpacks-starter

5
star
27

kita

An easy-to-deploy and easy-to-use ACME client service for Kubernetes Ingress instances
Java
4
star
28

simple-boot-image-gradle-plugin

A simple Gradle plugin to build very simple Spring Boot application Docker images
Java
4
star
29

try-oauth2-login

This application tests out Spring Boot's OAuth2 support for pre-defined providers
Java
3
star
30

try-luckperms-with-db

3
star
31

go-ssh-shell

Go module that serves SSH sessions with an interactive shell
Go
3
star
32

docker-grakn

This Docker image packages the GRAKN.AI knowledge graph database
Shell
3
star
33

try-nextjs-auth0

React frontend, rendered by Next.js, authenticated by Auth0, and backend API by Spring Boot
JavaScript
3
star
34

example-self-monitor-kafka-app

An example Spring Boot application that is both a Kafka producer and consumer that reports out its own kakfa performance metrics to InfluxDB
Java
3
star
35

discord-github-melder-bot

Discord bot that provides a command for users to link their Github user and apply contributor role
Java
3
star
36

junit-rule-docker

A JUnit rule that manages a Docker container lifecycle around test statements.
Java
3
star
37

itzg

3
star
38

go-tcp-relay

A little experiment to write a Go application that can relay incoming TCP connections to a dynamically requested endpoint
Go
3
star
39

alexa-notes

An Amazon Alexa (aka Echo) skill that provides very basic note taking capability.
Java
3
star
40

cert-helper

A Docker image that helps with self-signed/cluster signed certificate creation for use in other Docker containers
Shell
3
star
41

github-release-watcher

A Spring Boot + React web app that shows most recent releases of repositories you have starred.
Java
3
star
42

draw-legra

Trying out the Legra library in a React app
JavaScript
2
star
43

docker-kafka-multiarch

Shell
2
star
44

maven-metadata-release

A little utility to output the release identified by a maven-metadata.xml local/remote file
Go
2
star
45

kafka-slurp

Java
2
star
46

docker-rabbitmq-stomp

Extension of the official rabbitmq image that enables the rabbitmq_stomp plugin
2
star
47

file-tree-as-json

Walks one or more directories capturing the file/directory tree into a JSON format
Java
2
star
48

docker-apacheds

This image provides a streamlined ApacheDS server
2
star
49

docker-znc

A ZNC, an IRC bouncer, image with an easy option to switch between SSL and non-SSL serving
Shell
2
star
50

alt-codes

Little next.js web app that shows alt codes
JavaScript
2
star
51

prune-branches

CLI that prunes local git branches that have been merged
Java
2
star
52

test-github-releaser-plugin

Ruby
2
star
53

docker-mongo-backups

A very simplistic container to perform periodic backups of an adjacent mongo container
Shell
2
star
54

homebrew-tap

Homebrew tap for itzg's apps
Ruby
2
star
55

jsonschema2pojo-rules-bettermaps

Custom RuleFactory for the jsonschema2pojo facility that identifies additionalProperties that only declare a simple type and generates a Map without an intermediate property POJO.
Java
2
star
56

forge-downloader

A simple utility for downloading Forge installers
Go
1
star
57

spring-etcd

etcd v2 client based on Spring's RestTemplate
Java
1
star
58

getter

A little Java program that is useful inside containers where curl is not yet installed
Java
1
star
59

spring-boot-with-reactjs

JavaScript
1
star
60

docker-protoc2

This Google Protobuf compiler image is for projects that need an "ancient" version of the protoc compiler.
1
star
61

scoop-bucket

My apps published for installation via scoop
1
star
62

openstack-utils

Helper scripts install OpenStack on Ubuntu
Shell
1
star
63

carina-cli

This is a Dockerization of the Carina CLI, which is used to manage your Rackspace Carina clusters from the command-line.
Shell
1
star
64

artifactory-settings-gen

Java
1
star
65

try-spring-boot-with-jib

Java
1
star
66

go-metrics

This library provides Go applications a simple way to report dimensional statistics with optional support for Influx line protocol
Go
1
star
67

pom-tweaker

A simple Java tool to perform version, etc tweaking of Maven pom.xml files.
Java
1
star
68

try-nextjs-jwt-boot-api

Next.js web application that uses JWT issued by Auth0 to access authenticated Spring Boot API
JavaScript
1
star
69

libvirt-tools

A repo of some tools to simplify working with libvirt, kvm, qemu
Shell
1
star
70

test-webhooks

1
star
71

example-spring-security-impersonate

An example Spring MVC Security application that introduces a custom security filter to allow for user impersonation during development/testing.
Shell
1
star
72

mc-bds-helper

Go
1
star
73

LearningJava

Contains material teaching Java for new programmers
HTML
1
star
74

test-workflows

1
star
75

nextjs-bootstrap-validation

JavaScript
1
star
76

try-jpa-pk-and-fk

Spring Data JPA app that tries out an entity that uses a OneToOne relationship as primary key
Java
1
star
77

mcadmin-versions

Extracts the Spigot and CraftBukkit versions published by mcadmin site.
Java
1
star
78

try-oauth2-validate-aud

Java
1
star
79

utils

Java
1
star
80

img-hacker

A little golang tool to run some image manipulation
Go
1
star
81

spring-security-spa

Provides Spring Security filters and supporting classes that streamline the use of authentication and registration within Single Page web Applications
Java
1
star
82

docker-kodexplorer

This image runs KodExplorer
Dockerfile
1
star
83

logstash-filter-docker_container

A Logstash (>1.5) filter plugin to resolve Docker container IDs into the container's name
Ruby
1
star
84

docker-thrift

A Docker image for running the thrift generator
1
star
85

try-sb-test-properties-loading

This Spring Boot code demonstrates several ways of using a type-safe configuration class during unit testing
Java
1
star
86

imdb-warzat

JavaScript
1
star
87

docker-ubuntu-remote-dev

Shell
1
star
88

spring-security-vault-provider-example

Example Spring Boot web app using Vault as the Spring Security authentication provider
Java
1
star
89

atom-greppen-grok

An Atom editor package to grep and grok text into just what you want
CoffeeScript
1
star
90

nuc-es

My home NUC setup for ES and friends
1
star
91

stackdriver-spring-boot-autoconfigure

Provides a Spring Boot auto-configuration to export actuator metrics to Google Cloud's Stackdriver
Java
1
star
92

try-thanos

Contains a set of Kubernetes manifest files to try out a "single node" deployment of Thanos using MinIO as an S3 object store.
1
star
93

try-spring-jta-rollback-listener

This application tests the use of a @TransactionalEventListener in order to perform custom rollback processing.
Java
1
star
94

try-nextjs-cookie-auth-api

Very contrived Next.js application to simulate an authentication flow that uses next-cookies to provide server and client side with auth code
JavaScript
1
star
95

logstash-output-elasticsearch-groom

A logstash output plugin that will perform event triggered grooming (aka pruning) of time-series indices especially those created by logstash-output-elasticsearch.
Ruby
1
star
96

jenkins-vagrant-example

Brings up three Vagrant VMs with one Jenkins master and two slaves configured to run Docker pipeline jobs
1
star
97

chef-slurper

A little utility to bridge the worlds of Ansible and Chef
Go
1
star