Déployer des applications dans K8S !

Minecraft

Quelle joie pour moi de déployer un serveur minecraft dans K8S !

En prérequits à ce tuto :

Création du namespace Minecraft :

kubectl create namespace minecraft

Déclaration du PVC :

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: minecraft-srv-01-pvc
  namespace: minecraft
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
EOF

Déploiement & service minecraft :

cat <<EOF | kubectl apply -f -
apiVersion: apps/v1
kind: Deployment
metadata:
  name: minecraft-01
  namespace: minecraft
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: minecraft-01
  template:
    metadata:
      labels:
        app: minecraft-01
    spec:
      containers:
        - name: minecraft-01
          image: itzg/minecraft-server:java8
          env:
            - name: EULA
              value: "TRUE"
            - name: VERSION
              value: "1.12.2"
            - name: TYPE
              value: "MOHIST"
            - name: MEMORY
              value: "4G"
            - name: FORGE_VERSION
              value: "14.23.5.2860"   # version Forge stable pour 1.12.2
            - name: REMOVE_OLD_MODS
              value: "false"           # ne pas supprimer les mods au redémarrage
            - name: ONLINE_MODE
              value: "true"
          ports:
            - containerPort: 25565
          resources:
            requests:
              memory: "4.5Gi"
              cpu: "1000m"
            limits:
              memory: "6Gi"
              cpu: "4000m"
          volumeMounts:
            - name: storage-volume
              mountPath: /data
      volumes:
      - name: storage-volume
        persistentVolumeClaim:
          claimName: minecraft-srv-01-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: minecraft-01
  namespace: minecraft
  labels:
    expose: "true"
  annotations:
    lbipam.cilium.io/ips: "192.168.1.3"
spec:
  type: LoadBalancer
  selector:
    app: minecraft-01
  ports:
    - port: 25565
      targetPort: 25565
EOF

Factorio

Création du Namespace et du label : 

kubectl create namespace factorio

Création du PVC : 

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: factorio-srv-01-pvc
  namespace: factorio
spec:
  accessModes:
    - ReadWriteOnce
  storageClassName: longhorn
  resources:
    requests:
      storage: 10Gi
EOF

Déployment  + Service :

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
  name: factorio-mod-list
  namespace: factorio
data:
  mod-list.json: |
    {
      "mods": [
        {
          "name": "base",
          "enabled": true
        }
      ]
    }
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: factorio-01
  namespace: factorio
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: factorio-01
  template:
    metadata:
      labels:
        app: factorio-01
    spec:
      securityContext:
        runAsUser: 845
        runAsGroup: 845
        fsGroup: 845
      containers:
        - name: factorio-01
          image: factoriotools/factorio:latest-rootless
          ports:
            - containerPort: 34197
              protocol: UDP
          env:
            - name: UPDATE_MODS_ON_START
              value: "false"
            - name: DLC_SPACE_AGE
              value: "false"

          volumeMounts:
            - name: storage-volume
              mountPath: /factorio
            - name: mod-list
              mountPath: /factorio/config/mod-list.json
              subPath: mod-list.json
      volumes:
      - name: storage-volume
        persistentVolumeClaim:
          claimName: factorio-srv-01-pvc
      - name: mod-list
        configMap:
          name: factorio-mod-list
---
apiVersion: v1
kind: Service
metadata:
  name: factorio-01
  namespace: factorio
  labels:
    expose: "true"
  annotations:
    lbipam.cilium.io/ips: "10.0.20.2"
spec:
  type: LoadBalancer
  selector:
    app: factorio-01
  ports:
    - port: 34197
      targetPort: 34197
      protocol: UDP
EOF