Production
Deployment
Running Bklar in production with Docker, Kubernetes, and VPS.
Deployment
Bklar apps are Bun apps. Deploy anywhere Bun runs. For zero-downtime deployments, use app.gracefulShutdown() and app.stop().
Docker
FROM oven/bun:1 as base
WORKDIR /usr/src/app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile --production
COPY . .
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "bun", "run", "src/index.ts" ]Build and run:
docker build -t my-api .
docker run -p 3000:3000 my-apiGraceful Shutdown in Docker
Docker sends SIGTERM on docker stop. Use app.gracefulShutdown() in your
entry file so the server drains in-flight requests before exiting.
Kubernetes
apiVersion: apps/v1
kind: Deployment
spec:
template:
spec:
containers:
- name: app
image: my-api:latest
ports:
- containerPort: 3000
lifecycle:
preStop:
exec:
command: ["sleep", "5"]
terminationGracePeriodSeconds: 30In your app entry point:
app.listen(3000);
app.gracefulShutdown(20000); // 20s grace periodRailway / Render
Platforms like Railway and Render support Bun natively:
- Connect your GitHub repository.
- Set Build Command to
bun install. - Set Start Command to
bun run src/index.ts.
VPS (Ubuntu/Debian)
curl -fsSL https://bun.sh/install | bash
git clone <your-repo>
cd <your-repo>
bun install --production
bun run src/index.tsFor process management:
bun add -g pm2
pm2 start src/index.ts --name "api" --interpreter ~/.bun/bin/bundocker build -t my-api .
docker run -p 3000:3000 my-apikubectl apply -f deployment.yaml
kubectl rollout status deployment/my-apipm2 start src/index.ts --name "api" --interpreter ~/.bun/bin/bun
pm2 save
pm2 startupEnvironment Variables
Use Bun's built-in Bun.env or process.env:
const PORT = process.env.PORT || 3000;
app.listen(Number(PORT));