xiabingbao

博客园 首页 新随笔 联系 订阅 管理

在kubernetes部署ruoyi的服务(前端和基础的后端服务)

将以下yaml进行apply即可

先将外部服务添加进来,本次特指mysql

apiVersion: v1
kind: Service
metadata:
  name: ruoyi-mysql
  namespace: default    # 可根据你的命名空间修改
spec:
  ports:
    - port: 3306        # Pod 内访问端口
      targetPort: 3306  # 实际 MySQL 端口
  clusterIP: None        # 不分配集群 IP,由 Endpoints 映射
---
apiVersion: v1
kind: Endpoints
metadata:
  name: ruoyi-mysql
  namespace: default
subsets:
  - addresses:
      - ip: 10.12.50.0   # 你的外部数据库 IP
    ports:
      - port: 3306

ruoyi-auth的deployment和service

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ruoyi-auth
  labels:
    app: ruoyi-auth
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ruoyi-auth
  template:
    metadata:
      labels:
        app: ruoyi-auth
    spec:
      containers:
        - name: ruoyi-auth
          image: ccr.ccs.tencentyun.com/xiabingbao-pub/ruoyi-auth:v0.9
          ports:
            - containerPort: 9200
          # 如果需要健康检查,可以启用以下配置:
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: 9200
          #   initialDelaySeconds: 10
          #   periodSeconds: 30
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: ruoyi-auth
spec:
  selector:
    app: ruoyi-auth
  ports:
    - name: http
      port: 9200
      targetPort: 9200
      nodePort: 30920   # 可选,用于 NodePort 方式访问
  type: NodePort

ruoyi-system的deployment和service

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ruoyi-modules-system
  labels:
    app: ruoyi-modules-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ruoyi-modules-system
  template:
    metadata:
      labels:
        app: ruoyi-modules-system
    spec:
      containers:
        - name: ruoyi-modules-system
          image: ccr.ccs.tencentyun.com/xiabingbao-pub/ruoyi-modules-system:v0.8
          ports:
            - containerPort: 9201
          # 可选的健康检查配置(建议生产环境启用)
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: 9201
          #   initialDelaySeconds: 10
          #   periodSeconds: 30
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: ruoyi-modules-system
spec:
  selector:
    app: ruoyi-modules-system
  ports:
    - name: http
      port: 9201
      targetPort: 9201
      nodePort: 30921   # 可选:允许通过 Node IP:30921 访问
  type: NodePort

ruoyi-gateway的deployment和service

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ruoyi-gateway
  labels:
    app: ruoyi-gateway
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ruoyi-gateway
  template:
    metadata:
      labels:
        app: ruoyi-gateway
    spec:
      containers:
        - name: ruoyi-gateway
          image: ccr.ccs.tencentyun.com/xiabingbao-pub/ruoyi-gateway:v0.9
          ports:
            - containerPort: 8080
          # 如果容器有健康检查,可以加上:
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: 8080
          #   initialDelaySeconds: 10
          #   periodSeconds: 30
      restartPolicy: Always
      volumes:
        - name: ruoyi-gateway-volume
          hostPath:
            path: ./ruoyi-gateway
            type: Directory
---
apiVersion: v1
kind: Service
metadata:
  name: ruoyi-gateway
spec:
  selector:
    app: ruoyi-gateway
  ports:
    - name: http
      port: 8080
      targetPort: 8080
      nodePort: 30080   # 可选,若想通过 NodePort 访问
  type: NodePort

ruoyi前端的deployment和service

apiVersion: apps/v1
kind: Deployment
metadata:
  name: ruoyi-nginx
  labels:
    app: ruoyi-nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ruoyi-nginx
  template:
    metadata:
      labels:
        app: ruoyi-nginx
    spec:
      containers:
        - name: ruoyi-nginx
          image: ccr.ccs.tencentyun.com/xiabingbao-pub/ruoyi-ui:v0.8
          ports:
            - containerPort: 80
          # 如果你希望加载 nginx.conf 或静态资源卷,可在这里加 volumeMounts
      restartPolicy: Always
---
apiVersion: v1
kind: Service
metadata:
  name: ruoyi-nginx
spec:
  selector:
    app: ruoyi-nginx
  ports:
    - name: http
      port: 80
      targetPort: 80
      nodePort: 30880   # 可选,允许通过 Node IP:30080 访问
  type: NodePort
posted on 2026-01-18 16:48  夏冰雹先生  阅读(1)  评论(0)    收藏  举报