Kubernetes Pod Crashes Serving Flutter Apps
While Flutter is primarily a client-side framework, it's common to containerize Flutter web builds behind an Nginx server or run Dart backends with dart_frog or shelf. When these pods crash, here's how to fix them.
Flutter Web + Nginx: 403 Forbidden
The build output must be copied to the right Nginx directory:
# Build stage
FROM ghcr.io/cirruslabs/flutter:stable AS build
WORKDIR /app
COPY . .
RUN flutter build web --release
# Serve stage
FROM nginx:alpine
COPY --from=build /app/build/web /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
EXPOSE 80Make sure nginx.conf handles SPA routing:
server {
listen 80;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}Dart Backend Crashes
For Dart server applications, common pod crash causes include:
// Binding to localhost won't work in K8s
// Wrong:
final server = await shelf_io.serve(handler, 'localhost', 8080);
// Right:
final server = await shelf_io.serve(handler, '0.0.0.0', 8080);Health Checks
Add a health endpoint to prevent liveness probe failures:
Router()
..get('/healthz', (Request req) => Response.ok('ok'))
..get('/api/data', handleData);Bugsly's lightweight Dart integration captures unhandled exceptions from your server process, so crashed pods leave a clear error trail for post-mortem debugging.
Try Bugsly Free
AI-powered error tracking that explains your bugs. Set up in 2 minutes, free forever for small projects.
Get Started FreeRelated Articles
Fix CORS Blocked Error in Nuxt
Learn how to fix the CORS Blocked error in Nuxt. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreFix CORS Blocked Error in Rust
Learn how to fix the CORS Blocked error in Rust. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreFix CI/CD Pipeline Error in Swift
Learn how to fix the CI/CD Pipeline error in Swift. Step-by-step guide with code examples and solutions. Quick, practical guide for developers.
Read moreHow to Fix Type Mismatch in FastAPI
Learn how to diagnose and fix Type Mismatch errors in FastAPI. Step-by-step guide with code examples.
Read more