Usama Hameed
Usama Hameed

Reputation: 179

status of pod changes to CrashLoopBackOff after completed

Whenever I create a pod the status of pod changes to 'CrashLoopBackOff' after 'Completed'. I am using microk8s I have pushed the image to microk8s registry. I am creating a pod by running this command : "kubectl create -f backend-deployment.yml"

backend.Dockerfile( this docker file is of Django):

From python:3
ENV PYTHONUNBUFFERED 1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . ./
EXPOSE 8000

backend-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name : backend-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      component: backend
  template:
    metadata:
      labels:
        component: backend
    spec:
      containers:
        - name: backand
          image: localhost:32000/backend:latest
          ports:
          - containerPort: 8000

what am I doing wrong?

Upvotes: 1

Views: 1920

Answers (2)

Usama Hameed
Usama Hameed

Reputation: 179

I find a fix for it the main issue was I didn't added the command to run the django server that's why the pods was crashing the image inside the pod didn't know what to run.

I changed my yml file to:


      containers:
        - name: backand
          image: localhost:32000/backend:latest
          command: ["python", "manage.py", "runserver"]
          ports:
          - containerPort: 8000

Upvotes: 1

Blender Fox
Blender Fox

Reputation: 5625

A Deployment by design will endeavour to keep all its replicas running.

If your pod completes, whether successfully or not, the Deployment will restart it.

If the Deployment detects the pod has been restarted repeatedly, it will add delays to its restart attempts, hence the CrashLoopBackoff

If the pod is only supposed to run once to completion, it should be constructed as a Job instead.

Further reading: https://kubernetes.io/docs/concepts/workloads/controllers/job/

Upvotes: 3

Related Questions