Kubernetes at home - Part 9: Minecraft World0

I want to run a Minecraft service on my home network.

For reference, I started from this wonderful guide.

daniel@bequiet:~$ kubectl label node danielamd type=local
node/danielamd labeled

daniel@bequiet:~/development/k8s-home/minecraft$ kubectl create namespace minecraft-world0
namespace/minecraft-world0 created

Persistent Volume

kind: PersistentVolume
apiVersion: v1
metadata:
  name: minecraft-pv-world0
  labels:
    type: local
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  capacity:
    storage: 50Gi
  hostPath:
    path: "/media/working/minecraft/world0"
  nodeAffinity:
    required:
      nodeSelectorTerms:
      - matchExpressions:
        - key: type
          operator: In
          values:
          - local

Minecraft deployment

Key things to notice:

  1. hostNetwork=true. Not good practice, but I am letting the default minecraft port 25565 be open.
  2. spec.strategy.type=Recreate. When updating deployments, I want all pods to stop before recreating. Minecraft likes to lock files.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: minecraft-pvc-world0
  namespace: minecraft-world0
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minecraft-server-world0
  namespace: minecraft-world0
  labels:
    app: minecraft-server
spec:
  strategy:
    type: Recreate
  replicas: 1
  selector:
    matchLabels:
      app: minecraft-server
  template:
    metadata:
      labels:
        app: minecraft-server
    spec:
      hostNetwork: true
      volumes:
      - name: minecraft-pv-world0
        persistentVolumeClaim:
          claimName: minecraft-pvc-world0
      containers:
      - name: minecraft-server
        image: itzg/minecraft-server:latest
        resources:
          limits:
            memory: 4Gi
          requests:
            memory: 2Gi
        env:
          - name:  EULA
            value: 'TRUE'
          - name: MODE
            value: creative
          - name: MOTD
            value: Daniel's Minecraft server
          - name: ALLOW_FLIGHT
            value: 'TRUE'
        ports:
        - containerPort: 25565
          name: minecraft
        volumeMounts:
          - name: minecraft-pv-world0
            mountPath:  /data
        readinessProbe:
          exec:
            command:
            - mcstatus
            - 127.0.0.1
            - ping
          initialDelaySeconds: 30
          periodSeconds: 30
        livenessProbe:
          exec:
            command:
            - mcstatus
            - 127.0.0.1
            - ping
          initialDelaySeconds: 30
          periodSeconds: 30

Address

Server Info

I am already routing wildcard for my domain to that single-node cluster. And since the default port is being used, it just naturally works.

Server View

Server Inside