Chrome Cluster on K8s: Memory Config, /dev/shm, and Graceful Shutdown

200-500MB per instance, /dev/shm requirements, WebSocket long connections, graceful shutdown — K8s native resource management breaks for browser instances.

16Yun Engineering TeamApr 28, 20261 min read

Browsers vs Normal Services

Difference 1: Uneven Memory

resources:
  requests:
    memory: "512Mi"
    cpu: "500m"
  limits:
    memory: "1Gi"
    cpu: "1000m"

A blank page: 150MB. A complex SPA: 500MB+. Same instance, different tasks — 3x memory variance.

Difference 2: /dev/shm

Chrome needs shared memory for inter-process communication. Default /dev/shm is 64MB. Chrome often needs 256MB-512MB:

volumes:
- name: dshm
  emptyDir:
    medium: Memory
    sizeLimit: "512Mi"

Difference 3: Process Cleanup

spec:
  terminationGracePeriodSeconds: 60
  containers:
  - name: chrome
    lifecycle:
      preStop:
        exec:
          command:
          - /bin/sh
          - -c
          - |
            curl -s -X PUT http://localhost:9222/json/close 2>/dev/null || true
            pkill -f "chrome" || true

Resource Configuration

Task TypeMemory RequestMemory LimitNotes
Simple page256Mi512MiStatic pages
Medium SPA512Mi1GiReact/Vue
Complex SPA1Gi2GiHeavy JS
Multi-tab2Gi4GiShared browser

HPA Configuration

Use queue depth, not CPU:

triggers:
- type: rabbitmq
  metadata:
    queueName: browser-tasks
    queueLength: "5"

Node Selection

Use memory-optimized instances (AWS r6i series). Don't mix browser Pods with other services on the same Node.

Summary

Key points for browser clusters on K8s:

  1. /dev/shm must be explicitly sized
  2. Memory requests/limits depend on task type
  3. Graceful shutdown needs extended terminationGracePeriodSeconds + preStop hook
  4. HPA should use queue depth, not CPU/memory
  5. Node isolation — separate browser Pods from other services

Need an enterprise proxy plan?

We can tailor architecture to your target domains, concurrency, and reliability goals.