Open lqshow opened 5 years ago
你这样挂载 nginx 配置,subPath 的方式,不会冲掉 /etc/nginx 里的东西,但是 configmap 不会热更新,且你这个也没有做到 configmap 更新后实现 nginx reload~
@sweetpotatoman 对的,这个 demo 中的 nginx 不会自动做 reload 的。
nginx 容器中 /usr/share/nginx/data/project 目录下的数据主要来自与共享 volume,这个 demo 是作为整体的一个部署。如果前端有版本的升级,提供新的镜像,重新做一次整体的部署即可。
Overview
目前所有前端产品的部署流程是这样的,首先由前端项目打包提供纯静态文件,然后基于 nginx 实现静态网页的部署。
现在的做法是将静态文件和 nginx 定制在一个镜像内,由于打包需要 nodejs 的环境,所以最终生产的镜像根据依赖的不同一般都达到了1G 以上。
目前升级 app 的内容,哪怕只更改一个 app 的配置或者调整 nginx 的配置,都需要重新制作一个新的镜像发布,这样的流程非常麻烦。即使事先将配置做成卷映射,但是镜像依然巨大。
Sidecar pattern
sidecar 指的就是我们可以在一个 Pod 中,启动一个或多个辅助容器,来完成一些独立于主进程(主容器)之外的工作。
它主要利用在同一 Pod 中的容器可以共享存储空间的能力。
Frontend Deployment
根据 Sidecar 的容器设计模式,我们可以很容易想到,这里 nginx 应该作为主容器,前端项目作为辅助容器,只需负责提供静态文件即可。
这样部署有以下3个好处
Step 1: Frontend Dockerfile
通过多阶段构建生产 mini 镜像
Step 2: Create configmap for Nginx configuration
将 nginx 的配置通过 Configmap 方式注入到容器
Step 3: Create deployment
在这个 Pod 模板中,定义了两个容器
nginx:1.15.2(标准的 nginx 镜像)
Reference