blog.kuepper.nrw

Deploy Minecraft Server on Kubernetes Cluster

Rüdiger Küpper KubernetesMinecraftBedrockInternet

Create Kubernetes YAML for

  • Namespace
  • Configmap
  • PersistentVolumeClaim
  • Loadbalancer Service
  • StatefulSet
cat > minecraft.yaml <<EOF
---
apiVersion: v1
kind: Namespace
metadata:
  name: blog-kuepper
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: minecraft-bedrock
  namespace: minecraft
  labels:
    role: service-config
    app: bds
data:
  # Find more options at https://github.com/itzg/docker-minecraft-bedrock-server#server-properties
  # Remove # from in front of line if changing from default values.
  EULA: "TRUE" # Must accept EULA to use this minecraft server
  GAMEMODE: "creative" # Options: survival, creative, adventure
  #DIFFICULTY: "easy" # Options: peaceful, easy, normal, hard
  #DEFAULT_PLAYER_PERMISSION_LEVEL: "member" # Options: visitor, member, operator
  LEVEL_NAME: "my_minecraft_world"
  #LEVEL_SEED: "33480944"
  #SERVER_NAME: "my_minecraft_server"
  #SERVER_PORT: "19132"
  #LEVEL_TYPE: "DEFAULT" # Options: FLAT, LEGACY, DEFAULT
  #ALLOW_CHEATS: "false" # Options: true, false
  #MAX_PLAYERS: "10"
  #PLAYER_IDLE_TIMEOUT: "30"
  #TEXTUREPACK_REQUIRED: "false" # Options: true, false
  #
  ## Changing these will have a security impact
  #ONLINE_MODE: "true" # Options: true, false (removes Xbox Live account requirements)
  #WHITE_LIST: "false" # If enabled, need to provide a whitelist.json by your own means. 
  #
  ## Changing these will have a performance impact
  #VIEW_DISTANCE: "10"
  #TICK_DISTANCE: "4"
  #MAX_THREADS: "8"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: bds
  namespace: minecraft
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app: bds
  name: bds
  namespace: minecraft
spec:
  # never more than 1 since BDS is not horizontally scalable
  replicas: 1
  serviceName: bds
  selector:
    matchLabels:
      app: bds
  template:
    metadata:
      labels:
        app: bds
    spec:
      containers:
        - name: main
          image: itzg/minecraft-bedrock-server
          imagePullPolicy: Always
          envFrom:
            - configMapRef:
                name: minecraft-bedrock
          volumeMounts:
            - mountPath: /data
              name: data
          ports:
            - containerPort: 19132
              protocol: UDP
          readinessProbe: &probe
            exec:
              command:
                - mc-monitor
                - status-bedrock
                - --host
                # force health check against IPv4 port
                - 127.0.0.1
            initialDelaySeconds: 30
          livenessProbe: *probe
          tty: true
          stdin: true
  volumeClaimTemplates:
    - metadata:
        name: data
      spec:
        accessModes:
          - ReadWriteOnce
        resources:
          requests:
            storage: 1Gi
---
apiVersion: v1
kind: Service
metadata:
  name: bds
  namespace: minecraft
spec:
  selector:
    app: bds
  ports:
    - port: 19132
      protocol: UDP
  # ipFamily: IPv4
  # Use LoadBalancer if running on a provider that supports that
  type: LoadBalancer
  # or use NodePort on a non-managed system;
  # however, you'll need to lookup port assigned to the service
  # type: NodePort
EOF

Deploy to Kubernetes Cluster:

kubectl apply -f minecraft.yaml
Rüdiger Küpper
DevOps Engineer & CISO @ Mogenius