分支:matesr
平台:Kubernetes
官方提供的是docker-compose部署,部署流程比较简单,因此部署到Kubernetes难度也不高,本篇文章主要是为了解决部署后的访问异常。
部署
后端
后端依赖数据库mysql和redis,部署这里就不赘述了。
rap2-backend-deploy.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: rap2-backend
namespace: company
labels:
app: rap2-backend
spec:
replicas: 1
selector:
matchLabels:
app: rap2-backend
template:
metadata:
labels:
app: rap2-backend
spec:
containers:
- name: rap2-backend
image: 'rapteam/rap2-delos:latest'
command:
- /bin/sh
- '-c'
- node dispatch.js
ports:
- name: http-38080
containerPort: 38080
protocol: TCP
env:
- name: SERVE_PORT
value: '38080'
- name: MYSQL_URL
value: xxx
- name: MYSQL_PORT
value: '3306'
- name: MYSQL_USERNAME
value: root
- name: MYSQL_PASSWD
value: xxx
- name: MYSQL_SCHEMA
value: rap2
- name: REDIS_URL
value: xxx
- name: REDIS_PORT
value: '6379'
- name: REDIS_PWD
value: xxx
- name: MAIL_HOST
value: smtp.exmail.qq.com
- name: MAIL_USER
value: xxx
- name: MAIL_PASS
value: xxx
- name: MAIL_SENDER
value: xxx
- name: NODE_ENV
value: production
resources:
limits:
cpu: '5'
memory: 5000Mi
requests:
cpu: 50m
memory: 10Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
- name: harbor
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
前端
rap2-front-deply.yaml
kind: Deployment
apiVersion: apps/v1
metadata:
name: rap2-front
namespace: company
labels:
app: rap2-front
spec:
replicas: 1
selector:
matchLabels:
app: rap2-front
template:
metadata:
labels:
app: rap2-front
spec:
containers:
- name: rap2-front
image: 'harbor.com/rapteam/rap2-dolores:v1'
ports:
- name: http-38081
containerPort: 38081
protocol: TCP
resources:
limits:
cpu: 500m
memory: 200Mi
requests:
cpu: 50m
memory: 10Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: Always
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
imagePullSecrets:
- name: harbor-sk8s
schedulerName: default-scheduler
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 25%
maxSurge: 25%
revisionHistoryLimit: 10
progressDeadlineSeconds: 600
数据库初始化
# 在后端服务中执行数据初始化
delos node scripts/init
问题
浏览器访问前端地址
xxx.com
一直处于“拼命加载中”
打开浏览器开发者模式后可以看到info接口请求地址是http://xxx.com:38080/account/info
解决方法:该地址无法访问,如何变更后端接口地址。官方没有给出可变更的配置或者环境变量
重新编译会出现诸多问题,修改现有前端镜像中的js文件。
runtime-main.3d19d946.js
runtime-main.3d19d946.js.map
var a={serve:"https://rap2api.kreator-inc.com",
后端启动失败
2025-02-13 16:18:02[2025-02-13 08:18:01.347] master#1 worker#13 has disconnected.
2025-02-13 16:18:02[2025-02-13 08:18:02.256] master#1 worker#13 died (SIGKILL). restarting...
2025-02-13 16:18:02[2025-02-13 08:18:02.782] master#1 worker#23 has disconnected.
2025-02-13 16:18:02[2025-02-13 08:18:02.782] master#1 worker#23 died (SIGKILL). restarting...
2025-02-13 16:18:03[2025-02-13 08:18:03.747] master#1 worker#109 has disconnected.
2025-02-13 16:18:03[2025-02-13 08:18:03.946] master#1 worker#109 died (SIGKILL). restarting...
解决方法:资源给太小导致,按照2C5G配置启动。