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

yaml 复制代码
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nginx-pv
  namespace: ruoyi #使用ns ruoyi
spec:
  capacity:
    storage: 1Gi #存储容量为 1 GiB
  accessModes:
    - ReadWriteMany
  nfs:
    path: /nfs/nginx/html/ruoyi-vue-plus   #使用 NFS 服务器的路径和地址, 使用自己定义的
    server: 139.159.140.xxx
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nginx-pvc
  namespace: ruoyi
spec:
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 1Gi
---

apiVersion: v1
kind: Service
metadata:
  labels:
    app: nginx-service
  name: nginx-service
  namespace: ruoyi
spec:
  ports:
    - nodePort: 30088   #节点端口 30088
      port: 80
      protocol: TCP
      targetPort: 80
  selector:
    app: nginx-pod
  type: NodePort
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx-deploy
  name: nginx-deploy
  namespace: ruoyi
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx-pod
  strategy: {}
  template:
    metadata:
      labels:
        app: nginx-pod
      namespace: ruoyi
    spec:
      containers:
        - image: nginx:1.22.1   使用 Nginx 1.22.1 镜像
          name: nginx
          ports:
            - containerPort: 80
          resources: { }
          volumeMounts:
            - name: nginx-config
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
            - name: html-files
              mountPath: "/usr/share/nginx/html/ruoyi-vue-plus"
          env:
            - name: TZ  # 配置环境变量,设置时区
              value: Asia/Shanghai
      volumes:
        - name: nginx-config
          configMap:
            name: nginx-configmap
            items:
              - key: nginx.conf
                path: nginx.conf
        - name: html-files
          persistentVolumeClaim:
            claimName: nginx-pvc
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-configmap
  namespace: 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.前端部署

执行打包命令

shell 复制代码
# 打包正式环境
npm run build:prod

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

相关推荐
-纸短情长17 分钟前
公网域名流量禁用详解
运维·nginx
凉风听雪29 分钟前
vue信息列表实现点击加载更多陆续显示后面数据
前端·javascript·vue.js
小韩加油呀35 分钟前
nginx收集指定接口日志到elk
nginx·elk
花归去2 小时前
elementPuls_Treeg更改颜色
javascript·vue.js·elementui
计算机源码社2 小时前
分享一个基于Node.js和Vue的游戏点单陪玩系统(源码、调试、LW、开题、PPT)
vue.js·node.js·毕设项目·计算机毕业设计源码·计算机毕业设计论文·计算机毕业设计答辩·计算机毕业设计项目
不知名靓仔4 小时前
Vue.js 集成 Word 在线编辑功能
前端·vue.js·word
智慧的牛6 小时前
Vue3详细介绍,正则采集器所用前端框架
前端·vue.js·前端框架·vue3·生命周期钩子
软件技术NINI8 小时前
【网页设计】基于HTML+CSS上海旅游网站网页作业制作
开发语言·前端·javascript·vue.js·elementui
嫦娥妹妹等等我9 小时前
Nginx负载均衡
运维·nginx·负载均衡
记得开心一点嘛10 小时前
Router路由的使用
前端·vue.js·router