Your first server
Create a Minecraft server, connect to it and run a command, in a few minutes.
This guide assumes Kobblestone is installed. All commands use a namespace called minecraft:
kubectl create namespace minecraftCreate the server
Save this as server.yaml:
apiVersion: kobblestone.io/v1alpha1kind: Servermetadata: name: my-server namespace: minecraftspec: eula: true type: Paper version: "26.2" storage: size: 2Gi resources: limits: memory: 2Gieula: trueaccepts the Minecraft EULA. The server does not start without it.typeandversionpick the server software and game version.version: LATESTalways uses the latest release.storagegives the server a volume for its world and configuration.- The memory limit also sizes the Java heap: by default, 75% of it.
Apply it and wait until the server is up:
kubectl apply -f server.yamlkubectl -n minecraft wait --for=condition=Running=True server/my-server --timeout=5mThe first start downloads the server software and generates the world, so it can take a few minutes. Follow along with:
kubectl -n minecraft get server my-serverkubectl -n minecraft logs my-server-0 -c server -fConnect to it
The server is only reachable inside the cluster for now. For a quick test, forward its port to your machine:
kubectl -n minecraft port-forward svc/my-server 25565:25565Then add localhost as a server in Minecraft and join. To make the server reachable for other players, see exposing servers.
Run a command
Commands are resources too. Save this as command.yaml and apply it:
apiVersion: kobblestone.io/v1alpha1kind: Commandmetadata: name: hello namespace: minecraftspec: targetRef: name: my-server command: say Hello from Kubernetes!The server’s answer ends up in the resource’s status:
kubectl -n minecraft get command hello -o jsonpath='{.status.response}'Stop, start and clean up
Set spec.state to Stopped to shut the server down while keeping its data, and back to Running to start it again:
kubectl -n minecraft patch server my-server --type merge -p '{"spec":{"state":"Stopped"}}'When you are done, delete the server. This deletes its volume and the world with it.
kubectl -n minecraft delete server my-server