# https://github.com/itzg/docker-minecraft-server/blob/master/README.md
# 
# Check health with:
#  docker container inspect -f "{{.State.Health.Status}}" mc

apiVersion: v1
kind: Service
metadata:
  name: minecraft
  labels:
    run: minecraft
spec:
  ports:
    - name: rcon
      port: 25575
      targetPort: 25575
    - name: server
      port: 25565
      targetPort: 25565
  selector:
    run: minecraft
  type: LoadBalancer
  loadBalancerIP: 10.42.42.215
  externalTrafficPolicy: Local
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: minecraft-data
spec:
  capacity:
    storage: 10Ti
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Retain # Keep 4eva
  storageClassName: default
  mountOptions:
    - hard
    - nfsvers=3
  nfs:
    path: /mnt/DroboFS/Shares/Kubernetes/volumes/static/minecraft-data
    server: 10.42.42.10
  claimRef:
    name: minecraft-data
    namespace: default
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minecraft-data
spec:
  storageClassName: standard
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 10Ti
status: {}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minecraft
spec:
  replicas: 1
  selector:
    matchLabels:
      run: minecraft
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        run: minecraft
    spec:
      terminationGracePeriodSeconds: 90
      containers:
        - image: itzg/minecraft-server:latest
          imagePullPolicy: "Always"
          name: minecraft
          env:
            - name: TZ
              value: US/Michigan
            - name: MEMORY
              value: "3G"
            # max tick time is default 60.0 seconds (60000 here), -1 to disable
            - name: MAX_TICK_TIME
              value: "-1"
            - name: MAX_PLAYERS
              value: "6"
            - name: VERSION
              value: "1.19.2"
            - name: EULA
              value: "TRUE"
            - name: CF_API_KEY
              value: "$$2a$$10$$JU91aPtRDMOid0cAfwDGwuk3IETckr93LyV/zW3Xfz49TrT0PoiYy"
            - name: TYPE
              value: "FORGE"
#            - name:  GENERIC_PACK
#              value: "lol.zip"
#            - name: TYPE
#              value: "AUTO_CURSEFORGE"
#            - name: CF_MODPACK_ZIP
#              value: "lol.zip"
            # Values below this line will likely have no effect.
            # Update the configuration in the data directory instead
            - name: MOTD
              value: "Enjoy MonkeyBOX!"
            - name: OPS
              value: "Aspectra7495"
            - name: RCON_PASSWORD
              value: "0202"
            - name: ANNOUNCE_PLAYER_ACHIEVEMENTS
              value: "true"
            - name: MODE
              value: "survival"
            - name: SERVER_NAME
              value: "monkeybox"
            - name: STOP_SERVER_ANNOUNCE_DELAY
              value: "60"
            - name: ENABLE_ROLLING_LOGS
              value: "true"
          ports:
            - containerPort: 25575
            - containerPort: 25565
          resources:
            limits:
              memory: "8192Mi"
              cpu: "8000m"
            requests:
              memory: "3384Mi"
              cpu: "2000m"
          volumeMounts:
            - mountPath: /data
              name: minecraft-data
      restartPolicy: Always
      volumes:
        - name: minecraft-data
          persistentVolumeClaim:
            claimName: minecraft-data
status: {}
#---
## Hosting
#apiVersion: networking.k8s.io/v1
#kind: Ingress
#metadata:
#  name: minecraft-ingress
#  annotations:
#    cert-manager.io/cluster-issuer: "letsencrypt-prod"
#    ## No basic auth for minecraft
#    ## type of authentication
#    #nginx.ingress.kubernetes.io/auth-type: basic
#    ## name of the secret that contains the user/password definitions
#    #nginx.ingress.kubernetes.io/auth-secret: basic-auth
#    ## message to display with an appropriate context why the authentication is required
#    #nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required - Octoprint'
#spec:
#  tls:
#  - hosts:
#    - minecraft.monkeybox.org
#    secretName: minecraft-tls
#  rules:
#  - host: minecraft.monkeybox.org
#    http:
#      paths:
#      - path: /
#        pathType: Prefix
#        backend:
#          service:
#            name: minecraft
#            port:
#              number: 80
