3
votes

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.

6

6 Answers

2
votes

You need to use

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

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

1
votes

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

0
votes

You deployment resource looks ok. As you are able to create the container manually using, problem is with the connection to the image repository. Setup the impage pull secret and you should be able to create the pod

0
votes

I faced similar issue. Just verify if your container is able to run continuously. You have to run the process in foreground to keep container running.

0
votes

The possible reasons of such error are:

  • the application inside your pod is not starting due to an error;
  • the image your pod is based on is not present in the registry, or the node where your pod has been scheduled cannot pull from the registry;
  • some parameters of the pod has not been configured correctly

You can view what is happening by checking the events:

kubectl get events

or checking pod status:

kubectl describe po mypod-390jo50wn3-sp40r

Full explanation here: https://pillsfromtheweb.blogspot.com/2020/05/troubleshooting-kubernetes.html

-1
votes

I had the same problem, but using this worked for me:

image: Image:latest

command: [ "sleep" ]

args: [ "infinity" ]