原因,数据库为 MySQL 5.7
需要在yaml加上参数
mysql.db.param: "characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=UTC"
使用 Kubeadm 部署 Kubernetes(K8S) 安装 -- 持久化存储(NFS网络存储)
nacos-nfs.yaml
apiVersion: v1 kind: Service metadata: name: nacos-headless namespace: vipsoft-test labels: app: nacos annotations: service.alpha.kubernetes.io/tolerate-unready-endpoints: "true" spec: ports: - port: 8848 name: server targetPort: 8848 - port: 7848 name: rpc targetPort: 7848 clusterIP: None selector: app: nacos --- apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm namespace: vipsoft-test data: mysql.host: "数据库IP" mysql.db.name: "nacos" mysql.port: "3306" mysql.user: "root" mysql.password: "110" mysql.db.param: "characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false&serverTimezone=UTC" --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nacos namespace: vipsoft-test spec: serviceName: nacos-headless replicas: 1 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 imagePullPolicy: IfNotPresent image: nacos/nacos-server:v2.0.3 resources: requests: memory: "1Gi" cpu: "500m" ports: - containerPort: 8848 name: client-port - containerPort: 7848 name: rpc env: - name: NACOS_REPLICAS value: "1" - name: SERVICE_NAME value: "nacos-headless" - name: DOMAIN_NAME value: "cluster.local" - name: POD_NAMESPACE valueFrom: fieldRef: apiVersion: v1 fieldPath: metadata.namespace - 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: MYSQL_SERVICE_DB_PARAM valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.param - name: MODE value: standalone - name: NACOS_SERVER_PORT value: '8848' - name: NACOS_APPLICATION_PORT value: '8848' - name: PREFER_HOST_MODE value: hostname - name: NACOS_SERVERS value: 'nacos-0.nacos-headless.default.svc.cluster.local:8848' - name: SPRING_DATASOURCE_PLATFORM value: mysql volumeMounts: - name: plugindir mountPath: /home/nacos/plugins/peer-finder - name: datadir mountPath: /home/nacos/data - name: logdir mountPath: /home/nacos/logs volumes: - name: plugindir hostPath: path: /nfs/nacos/plugins/peer-finder - name: datadir hostPath: path: /nfs/nacos/data - name: logdir hostPath: path: /nfs/nacos/logs selector: matchLabels: app: nacos --- apiVersion: v1 kind: Service metadata: namespace: vipsoft-test name: service-nacos labels: app: nacos spec: ports: - port: 8848 targetPort: 8848 nodePort: 30848 name: server - port: 7848 targetPort: 7848 name: rpc - port: 9848 targetPort: 9848 name: ws - port: 9849 targetPort: 9849 name: wss selector: app: nacos type: NodePort