nacos 部署在k8s 上的例子是使用的stateful 三节点加 MySQL 主从,对于测试环境来说太占资源了。官方给出的 docker-compose 单节点也是 MySQL 主从,对于测试环境没必要。所以在测试环境上基于官方的例子作出一些修改,部署一个单节点的 nacos-server 和 单节点MySQL,记录一些使用的文件。 Dockerfile:
FROM openjdk
ENV TIME_ZONE=Asia/Shanghai \
MODE="standalone" \
PREFER_HOST_MODE="ip"\
BASE_DIR="/home/nacos" \
CLASSPATH=".:/home/nacos/conf:$CLASSPATH" \
CLUSTER_CONF="/home/nacos/conf/cluster.conf" \
FUNCTION_MODE="all" \
NACOS_USER="nacos" \
JVM_XMS="2g" \
JVM_XMX="2g" \
JVM_XMN="1g" \
JVM_MS="128m" \
JVM_MMS="320m" \
NACOS_DEBUG="n" \
TOMCAT_ACCESSLOG_ENABLED="false" \
JAVA="/usr/java/openjdk-13/bin/java"
WORKDIR /$BASE_DIR
RUN set -x && \
yum update -y && \
yum install iputils nc libcurl -y && \
ln -snf /usr/share/zoneinfo/$TIME_ZONE /etc/localtime && echo '$TIME_ZONE' > /etc/timezone && \
yum autoremove && yum clean all
COPY ./nacos /home/nacos
# set startup log dir
RUN mkdir -p logs \
&& cd logs \
&& touch start.out \
&& ln -sf /dev/stdout start.out \
&& ln -sf /dev/stderr start.out
EXPOSE 8848
ENTRYPOINT ["bin/docker-startup.sh"]
application.properties
# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_SERVER_PORT:8848}
spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:""}
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false
db.num=${MYSQL_DATABASE_NUM:2}
db.url.0=jdbc:mysql://${MYSQL_MASTER_SERVICE_HOST}:${MYSQL_MASTER_SERVICE_PORT:3306}/${MYSQL_MASTER_SERVICE_DB_NAME}?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user=${MYSQL_MASTER_SERVICE_USER}
db.password=${MYSQL_MASTER_SERVICE_PASSWORD}
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=/,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/login,/v1/console/health/**,/v1/cs/**,/v1/ns/**,/v1/cmdb/**,/actuator/**,/v1/console/server/**
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false
nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true
MySQL PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nacos-mysql-pvc
spec:
accessModes:
- ReadWriteOnce
storageClassName: rook-ceph-block
resources:
requests:
storage: 5Gi
MySQL Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nacos-mysql
spec:
selector:
matchLabels:
app: nacos-mysql
template:
metadata:
labels:
app: nacos-mysql
spec:
containers:
- name: nacos-mysql
image: nacos/nacos-mysql-master:latest
resources:
limits:
memory: "1024Mi"
cpu: "1000m"
requests:
memory: "512Mi"
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: "root"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "nacos"
- name: MYSQL_REPLICATION_USER
value: 'nacos_ru'
- name: MYSQL_REPLICATION_PASSWORD
value: 'nacos_ru'
volumeMounts:
- name: mysql-persistent-storage
mountPath: /var/lib/mysql
subPath: mysql
readOnly: false
volumes:
- name: mysql-persistent-storage
persistentVolumeClaim:
claimName: nacos-mysql-pvc
---
apiVersion: v1
kind: Service
metadata:
name: nacos-mysql
labels:
name: nacos-mysql
spec:
selector:
app: nacos-mysql
ports:
- name mysql-remote
port: 3306
nacos PVC
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nacos-server-plugindir
spec:
accessModes:
- ReadWriteOnce
storageClassName: rook-ceph-block
resources:
requests:
storage: 5Gi
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nacos-server-datadir
spec:
accessModes:
- ReadWriteOnce
storageClassName: rook-ceph-block
resources:
requests:
storage: 5Gi
nacos deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nacos-server
spec:
selector:
matchLabels:
app: nacos-server
template:
metadata:
labels:
app: nacos-server
spec:
containers:
- name: nacos-server
image: registry.cn-hangzhou.aliyuncs.com/private/nacos-server:standalone-1.0
resources:
limits:
memory: "640Mi"
cpu: "500m"
requests:
memory: "256Mi"
ports:
- containerPort: 8848
env:
- name: MYSQL_MASTER_SERVICE_DB_NAME
value: "nacos_devtest"
- name: MYSQL_MASTER_SERVICE_PORT
value: "3306"
- name: MYSQL_MASTER_SERVICE_USER
value: "nacos"
- name: MYSQL_MASTER_SERVICE_PASSWORD
value: "nacos"
- name: MYSQL_MASTER_SERVICE_HOST
value: "nacos-mysql"
- name: NACOS_SERVER_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
readinessProbe:
httpGet:
port: 8848
path: /nacos/v1/console/health/readiness
initialDelaySeconds: 60
timeoutSeconds: 3
livenessProbe:
httpGet:
port: 8848
path: /nacos/v1/console/health/liveness
initialDelaySeconds: 60
timeoutSeconds: 3
volumeMounts:
- name: plugindir
mountPath: /home/nacos/plugins/peer-finder
- name: datadir
mountPath: /home/nacos/data
volumes:
- name: plugindir
persistentVolumeClaim:
claimName: nacos-server-plugindir
- name: datadir
persistentVolumeClaim:
claimName: nacos-server-datadir
---
apiVersion: v1
kind: Service
metadata:
name: nacos-server
labels:
name: nacos-server
spec:
selector:
app: nacos-server
ports:
- name: nacos-client
port: 8848