Why do this?
- I have a 5 year old son
- we like to play games and build stuff with blocks
- I'm interested in kubernetes
- I saw this post on minecraft in docker
- I wanted to get to know minecraft and kubernetes better
Note: After I got this working, but before I posted this, I came across Julia Ferraioli's series of blog posts about minecraft, docker and kubernetes. These posts are good and you may want to check them out too.
Docker
One of the advantages of Docker is sharing. In the public docker hub, there were a few different minecraft builds available. I choose to reuse Geoff Bourne's (@itzg) dockerfile listed here. Its a great build that lets you specificy many server configuration options via environment variables so you don't have to worry about putting together a minecraft configuration file. With my container already created for me, getting minecraft up in kubernetes was easy.
Game on Kubernetes
First, you will need kubernetes cluster. Doesn't matter where your cluster is as the bueaty of kubernetes is this will work regardless of where your cluster is. Since I work at Centurylink Cloud, I used the scripts I created here to create my kubernetes cluster on CL cloud.
Kubernetes has the concept of pods. A pod in k8 is a logical grouping of one or more containers, zero or more storage volumes and an IP address. We will launch the above minecraft docker container in a pod in kubernetes. And, since minecraft isn't a clustered server, we only need to run one pod per minecraft server.
Here is the yaml file I used to create this pod.
(Also located here: https://github.com/ckleban/minecraft-k8)
apiVersion: v1
kind: Pod
metadata:
name: minecraft-server
labels:
app: minecraft-server
spec:
containers:
- name: minecraft-server
image: itzg/minecraft-server
env:
- name: OPS
value: madsurfer79
- name: EULA
value: "TRUE"
ports:
- containerPort: 25565
You will want to at least change the username in the OPS ENV variable to be your minecraft username. This let's the server know who has admin privileges on the server. You can add more settings, like game type, minecraft version, etc as you wish. To see a more detailed list of what options are available, go check out here. Now, go create the minecraft server:
-------------------------------------
#Create pod
> kubectl create -f pod.yml
#See it up and running:
NAME READY STATUS RESTARTS AGE
minecraft-dfhse 1/1 Running 0 2h
#If you want this server to be reachable on the internet, you probably need to do some more things. If you are on a public cloud, like Centurylink, amazon or google, this is easy to do. Simply run:
> kubectl expose pod minecraft-server --port=25565 --type=LoadBalancer
You will be given a public IP address, which you can see by running:
> kubectl get services
-------------------------------------
That is it. You and your friends can now play minecraft, inside docker, on kubernetes.
A few things to note:
- you may need to wait a few minutes while you wait for the external IP address to be published.
- you may also need to open up a firewall rule to this IP address and port.
- this isn't a durable configuration. If the pod dies, it won't come back online and the save games and world will be gone for ever. These problems are easily solved in kubernetes. We just need to add a replication controller and persistent storage. Perhaps, I'll work on that next and post it sometime.
Thanks
Chris
I think this is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article. Minecraft Server List
ReplyDeleteThis is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value. Im glad to have found this post as its such an interesting one! I am always on the lookout for quality posts and articles so i suppose im lucky to have found this! I hope you will be adding more in the future...
ReplyDeleteMinecraft Server
I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. http://minebrowse.com/
ReplyDeleteOptiFine 1.15.2 Mod for MC 1.15.1/1.14 >>> optifine 1.15.2 mod
ReplyDeleteMinecraft premium mu arıyorsunuz? Tıklayın: minecraft premium satın al
ReplyDelete