Minecraft on Kubernetes

How to install Minecraft Vanilla 1.18.2 on Kubernetes.

helm repo add itzg https://itzg.github.io/minecraft-server-charts/
helm repo update

kubectl create ns minecraft
helm install --namespace minecraft minecraft -f minecraft.yaml --set minecraftServer.eula=true itzg/minecraft

We also need to make the minecraft.yaml file for the installation here is the content.

# ref: https://hub.docker.com/r/itzg/minecraft-server/
image: itzg/minecraft-server
imageTag: latest

## Configure resource requests and limits
## ref: http://kubernetes.io/docs/user-guide/compute-resources/
##
resources:
  requests:
    memory: 1024Mi
    cpu: 500m

# upgrade strategy type (e.g. Recreate or RollingUpdate)
strategyType: Recreate

nodeSelector: {}

tolerations: []

affinity: {}

securityContext:
  # Security context settings
  runAsUser: 1000
  fsGroup: 2000
# Most of these map to environment variables. See Minecraft for details:
# https://hub.docker.com/r/itzg/minecraft-server/
livenessProbe:
  command:
    - mc-monitor
    - status
    - localhost:25565
  initialDelaySeconds: 30
  periodSeconds: 5
  failureThreshold: 10
  successThreshold: 1
  timeoutSeconds: 1
readinessProbe:
  command:
    - mc-monitor
    - status
    - localhost:25565
  initialDelaySeconds: 30
  periodSeconds: 5
  failureThreshold: 10
  successThreshold: 1
  timeoutSeconds: 1
minecraftServer:
  # This must be overridden, since we can't accept this for the user.
  eula: "true"
  # One of: LATEST, SNAPSHOT, or a specific version (ie: "1.7.9").
  version: "latest"
  # This can be one of "VANILLA", "FORGE", "SPIGOT", "BUKKIT", "PAPER", "FTB", "SPONGEVANILLA"
  type: "VANILLA"
  # If type is set to FORGE, this sets the version; this is ignored if forgeInstallerUrl is set
  forgeVersion:
  # If type is set to SPONGEVANILLA, this sets the version
  spongeVersion:
  # If type is set to FORGE, this sets the URL to download the Forge installer
  forgeInstallerUrl:
  # If type is set to BUKKIT, this sets the URL to download the Bukkit package
  bukkitDownloadUrl:
  # If type is set to SPIGOT, this sets the URL to download the Spigot package
  spigotDownloadUrl:
  # If type is set to PAPER, this sets the URL to download the PaperSpigot package
  paperDownloadUrl:
  # If type is set to FTB, this sets the server mod to run. You can also provide the URL to download the FTB package
  ftbServerMod:
  # Set to true if running Feed The Beast and get an error like "unable to launch forgemodloader"
  ftbLegacyJavaFixer: false
  # One of: peaceful, easy, normal, and hard
  difficulty: easy
  # A comma-separated list of player names to whitelist.
  whitelist:
  # A comma-separated list of player names who should be admins.
  ops:
  # A server icon URL for server listings. Auto-scaled and transcoded.
  icon:
  # Max connected players.
  maxPlayers: 10
  # This sets the maximum possible size in blocks, expressed as a radius, that the world border can obtain.
  maxWorldSize: 10000
  # Allows players to travel to the Nether.
  allowNether: true
