Deploying a Next.js Standalone App on OpenShift
Deploying a Next.js Standalone App on OpenShift
This is Part 3 of the series: Self-Hosting Next.js in Kubernetes (Without Vercel).
In the previous posts, we:
- Built a Next.js app in standalone mode
- Created a minimal, production-ready Docker image
Now we’ll deploy that image into OpenShift using standard Kubernetes resources: Deployment, Service, and Route.
Assumptions
This guide assumes:
- Your image is already built and pushed to an internal registry
- The container listens on
PORT=3000 - The app runs using Next.js standalone
server.js
1️⃣ Deployment
The Deployment runs the Next.js standalone server as a stateless container.
apiVersion: apps/v1
kind: Deployment
metadata:
name: example-nextjs
spec:
replicas: 2
selector:
matchLabels:
app: example-nextjs
template:
metadata:
labels:
app: example-nextjs
spec:
containers:
- name: web
image: image-registry.openshift-image-registry.svc:5000/internal/example-nextjs:latest
ports:
- containerPort: 3000
env:
- name: NODE_ENV
value: "production"
- name: PORT
value: "3000"
readinessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
httpGet:
path: /
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
Key points:
- No persistent storage required
- Stateless and horizontally scalable
- Probes use
/, which Next.js handles naturally
2️⃣ Service
The Service exposes the Deployment internally inside the cluster.
apiVersion: v1
kind: Service
metadata:
name: example-nextjs
spec:
selector:
app: example-nextjs
ports:
- name: http
port: 80
targetPort: 3000
The Service:
- Maps port 80 → container port 3000
- Provides stable networking for the Route
3️⃣ Route (OpenShift)
OpenShift Routes expose the app externally.
apiVersion: route.openshift.io/v1
kind: Route
metadata:
name: example-nextjs
spec:
to:
kind: Service
name: example-nextjs
port:
targetPort: http
tls:
termination: edge
With this Route:
- TLS is terminated at the router
- No HTTPS configuration is required in the app
- The app runs as plain HTTP internally
Common OpenShift Gotchas
- Ensure the container runs as a non-root user
- Do not rely on writable root filesystem
- Do not bind to privileged ports (<1024)
The standalone Next.js setup fits OpenShift security constraints well when built correctly.
Series Progress
Self-Hosting Next.js in Kubernetes (Without Vercel)
- ✅ Part 1: Standalone Deployment
- ✅ Part 2: Minimal Docker Images
- ✅ Part 3: OpenShift Deployment
- ⏭ Part 4: Fixing Static Asset 404s
- ⏭ Part 5: Runtime Config & Secrets
- ⏭ Part 6: Health Checks & Scaling
Final Thoughts
Once you treat Next.js as a normal Node.js server, deployment becomes straightforward.
In the next post, we’ll deep-dive into one of the most common problems:
404 errors for _next/static in standalone deployments.
❤️ Support This Blog
If this post helped you, you can support my writing with a small donation. Thank you for reading.
Comments
Post a Comment