All posts

Fix Kubernetes Pod Crash in Java

Resolve Java application pod crashes in Kubernetes caused by JVM heap sizing, slow startup, and misconfigured health probes.

Java Pods Crashing in Kubernetes

Java apps in Kubernetes have a reputation for being tricky. The JVM's memory model doesn't naturally align with container limits, and slow startup can trigger premature liveness probe failures.

JVM Doesn't Respect Container Memory

Older JVMs ignore cgroup limits. Use these flags:

ENV JAVA_OPTS="-XX:+UseContainerSupport -XX:MaxRAMPercentage=75.0"
CMD java $JAVA_OPTS -jar app.jar

This tells the JVM to use at most 75% of the container's memory limit, leaving room for native memory, threads, and buffers.

Slow Startup Kills

Spring Boot apps can take 30+ seconds to start. If your liveness probe fires too early:

startupProbe:
  httpGet:
    path: /actuator/health
    port: 8080
  failureThreshold: 30
  periodSeconds: 2
livenessProbe:
  httpGet:
    path: /actuator/health/liveness
    port: 8080
  initialDelaySeconds: 0
  periodSeconds: 10

The startupProbe gives the app up to 60 seconds to start before the livenessProbe takes over.

Thread Pool Exhaustion

Too many concurrent requests with a small thread pool causes cascading failures:

# application.yml
server:
  tomcat:
    threads:
      max: 200
      min-spare: 20
    accept-count: 100

Proper Resource Limits

resources:
  limits:
    memory: "1Gi"
    cpu: "1000m"
  requests:
    memory: "512Mi"
    cpu: "500m"

Bugsly's Java SDK captures OutOfMemoryError and unhandled exceptions with thread dumps, giving you the full picture when a pod goes down.

Try Bugsly Free

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

Get Started Free