All posts

Fix Kubernetes Pod Crash in Nuxt

Debug Nuxt.js application crashes in Kubernetes pods, covering SSR memory leaks, Nitro server configuration, and health checks.

Nuxt Pods in CrashLoopBackOff

Nuxt 3 runs on Nitro, a server engine that can be deployed to Kubernetes. When pods crash, it's usually SSR memory leaks, missing environment variables, or probe misconfiguration.

SSR Memory Leaks

Server-side rendering in Nuxt can leak memory if components store state globally:

// BAD — shared state across requests
const cache = new Map();

export default defineEventHandler(() => {
  cache.set(Date.now(), largeObject); // Never cleaned up
});

Fix by using Nuxt's built-in caching or scoping state per request:

export default defineEventHandler((event) => {
  const cache = useStorage('cache');
  // Storage is managed, not a memory leak
});

Environment Variable Configuration

Nuxt reads runtime config from environment variables, but they must be prefixed correctly:

# deployment.yaml
env:
  - name: NUXT_PUBLIC_API_BASE
    value: "https://api.example.com"
  - name: NUXT_SECRET_KEY
    value: "my-secret"
// nuxt.config.ts
export default defineNuxtConfig({
  runtimeConfig: {
    secretKey: '',
    public: {
      apiBase: ''
    }
  }
});

Health Endpoint

Add a server route for Kubernetes probes:

// server/api/health.get.ts
export default defineEventHandler(() => ({ status: 'ok' }));
livenessProbe:
  httpGet:
    path: /api/health
    port: 3000
  initialDelaySeconds: 10

Bugsly integrates seamlessly with Nuxt — install the module and all server-side errors are captured automatically with request context.

Try Bugsly Free

AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.

Get Started Free