您的位置:首页 > 汽车 > 时评 > k8s 部署RuoYi-Vue-Plus之nginx部署

k8s 部署RuoYi-Vue-Plus之nginx部署

2024/10/6 12:50:03 来源:https://blog.csdn.net/weimeibuqieryu/article/details/140250660  浏览:    关键词:k8s 部署RuoYi-Vue-Plus之nginx部署

k8s部署ruoyi也是一样的思路, 这里部署的是ruoyi-vue-plus版本

1.挂载存储

可参考 之前文章设置 https://blog.csdn.net/weimeibuqieryu/article/details/140183843

2.部署yaml

先创建命名空间ruoyi, 有就不用创建了

kubectl create namespace ruoyi

我暂不需要使用xxjob和Monitor模块, 所以去除了. 有需要再自行添加

需要先启动后端服务ruoyi-service ,不然k8s会找不到后端服务报错

需要先启动后端服务ruoyi-service ,不然k8s会找不到后端服务报错

创建部署文件 nginx-deploy.yaml

apiVersion: v1
kind: PersistentVolume
metadata:name: nginx-pvnamespace: ruoyi #使用ns ruoyi
spec:capacity:storage: 1Gi #存储容量为 1 GiBaccessModes:- ReadWriteManynfs:path: /nfs/nginx/html/ruoyi-vue-plus   #使用 NFS 服务器的路径和地址, 使用自己定义的server: 139.159.140.xxx
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: nginx-pvcnamespace: ruoyi
spec:accessModes:- ReadWriteManyresources:requests:storage: 1Gi
---apiVersion: v1
kind: Service
metadata:labels:app: nginx-servicename: nginx-servicenamespace: ruoyi
spec:ports:- nodePort: 30088   #节点端口 30088port: 80protocol: TCPtargetPort: 80selector:app: nginx-podtype: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:labels:app: nginx-deployname: nginx-deploynamespace: ruoyi
spec:replicas: 1selector:matchLabels:app: nginx-podstrategy: {}template:metadata:labels:app: nginx-podnamespace: ruoyispec:containers:- image: nginx:1.22.1   使用 Nginx 1.22.1 镜像name: nginxports:- containerPort: 80resources: { }volumeMounts:- name: nginx-configmountPath: /etc/nginx/nginx.confsubPath: nginx.conf- name: html-filesmountPath: "/usr/share/nginx/html/ruoyi-vue-plus"env:- name: TZ  # 配置环境变量,设置时区value: Asia/Shanghaivolumes:- name: nginx-configconfigMap:name: nginx-configmapitems:- key: nginx.confpath: nginx.conf- name: html-filespersistentVolumeClaim:claimName: nginx-pvc
---
apiVersion: v1
kind: ConfigMap
metadata:name: nginx-configmapnamespace: ruoyi
data:nginx.conf: |   #直接从项目里面复制. 修改后端服务为ruoyi-service:8080, 记得修改worker_processes  1;error_log  /var/log/nginx/error.log warn;pid        /var/run/nginx.pid;events {worker_connections  1024;}http {include       mime.types;default_type  application/octet-stream;sendfile        on;keepalive_timeout  65;# 限制body大小client_max_body_size 100m;log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;upstream server {ip_hash;server ruoyi-service:8080;   #就是这里记得修改}server {listen       80;server_name  localhost;#https配置参考 start# listen       444 ssl;# 证书直接存放 /docker/nginx/cert/ 目录下即可 更改证书名称即可 无需更改证书路径# ssl on;# ssl_certificate      /etc/nginx/cert/origin.pem; # /etc/nginx/cert/ 为docker映射路径 不允许更改# ssl_certificate_key  /etc/nginx/cert/originPrivate.pem; # /etc/nginx/cert/ 为docker映射路径 不允许更改# ssl_session_timeout 5m;# ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;# ssl_protocols TLSv1 TLSv1.1 TLSv1.2;# ssl_prefer_server_ciphers on;# https配置参考 end# 演示环境配置 拦截除 GET POST 之外的所有请求# if ($request_method !~* GET|POST) {#     rewrite  ^/(.*)$  /403;# }# location = /403 {#     default_type application/json;#     return 200 '{"msg":"演示模式,不允许操作","code":500}';# }# 限制外网访问内网 actuator 相关路径location ~ ^(/[^/]*)?/actuator(/.*)?$ {return 403;}location / {root   /usr/share/nginx/html/ruoyi-vue-plus;try_files $uri $uri/ /index.html;index  index.html index.htm;}location /prod-api/ {proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header REMOTE-HOST $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_pass http://server/;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}}}

部署该服务

kubectl apply -f nginx-deploy.yaml

就可以使用节点的ip+30088来访问了. 公网记得防火墙的端口要打开

3.前端部署

执行打包命令

# 打包正式环境
npm run build:prod

打包后生成打包文件在 ruoyi-ui/dist 目录 将 dist 目录下文件(不包含 dist 目录) 上传到部署服务器 /nfs/nginx/html/ruoyi-vue-plus 目录下

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com