一、构建eureka集群镜像
1、编写dockerfile文件,此处基础镜像为arm版本,eureka目录中文件内容:application-dev.yml、Dockerfile、eureka-server-1.0-SNAPSHOT.jar(添加登录认证模块,文章最后附上下载连接)
FROM mdsol/java8-jdk-arm:latest
COPY eureka /opt/eureka
RUN chmod -R 777 /opt/eureka/*
ENTRYPOINT ["java","-jar","/opt/eureka/eureka-server-1.0-SNAPSHOT.jar","--spring.config.location=classpath:/bootstrap.yml,/opt/eureka/application-dev.yml","&"]
2、配置文件基础信息,application-dev.yml ,此处可忽略暂不修改
spring:application:name: eurekaServerjackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT+8default-property-inclusion: non_nullsecurity:user:name: eurekapassword: e4!u$8&R*kA111
server:port: 8761
eureka:instance:hostname: 10.10.127.106lease-expiration-duration-in-seconds: 60server:enable-self-preservation: falseeviction-interval-timer-in-ms: 30000client:#不向Eureka注册自己register-with-eureka: false#不检查其他的EurekaServer节点fetch-registry: falseservice-url:#设置eureka服务器所在的地址,查询服务和注册服务程序都注册到这个地址(服务暴露的地址)defaultZone: http://10.10.127.106:8761/eureka/
二、使用有状态服务StatefulSet部署eureka集群
1、配置文件使用configmap挂载至eureka集群中,账号密码可以自己调整修改
apiVersion: v1
data:application.yml: |spring:application:name: eurekaServerjackson:date-format: yyyy-MM-dd HH:mm:sstime-zone: GMT+8default-property-inclusion: non_nullsecurity:user:name: usrpassword: passwordserver:port: 8761eureka:instance:hostname: eurekalease-expiration-duration-in-seconds: 60server:enable-self-preservation: trueeviction-interval-timer-in-ms: 3000client:#不向Eureka注册自己register-with-eureka: true#不检查其他的EurekaServer节点fetch-registry: trueservice-url:#设置eureka服务器所在的地址,查询服务和注册服务程序都注册到这个地址(服务暴露的地址)defaultZone: http://usr:password@eureka-dev-0.eureka-dev:8761/eureka/,http://usr:password@eureka-dev-1.eureka-dev:8761/eureka/,http://uer:password@eureka-dev-2.eureka-dev:8761/eureka/
kind: ConfigMap
metadata:name: eureka-config-devnamespace: paas
2、service 配置文件内容,eureka-svc.yaml
apiVersion: v1
kind: Service
metadata:name: eureka-devnamespace: paas
spec:ports:- name: httpport: 8761protocol: TCPtargetPort: 8761selector:app: eureka-devtype: NodePort
3、StatefulSet 文件信息,eureka-sts.yaml ,需修改参数 EUREKA_CLIENT_SERVICEURL_DEFAULTZONE ,启动命令需配置configmap文件同步修改,可保持默认启动。
apiVersion: apps/v1
kind: StatefulSet
metadata:labels:app: eureka-devname: eureka-devnamespace: paas
spec:replicas: 3selector:matchLabels:app: eureka-devserviceName: eureka-devtemplate:metadata:creationTimestamp: nulllabels:app: eureka-devspec:containers:- args:- --spring.config.location=classpath:/bootstrap.yml,/opt/eureka/application.ymlcommand:- java- -jar- /opt/eureka/eureka-server-1.0-SNAPSHOT.jarenv:- name: EUREKA_INSTANCE_HOSTNAMEvalue: $(POD_NAME)- name: EUREKA_INSTANCE_IDvalue: $(POD_NAME)- name: EUREKA_CLIENT_SERVICEURL_DEFAULTZONEvalue: http://usr:password@eureka-dev-0.eureka-dev:8761/eureka/,http://usr:password@eureka-dev-1.eureka-dev:8761/eureka/,http://usr:password@eureka-dev-2.eureka-dev:8761/eureka/image: harbor.dcos.xixian.unicom.local/armtianti/cetp-eureke-arm-dev:latestimagePullPolicy: IfNotPresentname: eureka-devports:- containerPort: 8761protocol: TCPterminationMessagePath: /dev/termination-logterminationMessagePolicy: FilevolumeMounts:- mountPath: /opt/eureka/application.ymlname: eureka-config-devsubPath: application.ymlvolumes:- configMap:defaultMode: 420items:- key: application.ymlpath: application.ymlname: eureka-config-devname: eureka-config-dev
4、查看集群部署状态
5、登录eureka集群,查看是否已添加登录认证,此处登录地址 http://masterIP:nodeport 方式登录
eureka-server-1.0-SNAPSHOT.jar 下载地址:
https://pan.baidu.com/s/1RVPxZ_1riYlAWcL6_At8Ew
提取码:kuer