Running Minecraft Server in Kubernetes Cluster

My own Minecraft server 🙂

A month ago I had an idea to run a Minecraft server in my garage Kubernetes lab. I though it might interest my little Minecraft player at home with some Kubernetes and GitOps stuff but that failed miserably. But at least I knew how to host a Minecraft server in Kubernetes, with ArgoCD too.

First step, of course the server which is an java app needs to be packed into a Docker image. From the official installation guide, the essential steps are

  • Use OpenJDK 16+ as base image
  • Download the server.jar
  • Run it with java -jar server.jar nogui
  • Make sure port 25565/tcp is open

That’s it! The Dockerfile looks like:

FROM openjdk:16.0.2

WORKDIR /minecraft

RUN curl -O

ADD config/* ./
RUN chown -R nobody /minecraft

USER nobody
CMD ["java", "-jar", "server.jar", "nogui"]

And the GitHub Action pipeline:

    runs-on: [ ubuntu-20.04 ]

      - uses: actions/[email protected]

      - name: build number
        run: |
          echo "build_number=dev-${GITHUB_RUN_ID}" >> $GITHUB_ENV

      - name: Docker build kubecraft-server
        run: |
          docker build -t$build_number .

      - name: Docker push
        run: |
          echo ${{ secrets.GHCR_PAT }} | docker login -u $GITHUB_ACTOR --password-stdin
          docker push$build_number
      # The GitHub Action pipeline will update the Kustomize patch file so the most recent tag will be referred to. 
      - name: Update deployment version
        run: |
          sed -i -E "s|(image:*|\1$build_number|g" kustomize/

      - name: Auto commit & push changes
        run: |
          git config --global '***'
          git config --global '***'
          git commit -am "Automated commit"
          git push

For more information, here’s my GitHub repository containing the docker build pipeline using GitHub Actions. There is also a kustomize directory where all necessary Kustomize templates reside.

The next step is to register the Kustomize templates as an app in ArgoCD. It can be done declaratively like:

kind: Application
  name: kubecraft
  namespace: argocd
    namespace: kubecraft
    server: https://kubernetes.default.svc
  project: default
    path: kustomize/
    targetRevision: HEAD
      prune: true

Here’s what it looks like in ArgoCD:

Since it’s not mentioned in the office document on how to configure session sharing for multiple Minecraft server instances, I doubt the meaning to create more than one pod.

TO-DO: I haven’t included a persistent volume in my Kustomize templates, which means the server will lose the state of the game world when re-deployed.

EDIT: A PersistentVolume is a nice-to-have. A PV sample made with NFS + CSI is here.