如何在Google Kubernetes Engine和Google Container Registry上运行Django Daphne服务

问题描述 投票:2回答:1

Dockerfile

FROM ubuntu:18.04
RUN apt-get update
RUN apt-get install build-essential -y
WORKDIR /app
COPY . /app/

# Python
RUN apt-get install python3-pip -y
RUN python3 -m pip install virtualenv
RUN python3 -m virtualenv /env36
ENV VIRTUAL_ENV /env36
ENV PATH /env36/bin:$PATH
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Start Daphne [8443]
ENV DJANGO_SETTINGS_MODULE=settings
CMD daphne -e ssl:8443:privateKey=/ssl-cert/privkey.pem:certKey=/ssl-cert/fullchain.pem asgi:application

# Open port 8443
EXPOSE 8443

启用Google IP Alias以便我们可以连接到Google Memorystore / Redis

Build & Push

$ docker build -t [GCR_NAME] -f path/to/Dockerfile .
$ docker tag [GCR_NAME] gcr.io/[GOOGLE_PROJECT_ID]/[GCR_NAME]:[TAG]
$ docker push gcr.io/[GOOGLE_PROJECT_ID]/[GCR_NAME]:[TAG]

Deploy to GKE

$ envsubst < k8s.yml > patched_k8s.yml
$ kubectl apply -f patched_k8s.yml
$ kubectl rollout status deployment/[GKE_WORKLOAD_NAME]

我在GKE / GCR上配置了Daphne。如果你们有其他解决方案,请给我你的建议。

django google-kubernetes-engine ubuntu-18.04 docker-container daphne
1个回答
1
投票

system不包括在Ubuntu:18.04码头图像中。

使用ENTRYPOINTExecStart属性中的命令将project-daphne.service添加到Dockerfile。

© www.soinside.com 2019 - 2024. All rights reserved.