Skip to content
Check out the jot that produced this doc! Check it out

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

  1. Navigate to playit.gg
  2. Name your agent (ex: homelab-agent)
  3. Save the secret key

Kubernetes

  1. Create a namespace: kubectl create ns minecraft

  2. Apply the following ConfigMap to your namespace: kubectl apply -f configmap.yaml -n minecraft

    configmap.yaml
    apiVersion: v1
    kind: ConfigMap
    metadata:
    name: mc
    data:
    SERVER_NAME: "Example Minecraft Server"
    EULA: "true"
    VERSION: "1.21.1"
    MAX_PLAYERS: "10"
    OPS: |
    YOUR_USERNAME_GOES_HERE
    ENABLE_WHITELIST: "true"
    WHITELIST: |
    YOUR_USERNAME_GOES_HERE

    Note: Make sure to update the OPS and WHITELIST variables to your minecraft username before applying

  3. 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

  4. Apply the following deployment manifest: kubectl apply -f deployment.yaml -n minecraft

    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
    name: mc
    spec:
    replicas: 0
    selector:
    matchLabels:
    server: mc
    template:
    metadata:
    labels:
    server: mc
    spec:
    containers:
    - name: mc
    image: itzg/minecraft-server
    stdin: true
    tty: true
    envFrom:
    - configMapRef:
    name: mc
    volumeMounts:
    - mountPath: /data
    name: data
    resources:
    requests:
    cpu: 2
    memory: 4Gi
    limits:
    cpu: 2
    memory: 4Gi
    - name: playit
    image: ghcr.io/playit-cloud/playit-agent:0.15
    env:
    - name: SECRET_KEY
    valueFrom:
    secretKeyRef:
    name: playit-gg-secret
    key: SECRET_KEY
    volumeClaimTemplates:
    - metadata:
    name: data
    spec:
    storageClassName: omv-porp-nvme
    accessModes:
    - ReadWriteOnce
    resources:
    requests:
    storage: 8Gi

DNS

  1. Navigate to playit.gg
  2. Click on the Agent we just created and find the Tunnel it created or create a Tunnel Minecraft Java
  3. Click on the Tunnel, scroll down and copy Allocation (Shared IP) (ex: 00.ip.gl.ply.gg)
  4. Run nslookup 00.ip.gl.ply.gg and copy the IP Address
  5. Add the following DNS Entries:
A mc IP_FROM_NSLOOKUP
SRV _minecraft._tcp.mc 0 0 63346 mc.SOME_DOMAIN.com
  1. 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.