0

I have the following Dockerfile which I need to create an image and run as a kubernetes deployment

ARG PYTHON_VERSION=3.7

FROM python:${PYTHON_VERSION}

ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1


ARG USERID
ARG USERNAME

WORKDIR /code

COPY requirements.txt ./
COPY manage.py ./

RUN pip install -r requirements.txt 
RUN useradd -u "${USERID:-1001}" "${USERNAME:-jananath}"

USER "${USERNAME:-jananath}"

EXPOSE 8080

COPY . /code/

RUN pwd 
RUN ls

ENV PATH="/code/bin:${PATH}"
# CMD bash

ENTRYPOINT ["/usr/local/bin/python"]
# CMD ["manage.py", "runserver", "0.0.0.0:8080"]

And I create the image, tag it and pushed to my private repository.

And I have the kubernetes manifest file as below:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    tier: my-app
  name: my-app
  namespace: my-app
spec:
  replicas: 1
  selector:
    matchLabels:
      tier: my-app
  template:
    metadata:
      labels:
        tier: my-app
    spec:
      containers:
      - name: my-app      
        image: "<RETRACTED>.dkr.ecr.eu-central-1.amazonaws.com/my-ecr:webv1.11"
        imagePullPolicy: Always
        args:
          - "manage.py"
          - "runserver" 
          - "0.0.0.0:8080"                     
        env:
          - name: HOST_POSTGRES
            valueFrom:
              configMapKeyRef:
                key: HOST_POSTGRES
                name: my-app  
          - name: POSTGRES_DB
            valueFrom:
              configMapKeyRef:
                key: POSTGRES_DB
                name: my-app
          - name: POSTGRES_USER
            valueFrom:
              configMapKeyRef:
                key: POSTGRES_USER
                name: my-app
          - name: USERID
            valueFrom:
              configMapKeyRef:
                key: USERID
                name: my-app
          - name: USERNAME
            valueFrom:
              configMapKeyRef:
                key: USERNAME
                name: my-app                

          - name: POSTGRES_PASSWORD
            valueFrom:
              secretKeyRef:
                key: POSTGRES_PASSWORD
                name: my-app

        ports:
          - containerPort: 8080

        resources:
          limits:
            cpu: 1000m
            memory: 1000Mi
          requests:
            cpu: 00m
            memory: 1000Mi

When I run the deployment above, the pod kills everytime and when I try to see the logs, this is all I see.

exec /usr/local/bin/python: exec format error

This is a simple django python application.

What is interesting is, this is working fine with docker-compose as below:

services:
  db:
    image: postgres
    volumes:
      - ./data/db:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
  web:
    build: 
      context: .
      args:
        USERID: ${USERID}
        USERNAME: ${USERNAME}
    command: manage.py runserver 0.0.0.0:8080
    volumes:
      - .:/code
    ports:
      - "8080:8080"
    environment:
      - POSTGRES_NAME=${POSTGRES_DB}
      - POSTGRES_USER=${POSTGRES_USER}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    env_file:
      - .env

Can someone help me with this?

1
  • 2
    What hardware are you using to build the image? What's running in the cluster? (Are you building on an ARM-based MacOS host, but running on an x86-based cluster?) Commented Dec 4, 2022 at 21:02

1 Answer 1

1

Try to inspect your image architecture using

docker image inspect <your image name>

If you see something like,

"Architecture": "arm64",
"Variant": "v8",
"Os": "linux",

which is different from your cluster architecture. Then you must build your image on a machine with the same architecture as your cluster.

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.