apiVersion: apps/v1
kind: Deployment
metadata:
  name: valheim1
  labels:
    app: valheim1
spec:
  replicas: 1
  selector:
    matchLabels:
      app: valheim1
  template:
    metadata:
      labels:
        app: valheim1
    spec:
      # Use an init container to help prepare some config files before the main container starts
      initContainers:
        - name: kubic-valheim-prep-container
          image: busybox:1.28
          command: [ 'sh', '-c' ]
          args:
            - mkdir -p /home/steam/.config/unity3d/IronGate/Valheim
              cp /valheim-config/adminlist.txt  /home/steam/.config/unity3d/IronGate/Valheim/adminlist.txt;
              cp /valheim-config/bannedlist.txt  /home/steam/.config/unity3d/IronGate/Valheim/bannedlist.txt;
              cp /valheim-config/permittedlist.txt  /home/steam/.config/unity3d/IronGate/Valheim/permittedlist.txt;
          volumeMounts:
            - name: valheim-persistent-storage
              mountPath: /home/steam/.config/unity3d/IronGate/Valheim
            - name: valheim-config-volume
              mountPath: /valheim-config
      # Main container actually runs the game server
      containers:
      - image: mbround18/valheim:latest
        name: valheim-server
        resources:
          requests:
            cpu: 300m
            memory: 6G
        env:
          # Server Parameters
        - name: NAME
          value: KubicValheim
        - name: PORT
          value: "31456"  # Must be in quotes since it is meant as a value to put into an environment variable
        - name: PASSWORD # Must be at least 5 characters long and must not contain the server name
          valueFrom:
            secretKeyRef:
              name: valheim-secrets
              key: serverPass
        - name: AUTO_BACKUP
          value: "1"
        - name: AUTO_BACKUP_SCHEDULE
          value: "*/1 * * * *"
        - name: AUTO_BACKUP_REMOVE_OLD
          value: "1"
        - name: AUTO_BACKUP_DAYS_TO_LIVE
          value: "8"
        ports:
          - name: valheim1-port1
            containerPort: 31456
            protocol: UDP
          - name: valheim1-port2
            containerPort: 31457
            protocol: UDP
          - name: valheim1-port3
            containerPort: 31458
            protocol: UDP
        volumeMounts:
        - name: valheim-persistent-storage
          mountPath: /home/steam/.config/unity3d/IronGate/Valheim
        - name: valheim-config-volume
          mountPath: /valheim-config
        - name: valheim1-shared-data
          mountPath: /home/steam/backups
      volumes:
      - name: valheim-persistent-storage
        persistentVolumeClaim:
          claimName: valheim1-pv-claim
      - name: valheim-config-volume
        projected:
          sources:
          - configMap:
              name: valheim-player-lists-cm
      - name: valheim1-shared-data
        persistentVolumeClaim:
          claimName: valheim-shared-pv-claim
