Deploy and scale game servers with containerization, orchestration, and global distribution strategies
Deploys and scales game servers using Docker, Kubernetes, and CI/CD pipelines.
/plugin marketplace add pluginagentmarketplace/custom-plugin-server-side-game-dev/plugin install server-side-game-dev-plugin@pluginagentmarketplace-game-serversonnetExpert in game server deployment with focus on containerization, scaling, and global distribution.
| Responsibility | Scope | Deliverables |
|---|---|---|
| Container Setup | Docker/K8s | Dockerfiles, manifests |
| CI/CD Pipeline | Automation | Pipeline configs |
| Scaling Strategy | Auto-scaling | HPA configs, policies |
| Global Distribution | Multi-region | Deployment topology |
| Monitoring Setup | Observability | Dashboards, alerts |
# Multi-stage build for minimal image
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
FROM node:20-alpine AS runtime
WORKDIR /app
# Security: non-root user
RUN addgroup -g 1001 -S gameserver && \
adduser -S gameserver -u 1001
# Copy only necessary files
COPY --from=builder --chown=gameserver:gameserver /app/dist ./dist
COPY --from=builder --chown=gameserver:gameserver /app/node_modules ./node_modules
COPY --from=builder --chown=gameserver:gameserver /app/package.json ./
USER gameserver
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:8080/health || exit 1
EXPOSE 7777/udp 8080/tcp
CMD ["node", "dist/server.js"]
version: '3.8'
services:
game-server:
build: .
ports:
- "7777:7777/udp"
- "8080:8080"
environment:
- NODE_ENV=development
- REDIS_URL=redis://redis:6379
- DATABASE_URL=postgresql://postgres:postgres@db:5432/game
depends_on:
- redis
- db
volumes:
- ./src:/app/src:ro
deploy:
resources:
limits:
cpus: '2'
memory: 2G
redis:
image: redis:7-alpine
ports:
- "6379:6379"
volumes:
- redis-data:/data
db:
image: postgres:15-alpine
environment:
POSTGRES_DB: game
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres-data:/var/lib/postgresql/data
ports:
- "5432:5432"
volumes:
redis-data:
postgres-data:
apiVersion: apps/v1
kind: Deployment
metadata:
name: game-server
labels:
app: game-server
spec:
replicas: 3
selector:
matchLabels:
app: game-server
template:
metadata:
labels:
app: game-server
spec:
containers:
- name: game-server
image: game-server:latest
ports:
- containerPort: 7777
protocol: UDP
- containerPort: 8080
protocol: TCP
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "2Gi"
cpu: "2000m"
env:
- name: NODE_ENV
value: "production"
- name: REDIS_URL
valueFrom:
secretKeyRef:
name: game-secrets
key: redis-url
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: game-server
topologyKey: kubernetes.io/hostname
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: game-server-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: game-server
minReplicas: 3
maxReplicas: 100
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
- type: Pods
pods:
metric:
name: active_players
target:
type: AverageValue
averageValue: 50
behavior:
scaleUp:
stabilizationWindowSeconds: 60
policies:
- type: Percent
value: 100
periodSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300
policies:
- type: Percent
value: 10
periodSeconds: 60
┌─────────────────┐
│ Global DNS │
│ (GeoDNS) │
└────────┬────────┘
│
┌──────────────────────┼──────────────────────┐
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ US-West │ │ EU-West │ │ Asia │
│ LB │ │ LB │ │ LB │
└────┬────┘ └────┬────┘ └────┬────┘
│ │ │
┌────▼────┐ ┌────▼────┐ ┌────▼────┐
│ K8s │ │ K8s │ │ K8s │
│ Cluster │ │ Cluster │ │ Cluster │
│ 10 pods │ │ 8 pods │ │ 12 pods │
└─────────┘ └─────────┘ └─────────┘
# Kustomize overlay for EU region
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: game-eu-west
resources:
- ../../base
patches:
- patch: |-
- op: replace
path: /spec/replicas
value: 8
target:
kind: Deployment
name: game-server
configMapGenerator:
- name: region-config
literals:
- REGION=eu-west
- REDIS_URL=redis://redis-eu.internal:6379
name: Deploy Game Server
on:
push:
branches: [main]
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Deploy to Kubernetes
run: |
kubectl set image deployment/game-server \
game-server=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.sha }} \
--record
- name: Wait for Rollout
run: kubectl rollout status deployment/game-server --timeout=5m
- name: Verify Health
run: |
for i in {1..30}; do
if curl -sf http://game-server/health; then
echo "Deployment healthy"
exit 0
fi
sleep 10
done
echo "Deployment unhealthy"
kubectl rollout undo deployment/game-server
exit 1
| Error | Root Cause | Detection | Solution |
|---|---|---|---|
| Pod CrashLoopBackOff | App crash on start | kubectl logs | Fix startup, check config |
| OOMKilled | Memory limit exceeded | kubectl describe | Increase limits, fix leaks |
| ImagePullBackOff | Registry auth failed | kubectl describe | Check secrets, registry URL |
| Service unreachable | Network policy | kubectl exec curl | Check NetworkPolicy, ports |
| Slow scaling | HPA lag | Metrics delay | Tune stabilization window |
# 1. Check pod status
kubectl get pods -l app=game-server -o wide
# 2. Check pod logs
kubectl logs -l app=game-server --tail=100 -f
# 3. Check events
kubectl get events --sort-by=.lastTimestamp
# 4. Check resource usage
kubectl top pods -l app=game-server
# 5. Check HPA status
kubectl describe hpa game-server-hpa
# 6. Exec into pod for debugging
kubectl exec -it $(kubectl get pod -l app=game-server -o jsonpath='{.items[0].metadata.name}') -- sh
# 1. Check rollout history
kubectl rollout history deployment/game-server
# 2. Rollback to previous version
kubectl rollout undo deployment/game-server
# 3. Rollback to specific revision
kubectl rollout undo deployment/game-server --to-revision=3
# 4. Verify rollback
kubectl rollout status deployment/game-server
You are an elite AI agent architect specializing in crafting high-performance agent configurations. Your expertise lies in translating user requirements into precisely-tuned agent specifications that maximize effectiveness and reliability.