[英]Django, nginx and gunicorn in kubernetes
I am trying to run my django app in kubernetes.I use docker-compose to build application and nginx.I am able to run the application using proxy server nginx in docker compose.我正在尝试在 kubernetes 中运行我的 django 应用程序。我使用 docker-compose 构建应用程序和 nginx。我能够在 docker compose 中使用代理服务器 nginx 运行应用程序。
docker-compose build - successful docker-compose build - 成功
docker-compose up - successful docker-compose up - 成功
http://aggre.mabh.io - successful(able to load the application) http://aggre.mabh.io - 成功(能够加载应用程序)
when i try to deploy the image of application and nginx, I am getting error in kubernetes dashboard saying当我尝试部署应用程序和 nginx 的图像时,我在 kubernetes 仪表板中收到错误提示
Error in kubernetes kubernetes 中的错误
pod has unbound PersistentVolumeClaims (repeated 2 times) (for both nginx and application) pod 具有未绑定的 PersistentVolumeClaims(重复 2 次)(对于 nginx 和应用程序)
I am using kompose up to build and deploy the application.我正在使用kompose up来构建和部署应用程序。
How to deploy the the application in kubernetes and access the application through nginx kubernetes external end-point?如何在 kubernetes 中部署应用程序并通过 nginx kubernetes 外部端点访问应用程序?
docker-compose.yml docker-compose.yml
version: '3'
services:
djangoapp:
build: .
image: sigmaaggregator/djangoapp
labels:
- kompose.service.type=NodePort
volumes:
- .:/djangoapp
- static_volume:/djangoapp/static
ports:
- 4000:4000
networks:
- nginx_network
nginx:
image: nginx:1.13
ports:
- 80:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/djangoapp/static
depends_on:
- djangoapp
networks:
- nginx_network
networks:
nginx_network:
driver: bridge
volumes:
static_volume:
Dockerfile文件
FROM python:3.6
RUN mkdir -p /djangoapp
WORKDIR /djangoapp
COPY . /djangoapp
RUN pip install -r requirements.txt
# copy our project code
RUN python manage.py collectstatic --no-input
CMD exec /bin/bash -c "trap : TERM INT; sleep infinity & wait"
# expose the port 4000
EXPOSE 4000
# define the default command to run when starting the container
CMD ["gunicorn", "--bind", ":4000", "aggre.wsgi:application"]
config/nginx/conf.d/local.conf配置/nginx/conf.d/local.conf
upstream hello_server {
server djangoapp:4000;
}
server {
listen 80;
server_name aggre.mabh.io;
location /static/ {
alias /djangoapp/static/;
}
location / {
proxy_pass http://hello_server;
proxy_set_header Host $host;
#proxy_ssl_server_name on;
#proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Forwarded-Proto $scheme;
proxy_redirect off;
}
}
For static files with django on kubernetes, consider whitenoise http://whitenoise.evans.io/en/stable/ to provide a solution here.对于kubernetes上django的静态文件,可以考虑whitenoise http://whitenoise.evans.io/en/stable/这里提供解决方案。
This is a straightforward recommendation, but I spent much time searching around before I found it referenced.这是一个直截了当的建议,但在我发现它被引用之前,我花了很多时间四处搜索。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.