Coder Social home page Coder Social logo

kubecraftadmin's Introduction

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:

  • A k8s cluster that you own and are allowed to break
  • A place to run the kubecraftcontainer, this can be anywhere inside or outside of the cluster. As long as it has network connectivity to the cluster and to your Minecraft client.
  • Minecraft Bedrock Edition

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
  1. Start up Minecraft Bedrock Edition
  2. Create a new world with the Activate Cheats option turned on Activate Cheats
  3. 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
  1. Next find a nice area to spawn your kubecraft pen. Type init to generate the structure.
  2. Lastly step on the beacon to activate the link with your cluster.
  3. At this point your pens should be populated with animals!

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:

  • Enumerates entities in Minecraft
  • Enumerates resources in Kubernetes
  • Kills / Spawns the differences in Minecraft

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

  • There are some hacks to make the sync stable. Some operations take time on the kubernetes cluster (e.g. you kill a service in Minecraft). For the duration of the deletion process, Minecraft and Kubernetes will be out of sync (chicken is dead, service is still there). This could lead to syncing issues where KubeCraftAdmin tries to spawn chickens. Right now this is 'fixed' by keeping a list of uniqueIDs and never spawning the same entity twice. This has its own issues. A slight improvement would be to have a TTL on the uniqueIDs, but the best solution would be to keep track of the state as "being synced to MC" or "being synced to K8s".
  • Hardcoded to 4 namespaces (more than 4 will crash)
  • Logging is bad / non-configurable
  • No error handling

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 .

kubecraftadmin's People

Contributors

erjadi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.