From ffa01aa378796f909ce11977cbd909d6dcb55da0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 19 Nov 2026 19:08:40 -0700 Subject: [PATCH] add playmat to k3s --- apps/playmat/imgcache-configmap.yaml | 53 ++++++++++++ apps/playmat/imgcache-deployment.yaml | 82 ++++++++++++++++++ apps/playmat/imgcache-service.yaml | 12 +++ apps/playmat/ingress.yaml | 25 ++++++ apps/playmat/kustomization.yaml | 15 ++++ apps/playmat/namespace.yaml | 4 + apps/playmat/network-policy.yaml | 15 ++++ apps/playmat/pvc.yaml | 25 ++++++ apps/playmat/web-deployment.yaml | 64 ++++++++++++++ apps/playmat/web-service.yaml | 12 +++ apps/playmat/xmage-deployment.yaml | 116 ++++++++++++++++++++++++++ apps/playmat/xmage-service.yaml | 15 ++++ argocd/playmat.yaml | 20 +++++ 13 files changed, 458 insertions(+) create mode 100644 apps/playmat/imgcache-configmap.yaml create mode 100644 apps/playmat/imgcache-deployment.yaml create mode 100644 apps/playmat/imgcache-service.yaml create mode 100644 apps/playmat/ingress.yaml create mode 100644 apps/playmat/kustomization.yaml create mode 100644 apps/playmat/namespace.yaml create mode 100644 apps/playmat/network-policy.yaml create mode 100644 apps/playmat/pvc.yaml create mode 100644 apps/playmat/web-deployment.yaml create mode 100644 apps/playmat/web-service.yaml create mode 100644 apps/playmat/xmage-deployment.yaml create mode 100644 apps/playmat/xmage-service.yaml create mode 100644 argocd/playmat.yaml diff --git a/apps/playmat/imgcache-configmap.yaml b/apps/playmat/imgcache-configmap.yaml new file mode 100644 index 0000000..e048771 --- /dev/null +++ b/apps/playmat/imgcache-configmap.yaml @@ -0,0 +1,53 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: imgcache-config + namespace: playmat +data: + imgcache.conf.template: | + resolver kube-dns.kube-system.svc.cluster.local ipv6=off valid=300s; + resolver_timeout 5s; + proxy_cache_path /var/cache/nginx/scryfall/images levels=1:2 keys_zone=scryfall_images:50m max_size=${IMGCACHE_IMAGES_MAX_SIZE} inactive=365d use_temp_path=off; + proxy_cache_path /var/cache/nginx/scryfall/api levels=1:2 keys_zone=scryfall_api:20m max_size=${IMGCACHE_API_MAX_SIZE} inactive=365d use_temp_path=off; + limit_req_zone $server_port zone=scryfall_upstream:1m rate=${IMGCACHE_API_RATE}; + limit_req_status 429; + proxy_buffer_size 32k; + proxy_buffers 16 32k; + proxy_busy_buffers_size 64k; + server { + listen 8080; + server_name _; + location = /healthz { access_log off; default_type text/plain; return 200 "ok\n"; } + location ~ ^/img/(cards|backs)/ { + proxy_set_header Host $1.scryfall.io; + proxy_set_header User-Agent "PlaymatXMageImageCache/1.0 (+https://github.com/arcanite24/playmat)"; + proxy_set_header Accept "*/*"; + proxy_set_header Accept-Encoding ""; + proxy_ssl_server_name on; + proxy_ssl_verify ${IMGCACHE_UPSTREAM_TLS_VERIFY}; + proxy_cache scryfall_images; + proxy_cache_key $request_uri; + proxy_cache_valid 200 301 302 365d; + proxy_pass https://$1.scryfall.io$request_uri; + } + location = /img/api/cards/collection { + limit_except POST { deny all; } + proxy_pass https://api.scryfall.com/cards/collection; + proxy_set_header Host api.scryfall.com; + proxy_set_header User-Agent "PlaymatXMageImageCache/1.0 (+https://github.com/arcanite24/playmat)"; + proxy_cache scryfall_api; + proxy_cache_methods GET HEAD POST; + proxy_cache_key "$request_method$request_uri$request_body"; + proxy_cache_valid 200 24h; + } + location /img/api/ { + proxy_pass https://api.scryfall.com/; + proxy_set_header Host api.scryfall.com; + proxy_set_header User-Agent "PlaymatXMageImageCache/1.0 (+https://github.com/arcanite24/playmat)"; + proxy_ssl_server_name on; + proxy_cache scryfall_api; + proxy_cache_key $request_uri; + proxy_cache_valid 200 301 302 24h; + } + location / { return 404; } + } diff --git a/apps/playmat/imgcache-deployment.yaml b/apps/playmat/imgcache-deployment.yaml new file mode 100644 index 0000000..8331bf5 --- /dev/null +++ b/apps/playmat/imgcache-deployment.yaml @@ -0,0 +1,82 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: imgcache + namespace: playmat +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: imgcache + template: + metadata: + labels: + app: imgcache + spec: + securityContext: + seccompProfile: + type: RuntimeDefault + containers: + - name: imgcache + image: nginx:1.30.5-alpine + ports: + - name: http + containerPort: 8080 + env: + - name: IMGCACHE_IMAGES_MAX_SIZE + value: 4g + - name: IMGCACHE_API_MAX_SIZE + value: 512m + - name: IMGCACHE_API_RATE + value: 10r/s + - name: IMGCACHE_API_BURST + value: "20" + - name: IMGCACHE_CARDS_UPSTREAM + value: https://cards.scryfall.io + - name: IMGCACHE_BACKS_UPSTREAM + value: https://backs.scryfall.io + - name: IMGCACHE_API_UPSTREAM + value: https://api.scryfall.com + - name: IMGCACHE_FALLBACK + value: "off" + - name: IMGCACHE_UPSTREAM_TLS_VERIFY + value: "on" + volumeMounts: + - name: imgcache-data + mountPath: /var/cache/nginx/scryfall + - name: config + mountPath: /etc/nginx/templates/default.conf.template + subPath: imgcache.conf.template + readinessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 10 + periodSeconds: 10 + livenessProbe: + httpGet: + path: /healthz + port: http + initialDelaySeconds: 30 + periodSeconds: 30 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 50m + memory: 64Mi + limits: + cpu: 300m + memory: 256Mi + volumes: + - name: imgcache-data + persistentVolumeClaim: + claimName: imgcache-data + - name: config + configMap: + name: imgcache-config diff --git a/apps/playmat/imgcache-service.yaml b/apps/playmat/imgcache-service.yaml new file mode 100644 index 0000000..46ea332 --- /dev/null +++ b/apps/playmat/imgcache-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: imgcache + namespace: playmat +spec: + selector: + app: imgcache + ports: + - name: http + port: 8080 + targetPort: http diff --git a/apps/playmat/ingress.yaml b/apps/playmat/ingress.yaml new file mode 100644 index 0000000..0aeb807 --- /dev/null +++ b/apps/playmat/ingress.yaml @@ -0,0 +1,25 @@ +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: playmat + namespace: playmat + annotations: + cert-manager.io/cluster-issuer: letsencrypt-prod + traefik.ingress.kubernetes.io/router.entrypoints: websecure +spec: + ingressClassName: traefik + rules: + - host: playmat.aleshym.co + http: + paths: + - path: / + pathType: Prefix + backend: + service: + name: web + port: + name: http + tls: + - hosts: + - playmat.aleshym.co + secretName: playmat-tls diff --git a/apps/playmat/kustomization.yaml b/apps/playmat/kustomization.yaml new file mode 100644 index 0000000..1cf8106 --- /dev/null +++ b/apps/playmat/kustomization.yaml @@ -0,0 +1,15 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - namespace.yaml + - pvc.yaml + - imgcache-configmap.yaml + - xmage-deployment.yaml + - xmage-service.yaml + - imgcache-deployment.yaml + - imgcache-service.yaml + - web-deployment.yaml + - web-service.yaml + - ingress.yaml + - network-policy.yaml diff --git a/apps/playmat/namespace.yaml b/apps/playmat/namespace.yaml new file mode 100644 index 0000000..ac1d509 --- /dev/null +++ b/apps/playmat/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: playmat diff --git a/apps/playmat/network-policy.yaml b/apps/playmat/network-policy.yaml new file mode 100644 index 0000000..b6f1d0a --- /dev/null +++ b/apps/playmat/network-policy.yaml @@ -0,0 +1,15 @@ +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: allow-ingress-from-traefik-and-playmat + namespace: playmat +spec: + podSelector: {} + policyTypes: + - Ingress + ingress: + - from: + - namespaceSelector: + matchLabels: + kubernetes.io/metadata.name: kube-system + - podSelector: {} diff --git a/apps/playmat/pvc.yaml b/apps/playmat/pvc.yaml new file mode 100644 index 0000000..cf44cb6 --- /dev/null +++ b/apps/playmat/pvc.yaml @@ -0,0 +1,25 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: xmage-data + namespace: playmat +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-path + resources: + requests: + storage: 5Gi +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: imgcache-data + namespace: playmat +spec: + accessModes: + - ReadWriteOnce + storageClassName: local-path + resources: + requests: + storage: 5Gi diff --git a/apps/playmat/web-deployment.yaml b/apps/playmat/web-deployment.yaml new file mode 100644 index 0000000..059ce4b --- /dev/null +++ b/apps/playmat/web-deployment.yaml @@ -0,0 +1,64 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: web + namespace: playmat +spec: + replicas: 1 + selector: + matchLabels: + app: web + template: + metadata: + labels: + app: web + spec: + securityContext: + seccompProfile: + type: RuntimeDefault + containers: + - name: web + image: ghcr.io/arcanite24/playmat-web:master + imagePullPolicy: Always + ports: + - name: http + containerPort: 80 + env: + - name: DOMAIN + value: playmat.aleshym.co + - name: TLS_MODE + value: external + - name: UPSTREAM_PROXIES + value: 10.42.0.0/16 + - name: XMAGE_GATEWAY + value: off + - name: XMAGE_ALLOWED_ORIGINS + value: https://playmat.aleshym.co + - name: XMAGE_PUBLIC_URL + value: https://playmat.aleshym.co + - name: CADDY_IP + value: 127.0.0.1 + readinessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 10 + periodSeconds: 10 + livenessProbe: + httpGet: + path: / + port: http + initialDelaySeconds: 30 + periodSeconds: 30 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 500m + memory: 256Mi diff --git a/apps/playmat/web-service.yaml b/apps/playmat/web-service.yaml new file mode 100644 index 0000000..d5897b3 --- /dev/null +++ b/apps/playmat/web-service.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Service +metadata: + name: web + namespace: playmat +spec: + selector: + app: web + ports: + - name: http + port: 80 + targetPort: http diff --git a/apps/playmat/xmage-deployment.yaml b/apps/playmat/xmage-deployment.yaml new file mode 100644 index 0000000..935432f --- /dev/null +++ b/apps/playmat/xmage-deployment.yaml @@ -0,0 +1,116 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: xmage + namespace: playmat +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: xmage + template: + metadata: + labels: + app: xmage + spec: + securityContext: + seccompProfile: + type: RuntimeDefault + initContainers: + - name: prepare-data + image: busybox:1.37 + command: + - sh + - -c + - mkdir -p /data/db /data/cards-db /data/logs /data/saved /data/updates + volumeMounts: + - name: xmage-data + mountPath: /data + containers: + - name: xmage + image: ghcr.io/arcanite24/playmat-server:master + imagePullPolicy: Always + ports: + - name: bridge + containerPort: 17172 + - name: health + containerPort: 17173 + env: + - name: XMAGE_ALLOWED_ORIGINS + value: https://playmat.aleshym.co + - name: XMAGE_PUBLIC_URL + value: https://playmat.aleshym.co + - name: XMAGE_SERVER_NAME + value: playmat + - name: XMAGE_TRUSTED_PROXIES + value: 10.42.0.0/16 + - name: XMAGE_AUTH + value: "false" + - name: XMAGE_ACCESS + value: open + - name: XMAGE_CAREER + value: "on" + - name: XMAGE_SAVE_GAMES + value: "false" + - name: XMAGE_REPLAYS + value: "true" + - name: XMAGE_UPDATE_CHECK + value: "off" + - name: XMAGE_MEMORY + value: 768m + - name: XMAGE_MAX_GAME_THREADS + value: "2" + - name: XMAGE_MAX_AI_OPPONENTS + value: "2" + - name: XMAGE_GATEWAY + value: off + - name: XMAGE_AI_BACKEND + value: java + volumeMounts: + - name: xmage-data + mountPath: /opt/xmage/db + subPath: db + - name: xmage-data + mountPath: /opt/xmage/cards-db + subPath: cards-db + - name: xmage-data + mountPath: /opt/xmage/logs + subPath: logs + - name: xmage-data + mountPath: /opt/xmage/saved + subPath: saved + - name: xmage-data + mountPath: /opt/xmage/updates + subPath: updates + startupProbe: + tcpSocket: + port: health + periodSeconds: 15 + failureThreshold: 60 + readinessProbe: + tcpSocket: + port: bridge + periodSeconds: 10 + livenessProbe: + tcpSocket: + port: bridge + initialDelaySeconds: 120 + periodSeconds: 30 + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + resources: + requests: + cpu: 500m + memory: 1Gi + limits: + cpu: 1500m + memory: 2Gi + volumes: + - name: xmage-data + persistentVolumeClaim: + claimName: xmage-data diff --git a/apps/playmat/xmage-service.yaml b/apps/playmat/xmage-service.yaml new file mode 100644 index 0000000..92c268a --- /dev/null +++ b/apps/playmat/xmage-service.yaml @@ -0,0 +1,15 @@ +apiVersion: v1 +kind: Service +metadata: + name: xmage + namespace: playmat +spec: + selector: + app: xmage + ports: + - name: bridge + port: 17172 + targetPort: bridge + - name: health + port: 17173 + targetPort: health diff --git a/argocd/playmat.yaml b/argocd/playmat.yaml new file mode 100644 index 0000000..a17df9b --- /dev/null +++ b/argocd/playmat.yaml @@ -0,0 +1,20 @@ +apiVersion: argoproj.io/v1alpha1 +kind: Application +metadata: + name: playmat + namespace: argocd +spec: + project: default + source: + repoURL: https://git.aleshym.co/funman300/k3s-homelab.git + targetRevision: main + path: apps/playmat + destination: + server: https://kubernetes.default.svc + namespace: playmat + syncPolicy: + automated: + prune: true + selfHeal: true + syncOptions: + - CreateNamespace=true