erjadi / kubecraftadmin

MIT License
992 stars 33 forks source link

KubeCraftAdmin

KubeCraftAdmin : The Adventurer's Admin Tool

Would you kill this innocent looking service?

This project allows you to do basic Kubernetes administration through Minecraft.

Quickstart

Read this if you're just interested in trying out KubeCraftAdmin yourself. You will need the following to get started:

How to run KubeCraftAdmin:

  1. Run the container erjadi/kubecraftadmin passing the external port and the location of your .kube directory. The container internally listens to port 8000 and in my case my .kube directory resides in /home/erjadi/.kube. You can optionally specify one to four namespaces from your cluster using the environment variable namespaces
    docker run -p 8000:8000 -v /home/erjadi/.kube:/.kube [-e namespaces=mynamespace1,mynamespace2] erjadi/kubecraftadmin
  2. Start up Minecraft Bedrock Edition
  3. Create a new world with the Activate Cheats option turned on Activate Cheats
  4. Once you've spawned log into the server with the following command after which you should be greeted by the KubeCraftAdmin splash screen. You should also be given some items to start with (a sword, TNT and some flint).
    /connect 10.0.0.1:8000/ws
  5. Next find a nice area to spawn your kubecraft pen. Type init to generate the structure.
  6. Lastly step on the beacon to activate the link with your cluster.
  7. At this point your pens should be populated with animals!

Running KUbecraftadmin on OpenShift

Technical Details

Structure

KubeCraftAdmin is written in Golang. It builds upon the great MCWSS project by Sandertv.

This project makes use of the Websocket Server functionality present in Minecraft Bedrock and Education Edition. The WS connection is a Minecraft client connection, which means that all actions are performed through the client. The server / local world is unaffected and not controlled by this project. This also implies we need to activate cheats in the world to be able to summon or kill entities.

The below description explains the main process which you can find in kubecraftadmin.go.
Highly simplified, KubeCraftAdmin connects to the Kubernetes cluster, spawns the required entities and starts an endless loop function LoopReconcile. Every second it starts a sync function called ReconcileKubetoMC which basically:

For the reverse sync we rely on a mobEvent which triggers execution of ReconcileMCtoKubeMob. We basically perform the same check, but this time we take the Minecraft entities as the truth and delete the corresponding Kubernetes resources.

Known Issues / TODO

How to compile

The easiest way to compile your own version is to use the provided Dockerfile. This way you can build it without requiring a local golang build environment.

docker build -t kubecraftadmin .