Kubernetes pod in crashloopbackoff

7/7/2020

I am new to Kubernetes.

Following is the yaml I am running:

---
apiVersion: v1
kind: Service
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  ports:
  - name: http
    port: 80
    targetPort: 80
  selector:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: k8-demo-aishwarya
      app.kubernetes.io/version: version1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: k8-demo-aishwarya
        app.kubernetes.io/version: version1
    spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT
        imagePullPolicy: IfNotPresent
        name: k8-demo-aishwarya
        ports:
        - containerPort: 80
          name: http
          protocol: TCP

Getting a crashloopbackoff error

Can anyone guide me?

No issue with the image, it runs properly, I have tested that on Docker.

Kubernetes pod logs are as follows:

1. Successfully assigned default/k8-demo-aishwarya-fdd8d58c6-lvxp9 to gke-cluster-3-pool-1-997819b9-j3b2
2. Container image "docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT" already present on machine
3. Created container k8-demo-aishwarya
4. Started container k8-demo-aishwarya
5. Back-off restarting failed container
-- Aishvarya Suryawanshi
crashloopbackoff
deployment
docker
kubernetes
service

2 Answers

7/8/2020

Please check the logs of POD for more details however i think it's due to processing is ending inside container and printing Hello World by Aishwarya S! you can check same by logs.

You can keep running pod by adding line in your YAML :

command: ["/bin/sh", "-ec", "sleep 1000"]

This command keep pod running

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app.kubernetes.io/name: k8-demo-aishwarya
    app.kubernetes.io/version: version1
  name: k8-demo-aishwarya
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: k8-demo-aishwarya
      app.kubernetes.io/version: version1
  template:
    metadata:
      labels:
        app.kubernetes.io/name: k8-demo-aishwarya
        app.kubernetes.io/version: version1
    spec:
      containers:
      - env:
        - name: KUBERNETES_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        image: docker.io/aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT
        command: ["/bin/sh", "-ec", "sleep 1000"]
        imagePullPolicy: IfNotPresent
        name: k8-demo-aishwarya
        ports:
        - containerPort: 80
          name: http
          protocol: TCP
-- Harsh Manvar
Source: StackOverflow

7/8/2020

The container is running and is printing the hello world message and exiting. See below the logs from container.

$ docker ps -a
CONTAINER ID        IMAGE                                                         COMMAND                  CREATED             STATUS                      PORTS               NAMES
2b177abdbae1        aishvaryaps/spring-boot-on-kubernetes-example:0.12-SNAPSHOT   "/bin/sh -c 'java ${…"   12 seconds ago      Exited (0) 10 seconds ago                       dummy


$ docker logs -f 2b1
Hello World by Aishwarya S!

If you want to keep the container running, the process inside the container should continue to run. You might need to print the message from a while or for loop.

-- P Ekambaram
Source: StackOverflow