# Allows server to announce when a player gets an achievement.
  announcePlayerAchievements: true
  # Enables command blocks.
  enableCommandBlock: true
  # If true, players will always join in the default gameMode even if they were previously set to something else.
  forcegameMode: false
  # Defines whether structures (such as villages) will be generated.
  generateStructures: true
  # If set to true, players will be set to spectator mode if they die.
  hardcore: false
  # The maximum height in which building is allowed.
  maxBuildHeight: 256
  # The maximum number of milliseconds a single tick may take before the server watchdog stops the server with the message. -1 disables this entirely.
  maxTickTime: 60000
  # Determines if animals will be able to spawn.
  spawnAnimals: true
  # Determines if monsters will be spawned.
  spawnMonsters: true
  # Determines if villagers will be spawned.
  spawnNPCs: true
  # Max view distance (in chunks).
  viewDistance: 6
  # Define this if you want a specific map generation seed.
  levelSeed:
  # One of: creative, survival, adventure, spectator
  gameMode: creative
  # Message of the Day
  motd: "Welcome to Minecraft on Kubernetes!"
  # If true, enable player-vs-player damage.
  pvp: false
  # One of: DEFAULT, FLAT, LARGEBIOMES, AMPLIFIED, CUSTOMIZED
  levelType: DEFAULT
  # When levelType == FLAT or CUSTOMIZED, this can be used to further customize map generation.
  # ref: https://hub.docker.com/r/itzg/minecraft-server/
  generatorSettings:
  worldSaveName: world
  # If set, this URL will be downloaded at startup and used as a starting point
  downloadWorldUrl:
  # force re-download of server file
  forceReDownload: false
  # If set, the modpack at this URL will be downloaded at startup
  downloadModpackUrl:
  # If true, old versions of downloaded mods will be replaced with new ones from downloadModpackUrl
  removeOldMods: false
  # Check accounts against Minecraft account service.
  onlineMode: true
  # If you adjust this, you may need to adjust resources.requests above to match.
  memory: 1024M
  # General JVM options to be passed to the Minecraft server invocation
  jvmOpts: ""
  # Options like -X that need to proceed general JVM options
  jvmXXOpts: ""
  serviceType: LoadBalancer
  loadBalancerIP:
  # loadBalancerSourceRanges: []
  ## Set the externalTrafficPolicy in the Service to either Cluster or Local
  # externalTrafficPolicy: Cluster

  rcon:
    # If you enable this, make SURE to change your password below.
    enabled: false
    port: 25575
    password: "CHANGEME!"
    serviceType: LoadBalancer
    loadBalancerIP:
    # loadBalancerSourceRanges: []
    ## Set the externalTrafficPolicy in the Service to either Cluster or Local
    # externalTrafficPolicy: Cluster


  query:
    # If you enable this, your server will be "published" to Gamespy
    enabled: false
    port: 25565

## Additional minecraft container environment variables
##
extraEnv: {}

persistence:
  ## minecraft data Persistent Volume Storage Class
  ## If defined, storageClassName: <storageClass>
  ## If set to "-", storageClassName: "", which disables dynamic provisioning
  ## If undefined (the default) or set to null, no storageClassName spec is
  ##   set, choosing the default provisioner.  (gp2 on AWS, standard on
  ##   GKE, AWS & OpenStack)
  ##
  storageClass: "nfs"
  dataDir:
    # Set this to false if you don't care to persist state between restarts.
    enabled: true
    # existingClaim: nil
    Size: 1Gi

podAnnotations: {}

deploymentAnnotations: {}

If you like to see some information about the installation can you do this with kubectl.

kubectl get pods -n minecraft
kubectl get service -n minecraft -o wide
kubectl get svc --namespace minecraft -w minecraft-minecraft

Uninstall the Minecraft server on Kubernetes is also easy with

helm uninstall --namespace minecraft minecraft

I use the Minecraft server with persistent storage on NFS. So my world not get lost on reboot or updates.

To make an update on the Minecraft server can you use this command.

helm upgrade --namespace minecraft minecraft -f minecraft.yaml --set minecraftServer.eula=true itzg/minecraft

We can also take a look from Portainer to see our Minecraft server and check the logs.

You will find Minecraft under Applications. Click on Minecraft and you can also see the log and the node.

To manage the server settings can you use the Console.

Consol from Portainer

Here you can find your World, the server.properties and ops.json where you can define your Minecraft admins.

You will also need this link to find you UUID for the Minecraft admins.

https://minecraftuuid.com/

You need this information to edit the ops.json file from the Portainer console.

Here the format of ops.json

After a restart of the Minecraft server now the user Knud can use the superuser commands. Change the uuid and your username.

Have fun ;O)

Leave a comment

Your email address will not be published.