All posts

Fix Kubernetes Pod Crash with SvelteKit

Fix SvelteKit application crashes in Kubernetes including adapter configuration, SSR issues, and container networking problems.

SvelteKit Pods Crashing in Kubernetes

SvelteKit's adapter system determines how your app runs in production. Using the wrong adapter — or misconfiguring the Node adapter — leads to pod crashes.

Use the Right Adapter

For Kubernetes, you need @sveltejs/adapter-node:

// svelte.config.js
import adapter from '@sveltejs/adapter-node';

export default {
  kit: {
    adapter: adapter({
      out: 'build',
      precompress: false
    })
  }
};

Don't use adapter-auto or adapter-static for a containerized deployment that needs SSR.

Dockerfile

FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build

FROM node:20-alpine
WORKDIR /app
COPY --from=builder /app/build ./build
COPY --from=builder /app/package*.json ./
RUN npm ci --omit=dev
EXPOSE 3000
CMD ["node", "build"]

Host and Port Binding

SvelteKit's Node adapter respects HOST and PORT environment variables:

env:
  - name: HOST
    value: "0.0.0.0"
  - name: PORT
    value: "3000"
  - name: ORIGIN
    value: "https://myapp.example.com"

The ORIGIN variable is crucial — without it, form actions and CSRF protection break.

Health Check

Add a simple health route:

// src/routes/healthz/+server.ts
export function GET() {
  return new Response('ok');
}

Bugsly hooks into SvelteKit's error handling to capture both server-side and client-side errors, with route and request context attached to every event.

Try Bugsly Free

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

Get Started Free