apiVersion: v1
kind: ConfigMap
metadata:
  name: tankwar-server-config
data:
  NODE_ENV: "production"
  PORT: "3000"
  HOST: "0.0.0.0"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tankwar-server
  labels:
    app: tankwar-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tankwar-server
  template:
    metadata:
      labels:
        app: tankwar-server
    spec:
      containers:
      - name: tankwar-server
        image: tankwar-server:latest
        ports:
        - containerPort: 3000
        envFrom:
        - configMapRef:
            name: tankwar-server-config
        resources:
          requests:
            memory: "256Mi"
            cpu: "250m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 30
          periodSeconds: 10
        readinessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 5
          periodSeconds: 5
---
apiVersion: v1
kind: Namespace
metadata:
  name: tankwar
  labels:
    app.kubernetes.io/part-of: tankwar
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: tankwar-server-config
  namespace: tankwar
data:
  NODE_ENV: "production"
  PORT: "3000"
  HOST: "0.0.0.0"
  # WebSocket path must match Nginx location and client SERVER_URL
  WS_PATH: "/tankwar/ws"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: tankwar-server
  namespace: tankwar
  labels:
    app: tankwar-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: tankwar-server
  template:
    metadata:
      labels:
        app: tankwar-server
    spec:
      containers:
      - name: tankwar-server
        image: tankwar/tankwar-server:latest
        imagePullPolicy: Never
        ports:
        - containerPort: 3000
          name: http-ws
        envFrom:
        - configMapRef:
            name: tankwar-server-config
        resources:
          requests:
            memory: "128Mi"
            cpu: "100m"
          limits:
            memory: "512Mi"
            cpu: "500m"
        livenessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 15
          periodSeconds: 20
        readinessProbe:
          httpGet:
            path: /health
            port: 3000
          initialDelaySeconds: 5
          periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
  name: tankwar-server
  namespace: tankwar
  labels:
    app: tankwar-server
spec:
  # ClusterIP: only exposed internally, external traffic comes through
  # warmcheck-namespace Nginx at game.igeek.site -> /tankwar/ws
  type: ClusterIP
  selector:
    app: tankwar-server
  ports:
  - name: http-ws
    port: 3000
    targetPort: 3000
    protocol: TCP
  type: LoadBalancer