DEV Community

Cover image for Run a Minecraft server for free on Kubernetes
Joyce Lin
Joyce Lin

Posted on • Originally published at on

Run a Minecraft server for free on Kubernetes

Simplify deployment for multiplayer Minecraft on a self-hosted Raspberry Pi server using Kubernetes

Just like Minecraft is more fun when a friend shows you how to make torches and avoid creepers, Kubernetes is also less scary with someone to guide the way.

The Minecraft wiki has lots of pointers for setting up your own server. But it doesn’t say how to do it with Kubernetes. I recently learned how easy it is to deploy an app to a local Raspberry Pi with Kubernetes.

Let’s try it again — this time to run a free Minecraft server on Kubernetes.

Running a Minecraft server on Kubernetes? Piece of cake!

Why Kubernetes instead of just Docker?

At a busy airport, air traffic controllers manage the flow of aircraft into and out of the airport airspace.

  • Aircraft transport passengers and cargo from one city to another. The pilots don’t know much about how the airport is managed. They don’t worry about the other aircraft because they rely on the air traffic controllers to keep them safe and moving.
  • Air traffic controllers guide pilots during takeoff and landing and monitor aircraft as they travel through the skies. They’re not opinionated about the aircraft, and don’t mind any loose chickens running through the aisles 🐔

At a less busy airport, you might not need a controller to manage the safety and efficiency of the aircraft. But having one makes operations run smoothly.

There’s a similar relationship between Docker and Kubernetes. Docker containers package software. Kubernetes is the orchestration system coordinating the behavior of those containers.

There’s a separation of concerns — so your containers don’t care where they run, and the orchestration system doesn’t care what is running inside those containers. If you want a refresher, I’ve previously written an intro to the basics.

separation of concerns between Docker and Kubernetes

Kubernetes has a reputation of being “hard”. So why go through the trouble of using it on top of Docker for a simple game server? Even if you run a single app with a single data store, as we’ll do today, Kubernetes can simplify deployment.

The friendly, but independent, relationship between Docker and Kubernetes gives us the flexibility to run our app the way we want. For example, I plan to deploy a lightweight C++ version of Minecraft. Later on, I can update my app to the default Java Minecraft server by swapping out the image of the deployment.

Let’s run Minecraft for free by deploying with Kubernetes on a self-hosted Raspberry Pi server.

A recipe for deploying Minecraft on Kubernetes with KubeSail

The Minecraft wiki lists a bunch of tips for setting up your own server. The game developers behind Minecraft offer a free Java version of server software. The open source community has developed a C++ version that’s more lightweight so we can run it on a Raspberry Pi.

Let’s roll our own Minecraft server using Kubernetes.

Let’s set up a server today!

run a Minecraft server on a single-node cluster on Raspberry Pi

Step 0: pre-requisites


Sign up for a free KubeSail account — to deploy and manage the apps on our cluster.


Decide where to run your Kubernetes cluster. I’m using a $35 Raspberry Pi 4. But you can also use a spare machine if it has enough input/output (I/O) performance to run Minecraft.

Step 1: add a cluster to the Raspberry Pi

I already have a Raspberry Pi 4 to run a Kubernetes cluster. This very good tutorial shows us how to set up a cluster on a new Raspberry Pi.

  • Flash an operating system, like Ubuntu, onto an SD card
  • Enable Secure Shell (SSH) to operate a headless Raspberry Pi without a separate keyboard and monitor
  • Connect the Raspberry Pi directly to the ethernet to reduce latency for gaming — or enable Wi-Fi on the SD card
  • Move the SD card over to the Raspberry Pi
  • Log in to the Raspberry Pi using SSH
  • Install MicroK8s — a lightweight Kubernetes recommended for IOT apps, so your terminal commands will be microk8s.kubectl instead of kubectl

To connect the Raspberry Pi to KubeSail, apply the configuration file to your personal namespace from the Raspberry Pi’s command line. This might take a couple minutes to spin up.

$ sudo microk8s.kubectl apply -f [<your-kubesail-username>.yaml](
Enter fullscreen mode Exit fullscreen mode

1) add a cluster on the Raspberry Pi using microk8s.kubectl instead of kubectl, and 2) give it a name

The Raspberry Pi is now a single-node Kubernetes cluster!

You can manage this new cluster in the KubeSail dashboard. Find the new cluster, give it a name, and then select Namespaces from the sub-menu. This is where you can add a new Kubernetes namespace, like one called games.

Add a new namespace called games

Now we have a Kubernetes context consisting of a cluster, a namespace, and a user — everything that we need to set up our deployment.

Step 2: fork a public template

