skip to Main Content

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?

2

Answers


  1. Chosen as BEST ANSWER

    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
    
    

  2. 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/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search