私有化环境部署测试服务
本文部署基于Kuboard导入yaml的形式处理,将模版中的变量替换成真实的值,在Kuboard中选择从yaml创建即可
名词解释
- 命名空间:服务运存在K8S集群的命名空间
- 工程镜像tag:通过
pai image publish
命令构建镜像得到,K8S运行的Docker镜像版本 - 域名:服务访问的主入口,K8S需要通过域名来转发代理请求到各个服务
- 伪域名:在没有申请到域名的情况下,可以通过更改本机的host文件内,IP对应的英文名的形式,实现伪域名访问网站的功能。
- 服务入口:主入口下的二级目录;
- 后端:一般工程名去掉
pai-
并加上-api
- 前端:一般工程名去掉
pai-
- 后端:一般工程名去掉
- 数据库:
- 创建数据库参考:
CREATE DATABASE IF NOT EXISTS `数据库名` DEFAULT CHARACTER SET utf8mb4 COLLATE 'utf8mb4_general_ci';
- 创建数据库参考:
部署前端
模板
apiVersion: apps/v1
kind: Deployment
metadata:
name: $替换成工程名
labels:
app: $替换成工程名
k8s.kuboard.cn/layer: 'web'
namespace: $替换成真实命名空间
spec:
replicas: 1
selector:
matchLabels:
app: $替换成工程名
template:
metadata:
labels:
app: $替换成工程名
spec:
containers:
- name: $替换成工程名
image: dev.flyrise.cn:8082/pi-dev/$替换成工程名:$替换成工程镜像tag
envFrom:
- configMapRef:
name: pai-env-front
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 80
timeoutSeconds: 1
dnsConfig:
nameservers:
- 114.114.114.114
terminationGracePeriodSeconds: 60
---
apiVersion: v1
kind: Service
metadata:
name: $替换成工程名
namespace: $替换成真实命名空间
labels:
app: $替换成工程名
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
selector:
app: $替换成工程名
---
kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
name: $替换成工程名
namespace: $替换成真实命名空间
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
nginx.ingress.kubernetes.io/proxy-body-size: 200m
spec:
rules:
- host: $替换成真实域名
http:
paths:
- path: /$替换成服务入口(/|$)(.*)
backend:
serviceName: $替换成工程名
servicePort: 80
如果是伪域名则需要配hosts,否则某些前端工程无法启动
hostAliases:
- hostnames:
- 域名
ip: 127.0.0.1
完整示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: pai-rule-ui
labels:
app: pai-rule-ui
k8s.kuboard.cn/layer: 'web'
namespace: honghu
spec:
replicas: 1
selector:
matchLabels:
app: pai-rule-ui
template:
metadata:
labels:
app: pai-rule-ui
spec:
containers:
- name: pai-rule-ui
image: dev.flyrise.cn:8082/pi-dev/pai-rule-ui:v1.8.0
envFrom:
- configMapRef:
name: pai-env-front
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 80
timeoutSeconds: 1
dnsConfig:
nameservers:
- 114.114.114.114
hostAliases:
- hostnames:
- lims.flyrise.cn
ip: 127.0.0.1
terminationGracePeriodSeconds: 60
---
apiVersion: v1
kind: Service
metadata:
name: pai-rule-ui
namespace: honghu
labels:
app: pai-rule-ui
spec:
type: NodePort
ports:
- port: 80
targetPort: 80
selector:
app: pai-rule-ui
---
kind: Ingress
apiVersion: networking.k8s.io/v1beta1
metadata:
name: pai-rule-ui
namespace: honghu
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/use-regex: 'true'
nginx.ingress.kubernetes.io/proxy-body-size: 200m
spec:
rules:
- host: lims.flyrise.cn
http:
paths:
- path: /rule(/|$)(.*)
backend:
serviceName: pai-rule-ui
servicePort: 80
部署后端
模版
apiVersion: apps/v1
kind: Deployment
metadata:
name: $替换成工程名
labels:
app: $替换成工程名
k8s.kuboard.cn/layer: 'svc'
namespace: $替换成真实命名空间
spec:
replicas: 1
selector:
matchLabels:
app: $替换成工程名
template:
metadata:
labels:
app: $替换成工程名
spec:
containers:
- name: $替换成工程名
image: dev.flyrise.cn:8082/pi-dev/$替换成工程名:v1.8.0
env:
- name: paideploy.project.name
value: $替换成工程名
- name: paideploy.spring.datasource.url
value: jdbc:mysql://mysql.pai-cloud.svc.cluster.local:3306/$替换成真实数据库名?serverTimezone=Asia/Shanghai
envFrom:
- configMapRef:
name: pai-env-paideploy
- configMapRef:
name: pai-env-base
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 2201
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
dnsConfig:
nameservers:
- 114.114.114.114
terminationGracePeriodSeconds: 60
---
apiVersion: v1
kind: Service
metadata:
name: $替换成工程名
namespace: $替换成真实命名空间
labels:
app: $替换成工程名
spec:
type: NodePort
ports:
- name: web
port: 8080
protocol: TCP
targetPort: 8080
- name: health
port: 2201
protocol: TCP
targetPort: 2201
selector:
app: $替换成工程名
示例:
apiVersion: apps/v1
kind: Deployment
metadata:
name: pai-rules
labels:
app: pai-rules
k8s.kuboard.cn/layer: 'svc'
namespace: honghu
spec:
replicas: 1
selector:
matchLabels:
app: pai-rules
template:
metadata:
labels:
app: pai-rules
spec:
containers:
- name: pai-rules
image: dev.flyrise.cn:8082/pi-dev/pai-rules:v1.8.0
env:
- name: paideploy.project.name
value: pai-rules
- name: paideploy.spring.datasource.url
value: jdbc:mysql://mysql.pai-cloud.svc.cluster.local:3306/pai_rules?serverTimezone=Asia/Shanghai
envFrom:
- configMapRef:
name: pai-env-paideploy
- configMapRef:
name: pai-env-base
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
protocol: TCP
- containerPort: 2201
protocol: TCP
readinessProbe:
failureThreshold: 3
initialDelaySeconds: 30
periodSeconds: 10
successThreshold: 1
tcpSocket:
port: 8080
timeoutSeconds: 1
dnsConfig:
nameservers:
- 114.114.114.114
terminationGracePeriodSeconds: 60
---
apiVersion: v1
kind: Service
metadata:
name: pai-rules
namespace: honghu
labels:
app: pai-rules
spec:
type: NodePort
ports:
- name: web
port: 8080
protocol: TCP
targetPort: 8080
- name: health
port: 2201
protocol: TCP
targetPort: 2201
selector:
app: pai-rules
路由
需要去nacos 的 prod命名空间,找到pai-gateway-prod.yaml
并编辑,加上此服务的路由。
放到 id: index-workbench
之前
示例:
- id: pai-rules
uri: lb://pai-rules
predicates:
- Path=/rules-api/**
filters:
- StripPrefix=1
升级服务版本
- 通过
pai image publish
命令构建镜像得到新的镜像tag - 通过kuboard找到对应的服务,调整镜像版本即可
- 或者通过Kuboard自带的
CI/CD
集成功能,发送调整镜像版本命令
- 或者通过Kuboard自带的
同步套件数据
请求 服务主入口/data-sync-edge-agent-api/?k=yyyyMMDDhhmm&appCode=simple
yyyyMMDDhhmm
: 年月日时分appCode
: 套件标识;多个用逗号分隔
示例:
http://lims.flyrise.cn/data-sync-edge-agent-api/?k=202205091212&appCode=simple
文档更新时间: 2024-12-25 16:37 作者:管理员