nacos v2.2 k8s部署启动报错:nacos server did not start because dumpservice bean construction failure. errMsg102, errllsg dataSource or tableName is null
背景
最近搭建个nacos环境,用的镜像是2.2版本的,yaml如下:
nacos-conf
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
namespace: nacos
data:
mysql.host: "122.122.100.101" # mysql ip
mysql.db.name: "nacos" #上面创建数据库是指的的库名称
mysql.port: "3306" #端口
mysql.user: "nacos_userName" #用户
mysql.password: "nacos_pwd" #用户密码
StatefulSet
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
namespace: nacos
spec:
serviceName: nacos-headless
replicas: 1 #3
template:
metadata:
labels:
app: nacos
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- nacos
topologyKey: "kubernetes.io/hostname"
containers:
- name: k8snacos
imagePullPolicy: Always
image: nacos/nacos-server:latest #2022年12月安装的是2.2
resources:
requests:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client
- containerPort: 9848
name: client-rpc
- containerPort: 9849
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
env:
- name: NACOS_REPLICAS
value: "1" #3
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.name
- name: MYSQL_SERVICE_PORT
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.port
- name: MYSQL_SERVICE_USER
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.user
- name: MYSQL_SERVICE_PASSWORD
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: MODE
#value: "cluster"
value: "standalone"
#- name: SPRING_DATASOURCE_PLATFORM #2.2版本一定要这个,官方的yaml漏了这个,不然会报错:
#value: "mysql"
- name: NACOS_AUTH_ENABLE
value: "true"
- name: MYSQL_SERVICE_DB_PARAM
value: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
- name: NACOS_SERVER_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: NACOS_SERVERS
value: "nacos-0.nacos-headless.nacos.svc.cluster.local:8848 nacos-1.nacos-headless.nacos.svc.cluster.local:8848 nacos-2.nacos-headless.nacos.svc.cluster.local:8848"
#格式 nacos-0.nacos-headless.<namespace>.svc.cluster.local
volumeMounts:
- name: azure
mountPath: /home/nacos/data
subPath: nacos/data
- name: azure
mountPath: /home/nacos/logs
subPath: nacos/logs
volumes:
- name: azure
persistentVolumeClaim:
claimName: mysql-pvc
selector:
matchLabels:
app: nacos
一直报错:
nacos server did not start because dumpservice bean construction failure. errMsg:102, dataSource or tableName is null
我开始根据报错搜索,判断的原因有:
1、数据库连接信息不对,连不上;
2、MYSQL_SERVICE_DB_PARAM 这个环境变量没补上,要写上,明确给定时区;
结果发现这个发现是错的。
最后折腾了几天加了一个官方钉钉群,一个老哥幽幽地指出:
“你试试添加SPRING_DATASOURCE_PLATFORM”,然后我试试就逝世,加上了:
- name: SPRING_DATASOURCE_PLATFORM #2.2版本一定要这个,官方的yaml漏了这个,不然会报错:
value: "mysql"
启动成功!!WTF,官方示例太不讲究了,坑人!!!rnm,退钱!!诶,我好像没交钱,活生生把火憋了回去;