kubernetes快速搭建nacos 1.4.1 单节点

  sre

B205E2E7E52CE1700375AB803A8F0448.jpg

pkgs

tar zxvf nacos-server-1.4.1.tar.gz

Dockerfile

#hub.my.com/base/nacos:1.4.1-20210328
FROM hub.my.com/base/jre:8u281
MAINTAINER sre <sre@my.com>
LABEL Description="nacos 1.4.1 standalone"
ENV JAVA_HOME="/usr/local/jre/jdk1.8.0_281"
ENV JAVA_OPTS="-server -Xms512m -Xmx512m -Xmn256m"
ENV NACOS_HOME="/usr/local/nacos"
ADD nacos /usr/local/nacos

CMD JAVA_HOME/bin/javaJAVA_OPTS \
-Dnacos.standalone=true \
-Dnacos.member.list= \
-Djava.ext.dirs=JAVA_HOME/jre/lib/ext:JAVA_HOME/lib/ext \
-Xloggc:NACOS_HOME/logs/nacos_gc.log \
-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps \
-XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation \
-XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M \
-Dloader.path=NACOS_HOME/plugins/health,NACOS_HOME/plugins/cmdb \
-Dnacos.home=NACOS_HOME \
-jar NACOS_HOME/target/nacos-server.jar  \
--spring.config.additional-location=file:NACOS_HOME/conf/ \
-Dspring.config.location=NACOS_HOME/conf/application.properties \
--logging.config=NACOS_HOME/conf/nacos-logback.xml \
--server.max-http-header-size=524288

EXPOSE 8848

cm nacos-config

apiVersion: v1
kind: ConfigMap
metadata:
  name: nacos-config
  namespace: quant
data:
  application.properties: |

        server.servlet.contextPath=/nacos
        server.port=8848
        spring.datasource.platform=mysql
        db.num=1
        db.url.0=jdbc:mysql://172.16.0.9:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
        db.user.0=nacos
        db.password.0=nacos

        ### Connection pool configuration: hikariCP
        db.pool.config.connectionTimeout=30000
        db.pool.config.validationTimeout=10000
        db.pool.config.maximumPoolSize=20
        db.pool.config.minimumIdle=2

        nacos.naming.empty-service.auto-clean=true
        nacos.naming.empty-service.clean.initial-delay-ms=50000
        nacos.naming.empty-service.clean.period-time-ms=30000
        management.metrics.export.elastic.enabled=false
        management.metrics.export.influx.enabled=false
        server.tomcat.accesslog.enabled=true

        server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

        server.tomcat.basedir=
        nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console        /server/**

        nacos.core.auth.system.type=nacos
        nacos.core.auth.enabled=false
        nacos.core.auth.default.token.expire.seconds=18000

        nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789

        nacos.core.auth.caching.enabled=true
        nacos.core.auth.enable.userAgentAuthWhite=true
        nacos.core.auth.server.identity.key=
        nacos.core.auth.server.identity.value=
        nacos.istio.mcp.server.enabled=false

pvc nacos-log

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nacos-log
  namespace: quant
spec:
  accessModes:
  - ReadWriteMany
  resources:
    requests:
      storage: "1000Gi"
  volumeName: 
  storageClassName: nfs

Deployment nacos-single

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    nacos: server
  name: nacos-single
  namespace: quant
spec:
  replicas: 1
  selector:
    matchLabels:
      nacos: server
  template:
    metadata:
      labels:
        nacos: server
    spec:
      containers:
      - name: nacos-server
        image: hub.my.com/base/nacos:1.4.1-20210328
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 8848
          name: nacos
          protocol: TCP
        volumeMounts:
        - name: nacos-config
          subPath: application.properties
          mountPath: /usr/local/nacos/conf/application.properties
        - name: nacos-log
          mountPath: /usr/local/nacos/logs
      volumes:
      - name: nacos-config
        configMap:
          name: nacos-config
      - name: nacos-log
        persistentVolumeClaim:
          claimName: nacos-log

svc nacos-server 8848

---
kind: Service
apiVersion: v1
metadata:
  labels:
    nacos: server
  name: nacos-sigle
  namespace: quant
spec:
  type: NodePort
  ports:
  - name: nacos-server
    port: 8848
    targetPort: 8848
    nodePort: 30848
    protocol: TCP
  selector:
    nacos: server

启动成功

         ,--.
       ,--.'|
   ,--,:  : |                                           Nacos 1.4.1
,`--.'`|  ' :                       ,---.               Running in stand alone mode, All function modules
|   :  :  | |                      '   ,'\   .--.--.    Port: 8848
:   |   \ | :  ,--.--.     ,---.  /   /   | /  /    '   Pid: 1
|   : '  '; | /       \   /     \.   ; ,. :|  :  /`./   Console: http://10.244.117.246:8848/nacos/index.html
'   ' ;.    ;.--.  .-. | /    / ''   | |: :|  :  ;_
|   | | \   | \__\/: . ..    ' / '   | .; : \  \    `.      https://nacos.io
'   : |  ; .' ," .--.; |'   ; :__|   :    |  `----.   \
|   | '`--'  /  /  ,.  |'   | '.'|\   \  /  /  /`--'  /
'   : |     ;  :   .'   \   :    : `----'  '--'.     /
;   |.'     |  ,     .-./\   \  /            `--'---'
'---'        `--`---'     `----'

web

172.16.0.120:30848
http://172.16.0.12:30848/nacos/#/login
nacos/nacos

LEAVE A COMMENT

Captcha Code