如何在Kubernetes中运行Python服务器

6l7fqoea  于 2022-12-11  发布在  Kubernetes
关注(0)|答案(1)|浏览(108)

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?

vxqlmq5t

vxqlmq5t1#

尝试使用以下方法检查映像体系结构

docker image inspect <your image name>

如果您看到类似以下的内容,

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

这与您的群集体系结构不同。则必须在与群集具有相同体系结构的计算机上构建映像。

相关问题