Deploy Guide · TypeScript / JavaScript

Deploy a Next.js App

Deploy Next.js with SSR and API routes — no Vercel lock-in.

Overview

Next.js is the dominant React framework for building full-stack web applications. While Vercel is the obvious host, running Next.js on Kubeletto gives you a portable, self-contained container with the same features — SSR, API routes, image optimization — without vendor lock-in.

Prerequisites

  • A Next.js 13+ project with App Router or Pages Router
  • next.config.js with output: "standalone" for optimal container size
  • A Kubeletto account

Step-by-Step Guide

Deploying Next.js to Kubeletto is done by configuring a Dockerfile, connecting your GitHub repository, and setting environment variables. Follow this step-by-step checklist to deploy your code:

  1. 1

    Enable standalone output in next.config.js

    Standalone mode traces only the files Next.js actually uses, reducing image size by 80%.

    javascript
    /** @type {import('next').NextConfig} */
    const nextConfig = {
      output: 'standalone',
    };
    module.exports = nextConfig;
  2. 2

    Create a production Dockerfile

    Use the official Next.js Docker example as your base.

    dockerfile
    FROM node:20-alpine AS deps
    WORKDIR /app
    COPY package*.json ./
    RUN npm ci
    
    FROM node:20-alpine AS builder
    WORKDIR /app
    COPY --from=deps /app/node_modules ./node_modules
    COPY . .
    RUN npm run build
    
    FROM node:20-alpine AS runner
    WORKDIR /app
    ENV NODE_ENV=production
    COPY --from=builder /app/public ./public
    COPY --from=builder /app/.next/standalone ./
    COPY --from=builder /app/.next/static ./.next/static
    EXPOSE 3000
    CMD ["node", "server.js"]
  3. 3

    Deploy via GitHub

    Connect your repo and every push to main triggers a build and deploy.

    bash
    kubeletto deploy --source github --repo your-org/nextjs-app --branch main
  4. 4

    Set Next.js environment variables

    Add NEXTAUTH_URL, DATABASE_URL, and other runtime variables.

    bash
    kubeletto env set NEXTAUTH_URL=https://nextjs-app.kubeletto.app --app nextjs-app
    kubeletto env set DATABASE_URL=postgres://... --app nextjs-app
    kubeletto env set NEXTAUTH_SECRET=your-secret --app nextjs-app

Sample Environment Variables

To configure your Next.js application, set these key-value pairs in the environment variables tab of the Kubeletto console or CLI. Ensure production secrets are flagged as write-only:

.env
NEXTAUTH_URL=https://nextjs-app.kubeletto.app
NEXTAUTH_SECRET=your-secret
DATABASE_URL=postgres://user:pass@host:5432/dbname
NEXT_PUBLIC_API_URL=https://nextjs-app.kubeletto.app

Related Kubeletto Features

Kubeletto offers automatic SSL certificate provisioning, zero-downtime rollbacks, and scale-to-zero autoscaling for Next.js container workloads:

PaaS Platform Comparisons

See how Kubeletto compares directly against other cloud platforms and PaaS providers when deploying TypeScript / JavaScript workloads:

Frequently Asked Questions

Find direct answers to common questions about hosting, building, scaling, and managing Next.js containerized apps on Kubeletto:

Can I use Next.js Image Optimization on Kubeletto?

Yes. Next.js image optimization runs inside your container. For best performance, configure an external image CDN (Cloudflare Images, Imgix) and set remotePatterns in next.config.js.

Do Next.js API routes work on Kubeletto?

Yes. API routes are standard Node.js HTTP handlers inside the container — they work identically to any other Node.js API.

Does Kubeletto scale to zero affect Next.js cold starts?

Scale-to-zero is configurable. For user-facing Next.js apps, set min-scale to 1 to avoid any cold start latency. For preview deployments, leave it at zero to save costs.

Deploy your Next.js app today

Free during our active beta. No credit card required.

Start Deploying Free