前端打包
部署包文件准备
运行命令,生成disk文件夹
npm run build
Dockerfile
FROM nginx:latest
ENV info="huazh wsh"
MAINTAINER ${info}
COPY default.conf /etc/nginx/conf.d/default.conf
COPY dist /usr/share/nginx/html
nginx配置文件
server {
listen 8080;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /api{
proxy_pass http://gateway-service:8080;
rewrite ^/api/(.*)$ /$1 break;
proxy_set_header Host $host;
proxy_set_header x-forwarded-for $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_redirect off;
}
}
注:http://gateway-service:8080利用了K3S的服务访问,这样做可以避免切换IP环境后需要重新打包前端的问题。
将文件复制到Linux指定目录下
运行命令,构建镜像
cd [dir]//部署包所在路径
docker build -t huazh.com/sophon-web:v1.0.0 -f Dockerfile .
在K3S添加负载
使用刚刚构建的镜像创建进行,并映射端口容器内部端口
测试效果
访问网址http://{ip}:30010/