Self-Hosting Minecraft on Kubernetes
Introduction
This Jot will walk you through how to run a Minecraft Java server with a custom domain on Kubernetes without opening any ports on your router.
Prerequisites
- Kubernetes
- Persistent Storage
- Playit.gg
- DNS Access
Playit.gg
- Navigate to playit.gg
- Name your agent (ex:
homelab-agent
) - Save the secret key
Kubernetes
-
Create a namespace:
kubectl create ns minecraft
-
Apply the following ConfigMap to your namespace:
kubectl apply -f configmap.yaml -n minecraft
configmap.yaml apiVersion: v1kind: ConfigMapmetadata:name: mcdata:SERVER_NAME: "Example Minecraft Server"EULA: "true"VERSION: "1.21.1"MAX_PLAYERS: "10"OPS: |YOUR_USERNAME_GOES_HEREENABLE_WHITELIST: "true"WHITELIST: |YOUR_USERNAME_GOES_HERENote: Make sure to update the
OPS
andWHITELIST
variables to your minecraft username before applying -
Create a secret which will contain the Agent key we obtained in the steps prior:
kubectl create secret generic playit-gg-secret --from-literal=SECRET_KEY=<TUNNEL_KEY_GOES_HERE> -n minecraft
-
Apply the following deployment manifest:
kubectl apply -f deployment.yaml -n minecraft
apiVersion: apps/v1kind: StatefulSetmetadata:name: mcspec:replicas: 0selector:matchLabels:server: mctemplate:metadata:labels:server: mcspec:containers:- name: mcimage: itzg/minecraft-serverstdin: truetty: trueenvFrom:- configMapRef:name: mcvolumeMounts:- mountPath: /dataname: dataresources:requests:cpu: 2memory: 4Gilimits:cpu: 2memory: 4Gi- name: playitimage: ghcr.io/playit-cloud/playit-agent:0.15env:- name: SECRET_KEYvalueFrom:secretKeyRef:name: playit-gg-secretkey: SECRET_KEYvolumeClaimTemplates:- metadata:name: dataspec:storageClassName: omv-porp-nvmeaccessModes:- ReadWriteOnceresources:requests:storage: 8Gi
DNS
- Navigate to playit.gg
- Click on the Agent we just created and find the Tunnel it created or create a Tunnel
Minecraft Java
- Click on the Tunnel, scroll down and copy
Allocation (Shared IP)
(ex:00.ip.gl.ply.gg
) - Run
nslookup 00.ip.gl.ply.gg
and copy the IP Address - Add the following DNS Entries:
A mc IP_FROM_NSLOOKUPSRV _minecraft._tcp.mc 0 0 63346 mc.SOME_DOMAIN.com
- You should be able to connect to Minecraft from
mc.SOME_DOMAIN.com
!
Note: The shared IP COULD change. If it does, just update your DNS records. From my experience it rarely does.