17-Nov-2022
It's time for some fun. You can tell your family and colleagues that you are doing research or experimenting with new tech, but don't let them know that you are playing Minecraft.
Let's say you're organizing a Minecraft class for students in STEM. You need to run your own Minecraft servers to ensure a kid-friendly multiplayer environment, restricted only to your students. You will need to run at least one server. Your load balancer will handle sending students to Server A and Server B depending on their load.
This article will discuss port forwarding and load balance with Kong Gateway. This will be done by setting up multiple Minecraft servers and then placing Kong Gateway in front these upstream services for port forwarding or load balancing.
Let's first briefly discuss some important technologies concepts before we get started.
Port Forwarding
Port forwarding refers to receiving network requests from a specific port on a machine and forwarding them to another port. This task is usually handled by a router, firewall, or API gateway. You might have a webserver listening on port 3000, and a database server listening at port 5000. The API gateway would listen to requests coming from outside your network. The gateway would forward requests to port 80 to your web server at Port 3000. In the meantime, port 5432 requests would be sent to your database server at Port 5000.
Load Balancing
Load balancing refers to the process of spreading multiple requests to a server evenly across many replicas. This task is usually handled by a specific piece of software or hardware called a loadbalancer. Outsiders are unaware that multiple servers can be running. They think they are making requests to one server. However, the load balancer distributes the request load so that no one server is overwhelmed. The load balancer makes sure that requests go only to healthy nodes in the event of a complete failure of the replica.
Kong Gateway
Kong Gateway is an API gateway layer that sits between upstream services and can perform load balancing and port forwarding tasks. Kong Gateway is the front-door greeter for all requests, regardless of whether those upstream services include web servers, databases, or Minecraft game servers. Kong Gateway is capable of managing traffic control as well as authentication, request transformations and analytics.
Support for TCP Stream
Our Minecraft project is different from other web servers or databases in that Minecraft requires an established connection between Minecraft client (the player) and the server. Instead of expecting stateless HTTP requests we will need to manage TCP connections with streaming data. TCP streaming is supported by Kong Gateway.
This project will be described step-by-step.
As you can see we will start with simplicity and slowly increase our complexity.
This mini-project doesn't require a lot of Minecraft knowledge. It's easy to set up Minecraft servers in Docker containers. A basic knowledge of Docker is helpful.
Docker Engine will be installed on your local computer. Finally, to verify that the project is successful, you will need to install Docker Engine on your local machine. Log in as a paid owner to the Minecraft client. Minecraft's free trial does not allow you to connect to multiplayer servers. This is what we will be using for our project.