阅读量:3
主要因为是连接数据库字符串未指定时区问题
将 mysql-service-db-param 参数追加 serverTimezone=UTC 即可连接成功。
k8s集群yaml文件
apiVersion: v1 data: mysql_root_password: MTIzNDU2 kind: Secret metadata: name: mysql-password namespace: test --- apiVersion: v1 data: jvm-xmn: 128m jvm-xms: 256m jvm-xmx: 256m mode: cluster mysql-database-num: "1" mysql-service-db-name: nacos_config mysql-service-db-param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=UTC mysql-service-host: 172.17.19.17 mysql-service-port: "30121" mysql-service-user: root nacos-servers: nacos-0.nacos-headless.test.svc.cluster.local:8848 nacos-1.nacos-headless.test.svc.cluster.local:8848 nacos-2.nacos-headless.test.svc.cluster.local:8848 spring-datasource-platform: mysql kind: ConfigMap metadata: name: nacos-deploy-config namespace: test --- kind: Service apiVersion: v1 metadata: name: nacos-external-lb namespace: test labels: app: nacos-external-lb spec: ports: - name: server protocol: TCP port: 8848 targetPort: 8848 nodePort: 31180 - name: client-rpc protocol: TCP port: 9848 targetPort: 9848 nodePort: 30182 - name: raft-rpc protocol: TCP port: 9849 targetPort: 9849 nodePort: 31626 - name: old-raft-rpc protocol: TCP port: 7848 targetPort: 7848 nodePort: 32724 selector: app: nacos type: NodePort sessionAffinity: None externalTrafficPolicy: Cluster --- apiVersion: v1 kind: Service metadata: name: nacos-headless namespace: test labels: app: nacos-headless spec: type: ClusterIP clusterIP: None ports: - port: 8848 name: server targetPort: 8848 - port: 9848 name: client-rpc targetPort: 9848 - port: 9849 name: raft-rpc targetPort: 9849 ## 兼容1.4.x版本的选举端口 - port: 7848 name: old-raft-rpc targetPort: 7848 selector: app: nacos --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nacos namespace: test spec: selector: matchLabels: app: nacos serviceName: nacos-headless replicas: 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: nacos image: 172.17.19.17:8082/library/nacos/nacos-server:2.0.3 ports: - containerPort: 8848 name: nacos - containerPort: 9848 name: client-rpc - containerPort: 9849 name: raft-rpc - containerPort: 7848 name: old-raft-rpc env: - name: JVM_XMN valueFrom: configMapKeyRef: key: jvm-xmn name: nacos-deploy-config - name: JVM_XMS valueFrom: configMapKeyRef: key: jvm-xms name: nacos-deploy-config - name: JVM_XMX valueFrom: configMapKeyRef: key: jvm-xmx name: nacos-deploy-config - name: NACOS_REPLICAS value: "3" - name: MYSQL_DATABASE_NUM valueFrom: configMapKeyRef: key: mysql-database-num name: nacos-deploy-config - name: MYSQL_SERVICE_DB_NAME valueFrom: configMapKeyRef: key: mysql-service-db-name name: nacos-deploy-config - name: MYSQL_SERVICE_DB_PARAM valueFrom: configMapKeyRef: key: mysql-service-db-param name: nacos-deploy-config - name: MYSQL_SERVICE_HOST valueFrom: configMapKeyRef: key: mysql-service-host name: nacos-deploy-config - name: MYSQL_SERVICE_PASSWORD valueFrom: secretKeyRef: key: mysql_root_password name: mysql-password - name: MYSQL_SERVICE_PORT valueFrom: configMapKeyRef: key: mysql-service-port name: nacos-deploy-config - name: MYSQL_SERVICE_USER valueFrom: configMapKeyRef: key: mysql-service-user name: nacos-deploy-config - name: NACOS_SERVER_PORT value: "8848" - name: NACOS_APPLICATION_PORT value: "8848" - name: PREFER_HOST_MODE value: "hostname" - name: NACOS_SERVERS valueFrom: configMapKeyRef: key: nacos-servers name: nacos-deploy-config - name: SPRING_DATASOURCE_PLATFORM valueFrom: configMapKeyRef: key: spring-datasource-platform name: nacos-deploy-config