KubeCraftAdmin: use Minecraft to manage K8S tools, interested brothers may wish to play a play.

Minecraft: Minecraft is a sandbox game from Microsoft. The player can interact with the blocks in a 3D world. It’s a popular game where players build fantastical virtual worlds out of blocks of numbers

Why isn’t there an immersive 3D sandbox user interface to manage the workload in the container choreography?

KubeCraftAdmin was inspired by MakeCode for Minecraft to make learning to code super fun, manipulating the world in Minecraft programmatically via WebSocket Server.

Projects are filled with different animals in different enclosures (one per namespace). Each animal corresponds to a resource in the K8S cluster.

  • The pig is the Pods
  • Cattle are ReplicaSets
  • The chicken is Services
  • The horse is Deployments

By connecting to KubeCraft Admin WS, you can connect to the specified K8S cluster. Reflect cluster resources through animals. Animals die when resources are deleted. Conversely, killing an animal in Minecraft removes the resource.

KubeCraftAdmin

KubeCraftAdmin: Management tool for adventurers

This project allows you to do basic Kubernetes management via Minecraft.

If you want to operate, you need the following conditions:

  • A K8S cluster
  • Run kubecraft containers inside or outside of a cluster that can connect to a K8S cluster and Minecraft clients
  • Minecraft based version

Run KubeCraftAdmin

Run container, set port mapping, mount. Kube directory. The container listens internally on port 8000. You can specify 1 to 4 namespaces from a cluster using the environment variable namespaces.

docker run --name kca -d -p 8000:8000 -v /root/.kube:/.kube -e namespaces=kca1,kca2 erjadi/kubecraftadmin
Copy the code
# docker ps -f name=kcaCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 58ee6241048b erjadi/kubecraftadmin "/app/main" 30 seconds ago Up 29 seconds 0.0.0.0:8000->8000/ TCP, :::8000->8000/ TCP KCACopy the code
  1. Launch Minecraft Basics

  2. Open the Activate Cheats option to create a new world

  1. When you log in to the server with the following command, you should see the KubeCraftAdmin splash screen. At the beginning of the game, you need to get some items (sword, TNT, flint).
/ connect 10.0.0.1:8000 / wsCopy the code
  1. Find an area to generate kubecraft fences. Type init to generate the structure.

  2. Finally, activate the cluster link on the Beacon.

  3. At this point, your pen should be filled with some animals (K8S resources).

The technical details

KubeCraftAdmin is written in Golang. It builds on Sandertv’s MCWSS project.

This project utilizes Websocket Server functionality on Minecraft Basics and Education. The WS connection is a Minecraft client connection, and all actions are performed through the client. Server/Local is not affected and is not controlled by this project. This means that we need to activate the cheat mechanism in order to be able to generate or kill entities.

The main process can be found in kubecraftadmin.go.

The simplified KubeCraftAdmin connects to the Kubernetes cluster, generates the required entities, and starts an endless loop function called LoopReconcile. Every second it fires up a synchronization function called ReconcileKubetoMC, which basically says:

  • Enumerate entities in Minecraft
  • Enumerate resources in Kubernetes
  • Make or kill differences in Minecraft

For the reverse synchronization, it relies on mobEvent, which triggers the execution of the ReconcileMCtoKubeMob. Basically the same checks are performed, but this time with Minecraft entities as the standard and Kubernetes resources removed.


Minecraft as a K8s admin tool

The original

This article is first published in the wechat public number “My small bowl of soup”. Scan the left code to follow, learn more about consultation, and have free resources for you to learn

The author is simple

Author: Xiaowantang, a passionate and serious writer, currently maintains the original public account “My Xiaowantang”, focusing on writing the go language, Docker, Kubernetes, Java and other development, operation and maintenance knowledge to enhance the hard power of the article, looking forward to your attention. Note: Be sure to specify the source (note: from the official account: My Small bowl of soup, author: Small bowl of soup)