KubeSail has a bunch of Kubernetes templates to browse YAML examples and customize your own deployments.

Under Templates , I made this one for Minecraft on Raspberry Pi. If you’re not using a Raspberry Pi, use this template instead.

minecraft-raspberry-pi: Minecraft server with a Persistent Volume Claim to store your world data, on Raspberry Pi 🍓. This template also runs on any board with an arm64 CPU .

The minecraft-raspberry-pi template has two kinds of Kubernetes resources.

fork the minecraft-raspberry-pi template

Fork the template. You can rename it, and also toggle the new template’s setting to Private if you don’t want the template to be listed publicly as one of your own.

The YAML explained

This section explains some of the underlying YAML for these resources if you want to make any adjustments. Feel free to skip ahead to the next step.

In your new KubeSail template, click the Edit Yaml button to open the YAML editor on the right side of the page. Find the Deployment document tab in the YAML editor, and notice some details.

  • replicas: to specify the number of pods to run
  • image: the base Docker image for the container is joycelin79/cuberite, a C++ version of Minecraft (instead of the default Java) that is more lightweight for the Raspberry Pi or any machine with an arm64 CPU
  • volumes: there’s a single volume, or data store, that points to our second resource which is a PersistentVolumeClaim
  • volumeMounts: uses subpaths to specify where to mount the volumes into the container according to how the base image is structured
  • ports: exposes the port by setting the hostPort and containerPort — these two ports should be the same value, the default Minecraft port 25565
  • resources: allocates your cluster’s memory to run your game smoothly, you may need to increase this amount, but most game servers should run below 1 CPU and 2Gi of memory

Review the deployment details

Find the PersistentVolumeClaim document tab in the YAML editor. This claim asks the cluster for a particular type of storage, to be provisioned as a PersistentVolume.

  • name : points back to the volume specified in the Deployment document
  • resources: this is a request for resources for the volume, or the data stored, and 2Gi should be enough for the Minecraft world.

Review PersistentVolumeClaim

The PersistentVolume in this deployment allows us to save the state of the Minecraft world, so that we can quit our game and keep all of our precious minerals when the server reboots 💎

Step 3: deploy on Kubernetes

We’re ready to deploy our app on Kubernetes!

In the dropdown menu next to the Launch Template button, select theKubernetes context from Step 1.

Select a Kubernetes context to deploy the app

Hit Launch Template , and KubeSail will deploy Minecraft. In this example, I deploy to the games namespace on my Raspberry Pi cluster.

Our Minecraft server is alive!

Step 4: connect to the Minecraft server

To connect to the Minecraft server, start Minecraft on the machine where you want to play. Select Multiplayer from the main menu. Click the Add Server button, and enter the IP or web address of the Raspberry Pi server. If you’re on the same local network, you should see the server suggested in the local list.

scanning for games on the local network

If you want to allow access to the Minecraft server via the internet, set up port forwarding to point port 25565 to the IP of your Raspberry Pi. If you need a refresher, here is a tutorial to forward ports on your router.

Provide this public IP to friends you invite to multiplayer Minecraft. Or you can set up an A record with your DNS provider that points to your home network like we did previously, so friends can input a URL instead of an IP address.

Players need to run the same version of Minecraft as the server. As of the writing of this article, the latest version of cuberite is 1.12, so players should set their Minecraft version to 1.12.

So that’s it!

We set up a Minecraft server on Raspberry Pi using Kubernetes with a few terminal commands and clicks. Hosting a game server from your living room is free and easy. With the time I saved setting up a Minecraft server, I now have more time to spend on mining precious minerals

🤓 Fun Fact: If my IP address changes while I’m away from home, I might have trouble accessing the game server or any other self-hosted services. Check out this other tutorial I wrote for setting up a dynamic DNS service, also on Raspberry Pi using Kubernetes!

Final thoughts on deploying with Kubernetes

When people talk about Kubernetes, they picture huge companies with tons of traffic hitting their services. My little game server certainly doesn’t need Kubernetes for any advanced capabilities. But Kubernetes can also make deployment easier. I’ve done the “hard part” by configuring the Minecraft server to run on Kubernetes. And now if I want to run Kubernetes on a different cluster, I switch the context in KubeSail to deploy my changes with a single click.

Most people also picture Kubernetes running on a managed cloud provider, which can get expensive. But now we know how to run a cluster for free on a local machine like a Raspberry Pi.

There’s a bunch of reasons why people use Kubernetes. For this game server, I’m using Kubernetes to simplify deployment and because it’s free to run on a self-hosted server.

Try it yourself, and let me know what you think!

Top comments (0)