1、ruoyi-web端端打包dist并上传到master节点主机
上传到master节点【192.168.91.166/home/web/dist】目录下
注:master:166,home/web/dist为后端dist-prod打包镜像使用
1.1、npm run build:prod打包dist-prod


1.2、dist-prod上传到master节点【192.168.91.166/home/web/dist】目录下

2、dist 构成镜像并推送到私库192.168.91.164:harbor
######master节点【192.168.91.166/home/web】执行构成镜像并上传到私库192.168.91.164:harbor
2.1 DockerFile 文件内容如下
# 基础Nginx镜像
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/ghcr.io/u-sb/nginx:latest
# 1. 全局定义构建参数VERSION,构建时传入,默认兜底dist兼容旧流程
# FROM内部重新声明AR
ARG VERSION=""
# 只清理默认页面,不删除sites配置文件
RUN rm -rf /var/www/html/*
# 复制自定义配置到conf.d,Nginx会自动加载该目录下所有.conf
COPY nginx.conf /etc/nginx/conf.d/default.conf
# 你想要新增的一行(本地必须有site-default.conf文件,否则build报错)
COPY nginx.conf /etc/nginx/sites-enabled/default
# 复制前端dist静态资源
COPY dist /var/www/html
# 拼接目录 yudao-web${VERSION},完全对应你要的 yudao-web版本号
#COPY yudao-web${VERSION} /var/www/html
# 前台运行Nginx,防止容器退出重启
CMD ["nginx", "-g", "daemon off;"]
2.2 nginx.conf文件内容如下

2.3 本地构成镜像docker build -t yudao-web:202607311003 .

docker build -t yudao-web:202607311003 .

2.4 镜像推送到私库192.168.91.164:harbor
#先打上 Harbor 仓库标签
docker tag yudao-web:202607311003 192.168.91.164/rouyi-biz/yudao-web:202607311003
# 推送harbor
docker push 192.168.91.164/rouyi-biz/yudao-web:202607311003

3、创建Deployment、Service文件yaml
kubeSphere 用命令创建 namespace: biz-rouyi

【Deployment、Service】rouyi-ng-web.yaml内容如下
apiVersion: apps/v1
kind: Deployment
metadata:
name: rouyi-ng-web
namespace: biz-rouyi
spec:
replicas: 1
selector:
matchLabels:
app: rouyi-ng-web
template:
metadata:
labels:
app: rouyi-ng-web
spec:
imagePullSecrets:
- name: harbor-auth
containers:
- name: rouyi-nginx-web
#image: swr.cn-north-4.myhuaweicloud.com/ddn-k8s/ghcr.io/u-sb/nginx:latest
image: 192.168.91.164/rouyi-biz/yudao-web:202607311003
imagePullPolicy: Never
command:
- nginx
args:
- -g
- daemon off;
ports:
- containerPort: 80
---
# 新增Service片段,type直接写NodePort
apiVersion: v1
kind: Service
metadata:
name: rouyi-ng-web
namespace: biz-rouyi
spec:
type: NodePort
selector:
app: rouyi-ng-web
ports:
- port: 80
targetPort: 80
nodePort: 30080 # 固定端口30080,范围30000-32767
4、发布【Deployment、Service】
kubectl apply -f rouyi-ng-web.yaml -n biz-rouyi
查看kubectl get pods -n biz-rouyi

查看kubectl deployment日志
kubectl logs -f deployment/rouyi-ng-web -n biz-rouyi

5、kubeSphere


6、http://192.168.91.166:30080/
http://192.168.91.166:30080/login?redirect=/index


浙公网安备 33010602011771号