我在 Django 中构建了一个 API,并使用 docker-compose 来编排 redis 和 celery 服务。现在,我想将 API 移动到 Kubernetes 集群 (AKS)。但是,python can't find manage.py
当我将它运行到集群中时出现错误。我使用 Kompose 工具编写了 kubernets manifest.yaml。这是我的 Dockerfile、docker-compose.yml 和 kubernets.yaml 文件
# docker-compose.yml
version: '3'
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python3 ./manage.py makemigrations &&
python3 ./manage.py migrate &&
python3 ./manage.py runserver 0.0.0.0:8000"
Dockerfile
# Dockerfile
FROM python:3.8
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
COPY ./app /app
WORKDIR /app
并且 kubernets 表现出来
apiVersion: v1
items:
- apiVersion: v1
kind: Service
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kb_manifests.yaml
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: app
name: app
spec:
ports:
- name: "8000"
port: 8000
targetPort: 8000
selector:
io.kompose.service: app
status:
loadBalancer: {}
- apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kb_manifests.yaml
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: app
name: app
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: app
strategy:
type: Recreate
template:
metadata:
annotations:
kompose.cmd: kompose convert -f docker-compose.yml -o kb_manifests.yaml
kompose.version: 1.22.0 (955b78124)
creationTimestamp: null
labels:
io.kompose.service: app
spec:
containers:
- args:
- sh
- -c
- |-
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py runserver 0.0.0.0:8000
image: <image pushed in a Azure Container Registry (ACR)>
name: app
ports:
- containerPort: 8000
resources: {}
volumeMounts:
- mountPath: /app
name: app-claim0
restartPolicy: Always
volumes:
- name: app-claim0
persistentVolumeClaim:
claimName: app-claim0
status: {}
- apiVersion: v1
kind: PersistentVolumeClaim
metadata:
creationTimestamp: null
labels:
io.kompose.service: app-claim0
name: app-claim0
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 100Mi
status: {}
日志错误
$ kubectl logs app-6fc488bf56-hb8g9 --previous
# python: can't open file 'manage.py': [Errno 2] No such file or director