How to run Django Daphne service on Google Kubernetes Engine and Google Container Registry

3/24/2019

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

Enable Google IP Alias in order that we may connect to 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]

I configured Daphne on GKE/GCR. If you guys have other solutions, please give me your advice.

-- Tay Dong
daphne
django
docker-container
google-kubernetes-engine
ubuntu-18.04

1 Answer

3/24/2019

system is not included in the Ubuntu:18.04 docker image.

Add an ENTRYPOINT to your Dockerfile with commands in ExecStart property of project-daphne.service.

-- Sanjeewa
Source: StackOverflow