Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes Pod stuck in CrashLoopBackOff

Dockerfile

FROM ubuntu
MAINTAINER [email protected]
RUN apt-get update
RUN apt-get install -y openjdk-8-jdk
ADD build/libs/micro-service-gradle-0.0.1-SNAPSHOT.jar /var/local/
ENTRYPOINT exec java $JAVA_OPTS \
 -jar /var/local/micro-service-gradle-0.0.1-SNAPSHOT.jar
EXPOSE 8080

deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: micro-service-gradle
  labels:
    app: micro-service-gradle
spec:
  replicas: 1
  selector:
    matchLabels:
      app: micro-service-gradle
  template:
    metadata:
      labels:
        app: micro-service-gradle
    spec:
      containers:
      - name: micro-service-gradle
        image: micro-service-gradle:latest
        ports:
        - containerPort: 8080

Deploying spring boot application in Kubernetes . Pod is not getting created. When i check kubectl get pods. it says CrashLoopBackOff.

NAME                                  READY   STATUS             RESTARTS   AGE
micro-service-gradle-fc97c97b-8hwhg   0/1     CrashLoopBackOff   6          6m23s

I tried to check logs for the same container. Logs are empty

kubectl logs -p micro-service-gradle-fc97c97b-8hwhg

I created the container manually using docker run. There is no issues in image and containers works fine.

How to verify the logs for why the pods in crash status.

like image 868
VijayaKumar Thangavel Avatar asked Dec 31 '25 21:12

VijayaKumar Thangavel


2 Answers

You need to use

kubectl describe pod micro-service-gradle-fc97c97b-8hwhg

to get the relevant logs. This should guide you to your problem.

like image 62
Michael Altenburger Avatar answered Jan 03 '26 23:01

Michael Altenburger


I ran into a similar issue. When I run

kubectl describe pod <podname>

and read the events, Though the image was pulled, message outputted was 'restarting failed container' The pod was crashing because it was not performing any task. To keep it running, I add a sleep command based on similar example in the docs

  command: ['sh', '-c', 'echo The app is running! && sleep 3600']

This SO answer also mentions running an infinite could also solve the problem https://stackoverflow.com/a/55610769/7128032

like image 36
Jida Avatar answered Jan 03 '26 23:01

Jida



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!