zoukankan      html  css  js  c++  java
  • kubernetes集群部署nacos:Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'MYSQL_SERVICE_HOST'

    按照官方文档部署。

    数据库已经启动:

     

     按照官网配置nacos-pvc-nfs.yaml :

    ---
    apiVersion: v1
    kind: Service
    metadata:
      name: nacos-headless
      labels:
        app: nacos
      annotations:
        service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
    spec:
      ports:
        - port: 8848
          name: server
          targetPort: 8848
      clusterIP: None
      selector:
        app: nacos
    ---
    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: nacos-cm
    data:
      mysql.master.db.name: "nacos_devtest"
      mysql.master.port: "3306"
      mysql.slave.port: "3306"
      mysql.master.user: "nacos"
      mysql.master.password: "nacos"
    ---
    apiVersion: apps/v1
    kind: StatefulSet
    metadata:
      name: nacos
    spec:
      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"
          serviceAccountName: nfs-client-provisioner
          initContainers:
            - name: peer-finder-plugin-install
              image: nacos/nacos-peer-finder-plugin:latest
              imagePullPolicy: Always
              volumeMounts:
                - mountPath: "/home/nacos/plugins/peer-finder"
                  name: plugindir
          containers:
            - name: nacos
              imagePullPolicy: Always
              image: nacos/nacos-server:latest
              resources:
                requests:
                  memory: "3Gi"
                  cpu: "500m"
              ports:
                - containerPort: 8848
                  name: client-port
              env:
                - name: NACOS_REPLICAS
                  value: "3"
                - name: SERVICE_NAME
                  value: "nacos-headless"
                - name: POD_NAMESPACE
                  valueFrom:
                    fieldRef:
                      apiVersion: v1
                      fieldPath: metadata.namespace
                - name: MYSQL_MASTER_SERVICE_DB_NAME
                  valueFrom:
                    configMapKeyRef:
                      name: nacos-cm
                      key: mysql.master.db.name
                - name: MYSQL_MASTER_SERVICE_PORT
                  valueFrom:
                    configMapKeyRef:
                      name: nacos-cm
                      key: mysql.master.port
                - name: MYSQL_SLAVE_SERVICE_PORT
                  valueFrom:
                    configMapKeyRef:
                      name: nacos-cm
                      key: mysql.slave.port
                - name: MYSQL_MASTER_SERVICE_USER
                  valueFrom:
                    configMapKeyRef:
                      name: nacos-cm
                      key: mysql.master.user
                - name: MYSQL_MASTER_SERVICE_PASSWORD
                  valueFrom:
                    configMapKeyRef:
                      name: nacos-cm
                      key: mysql.master.password
                - name: NACOS_SERVER_PORT
                  value: "8848"
                - name: PREFER_HOST_MODE
                  value: "hostname"
              volumeMounts:
                - name: plugindir
                  mountPath: /home/nacos/plugins/peer-finder
                - name: datadir
                  mountPath: /home/nacos/data
                - name: logdir
                  mountPath: /home/nacos/logs
      volumeClaimTemplates:
        - metadata:
            name: plugindir
            annotations:
              volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
          spec:
            accessModes: [ "ReadWriteMany" ]
            resources:
              requests:
                storage: 5Gi
        - metadata:
            name: datadir
            annotations:
              volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
          spec:
            accessModes: [ "ReadWriteMany" ]
            resources:
              requests:
                storage: 5Gi
        - metadata:
            name: logdir
            annotations:
              volume.beta.kubernetes.io/storage-class: "managed-nfs-storage"
          spec:
            accessModes: [ "ReadWriteMany" ]
            resources:
              requests:
                storage: 5Gi
      selector:
        matchLabels:
          app: nacos

    启动后,pod一直没正常:

     查看pod日志没发现异常:

     根据配置文件中挂载的nfs路径,进入到nfs目录下,找到日志:

    2020-03-24 14:21:45,800 INFO Nacos is starting...
    
    java.io.IOException: java.lang.IllegalArgumentException: Could not resolve placeholder 'MYSQL_SERVICE_HOST' in value "jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true"
            at com.alibaba.nacos.config.server.service.BasicDataSourceServiceImpl.reload(BasicDataSourceServiceImpl.java:217)
            at com.alibaba.nacos.config.server.service.BasicDataSourceServiceImpl.init(BasicDataSourceServiceImpl.java:131)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:363)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:307)
            at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:419)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1737)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:576)
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:498)
            at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
            at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
            at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
            at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
            at com.alibaba.nacos.config.server.service.DynamicDataSource.getDataSource(DynamicDataSource.java:54)
            at com.alibaba.nacos.config.server.service.PersistService.init(PersistService.java:91)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)

    根据日志提示,

    MYSQL_SERVICE_HOST、
    MYSQL_SERVICE_PORT、
    MYSQL_SERVICE_DB_NAME

    不能正常识别这些变量导致。
    解决办法:

    没找到直接解决的办法。换了一种方式搭建成功了,参考:https://www.cnblogs.com/zoujiaojiao/p/12561573.html
  • 相关阅读:
    c语言中while((c=getchar())!=EOF)怎样才能输入EOF是循环中断
    Python学习笔记之装饰器原理
    Ubuntu中使用pip3报错
    Django配置xadmin后台模板之坑(一)
    ES6之字符串扩展
    Koa中设置中文Cookie值
    node中中间件body-parser的实现方式
    CSS笔记之Grid网格系统
    从0开始搭建vue+webpack脚手架(四)
    从0开始搭建vue+webpack脚手架(三)
  • 原文地址:https://www.cnblogs.com/zoujiaojiao/p/12558946.html
Copyright © 2011-2022 走看看