2

I have been trying to run a Python Django application on Kubernets but not success. The application runs fine in Docker.

This is the yaml Deployment to Kubernets:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2022-02-06T14:48:45Z"
  generation: 1
  labels:
    app: keyvault
  name: keyvault
  namespace: default
  resourceVersion: "520"
  uid: ccf0e490-517f-4102-b282-2dcd71008948
spec:
  progressDeadlineSeconds: 600
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: keyvault
  strategy:
    rollingUpdate:
      maxSurge: 25%
      maxUnavailable: 25%
    type: RollingUpdate
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: keyvault
    spec:
      containers:
      - image: david900412/keyvault_web:latest
        imagePullPolicy: Always
        name: keyvault-web-5wrph
        resources: {}
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      terminationGracePeriodSeconds: 30
status:
  conditions:
  - lastTransitionTime: "2022-02-06T14:48:45Z"
    lastUpdateTime: "2022-02-06T14:48:45Z"
    message: Deployment does not have minimum availability.
    reason: MinimumReplicasUnavailable
    status: "False"
    type: Available
  - lastTransitionTime: "2022-02-06T14:48:45Z"
    lastUpdateTime: "2022-02-06T14:48:46Z"
    message: ReplicaSet "keyvault-6944b7b468" is progressing.
    reason: ReplicaSetUpdated
    status: "True"
    type: Progressing
  observedGeneration: 1
  replicas: 1
  unavailableReplicas: 1
  updatedReplicas: 1

This is the docker compose file I'm using to run the image in Docker:

version: "3.9"
   
services:
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "8000:8000"

This is the docker file I'm using to run the image in Docker:

FROM python:3.9
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

Kubectl describe pod Output:

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  51s                default-scheduler  Successfully assigned default/keyvault-6944b7b468-frss4 to minikube
  Normal   Pulled     37s                kubelet            Successfully pulled image "david900412/keyvault_web:latest" in 12.5095594s
  Normal   Pulled     33s                kubelet            Successfully pulled image "david900412/keyvault_web:latest" in 434.2995ms
  Normal   Pulling    17s (x3 over 49s)  kubelet            Pulling image "david900412/keyvault_web:latest"
  Normal   Created    16s (x3 over 35s)  kubelet            Created container keyvault-web-5wrph
  Normal   Started    16s (x3 over 35s)  kubelet            Started container keyvault-web-5wrph
  Normal   Pulled     16s                kubelet            Successfully pulled image "david900412/keyvault_web:latest" in 395.5345ms
  Warning  BackOff    5s (x4 over 33s)   kubelet            Back-off restarting failed container

Kubectl log pod Does not show anything :(

Thanks for your help.

4
  • 2
    The first thing I'd recommend doing is deleting the volumes: from your Compose setup and trying to run the container, as you've built it, with the code built into the image. Does that work? The Dockerfile seems to be missing the CMD line that tells the container what do you when you start it, does adding that in help at all? Commented Feb 6, 2022 at 15:37
  • In addition to what David Maze said, please share how you run the app using docker and try to use skaffold to translate docker-compose to kubernetes manifests Commented Feb 6, 2022 at 17:24
  • Thanks @DavidMaze and rok. I deleted volumes and add a this new line in the Dockerfile CMD [ "python3","manage.py","runserver"] and It works Commented Feb 9, 2022 at 2:24
  • How Can I mark this Question as solved? and Accept the Answer. I just see One Flag in each answer but no other options. Thanks!! Commented Feb 9, 2022 at 2:34

1 Answer 1

1

This is a community wiki answer posted for better visibility. Feel free to expand it.

Based on the comments, the solution should be as shown below.

  1. Remove volumes definition from the Compose file:
version: "3.9"

services:
  web:
    build: .
    command: python manage.py runserver 0.0.0.0:8000
    ports:
      - "8000:8000"
  1. Specify the startup command with CMD for an image in Dockerfile:

FROM python:3.9
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
CMD ["python3","manage.py","runserver"] 

Then translate a Docker Compose file to Kubernetes resources. This can be done with using Kompose or another suitable solution.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.