Home > Software engineering >  CrashLoopBackOff : Back-off restarting failed container for flask application
CrashLoopBackOff : Back-off restarting failed container for flask application

Time:05-20

I am a beginner in kubernetes and was trying to deploy my flask application following this guide: https://medium.com/analytics-vidhya/build-a-python-flask-app-and-deploy-with-kubernetes-ccc99bbec5dc

I have successfully built a docker image and pushed it to dockerhub https://hub.docker.com/repository/docker/beatrix1997/kubernetes_flask_app

but am having trouble debugging a pod. This is my yaml file:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kubernetesflaskapp-deploy
  labels:
    app: kubernetesflaskapp
spec:
  replicas: 1
  selector:
    matchLabels:
      app: kubernetesflaskapp
  template:
    metadata:
      labels:
        app: kubernetesflaskapp
    spec:
      containers:
      - name: kubernetesflaskapp
        image: beatrix1997/kubernetes_flask_app
        ports:
        - containerPort: 5000

And this is the description of the pod:

Name:         kubernetesflaskapp-deploy-5764bbbd44-8696k
Namespace:    default
Priority:     0
Node:         minikube/192.168.49.2
Start Time:   Fri, 20 May 2022 11:26:33  0100
Labels:       app=kubernetesflaskapp
              pod-template-hash=5764bbbd44
Annotations:  <none>
Status:       Running
IP:           172.17.0.12
IPs:
  IP:           172.17.0.12
Controlled By:  ReplicaSet/kubernetesflaskapp-deploy-5764bbbd44
Containers:
  kubernetesflaskapp:
    Container ID:   docker://d500dc15e389190670a9273fea1d70e6bd6ab2e7053bd2480d114ad6150830f1
    Image:          beatrix1997/kubernetes_flask_app
    Image ID:       docker-pullable://beatrix1997/kubernetes_flask_app@sha256:1bfa98229f55b04f32a6b85d72860886abcc0f17295b14e173151a8e4b0f0334
    Port:           5000/TCP
    Host Port:      0/TCP
    State:          Waiting
      Reason:       CrashLoopBackOff
    Last State:     Terminated
      Reason:       Completed
      Exit Code:    0
      Started:      Fri, 20 May 2022 11:58:38  0100
      Finished:     Fri, 20 May 2022 11:58:38  0100
    Ready:          False
    Restart Count:  11
    Environment:    <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-zq8n7 (ro)
Conditions:
  Type              Status
  Initialized       True 
  Ready             False 
  ContainersReady   False 
  PodScheduled      True 
Volumes:
  kube-api-access-zq8n7:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              <none>
Tolerations:                 node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                             node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
  Type     Reason     Age                    From               Message
  ----     ------     ----                   ----               -------
  Normal   Scheduled  33m                    default-scheduler  Successfully assigned default/kubernetesflaskapp-deploy-5764bbbd44-8696k to minikube
  Normal   Pulled     33m                    kubelet            Successfully pulled image "beatrix1997/kubernetes_flask_app" in 14.783413947s
  Normal   Pulled     33m                    kubelet            Successfully pulled image "beatrix1997/kubernetes_flask_app" in 1.243534487s
  Normal   Pulled     32m                    kubelet            Successfully pulled image "beatrix1997/kubernetes_flask_app" in 1.373217701s
  Normal   Pulling    32m (x4 over 33m)      kubelet            Pulling image "beatrix1997/kubernetes_flask_app"
  Normal   Created    32m (x4 over 33m)      kubelet            Created container kubernetesflaskapp
  Normal   Pulled     32m                    kubelet            Successfully pulled image "beatrix1997/kubernetes_flask_app" in 1.239794774s
  Normal   Started    32m (x4 over 33m)      kubelet            Started container kubernetesflaskapp
  Warning  BackOff    3m16s (x138 over 33m)  kubelet            Back-off restarting failed container

I am using ubuntu as my OS if it matters at all. Any help would be appreciated! Many thanks!

CodePudding user response:

The error can be due to the issue in the application as the reported reason is "Back-off restarting failed container". Please paste the following logs in the question for further clarification

kubectl logs -n <NS> pods <pod-name>

CodePudding user response:

I would check the following:

  1. Check if your Docker image works in Docker, you can run it with the run command, find the official doc here
  2. If it doesn't work, then you can check what is wrong in your app first.
  3. If it does, try checking the readiness and liveness probe, here the official documentation
  4. You can find more hints about failing pods here
  • Related