一、构建eureka集群镜像
1、编写dockerfile文件,此处基础镜像为arm版本,eureka目录中文件内容:application-dev.yml、Dockerfile、eureka-server-1.0-SNAPSHOT.jar(添加登录认证模块,文章最后附上下载连接)
bash
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 ,此处可忽略暂不修改
bash
spring:
application:
name: eurekaServer
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
security:
user:
name: eureka
password: e4!u$8&R*kA111
server:
port: 8761
eureka:
instance:
hostname: 10.10.127.106
lease-expiration-duration-in-seconds: 60
server:
enable-self-preservation: false
eviction-interval-timer-in-ms: 30000
client:
#不向Eureka注册自己
register-with-eureka: false
#不检查其他的EurekaServer节点
fetch-registry: false
service-url:
#设置eureka服务器所在的地址,查询服务和注册服务程序都注册到这个地址(服务暴露的地址)
defaultZone: http://10.10.127.106:8761/eureka/
二、使用有状态服务StatefulSet部署eureka集群
1、配置文件使用configmap挂载至eureka集群中,账号密码可以自己调整修改
bash
apiVersion: v1
data:
application.yml: |
spring:
application:
name: eurekaServer
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
default-property-inclusion: non_null
security:
user:
name: usr
password: password
server:
port: 8761
eureka:
instance:
hostname: eureka
lease-expiration-duration-in-seconds: 60
server:
enable-self-preservation: true
eviction-interval-timer-in-ms: 3000
client:
#不向Eureka注册自己
register-with-eureka: true
#不检查其他的EurekaServer节点
fetch-registry: true
service-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-dev
namespace: paas
2、service 配置文件内容,eureka-svc.yaml
bash
apiVersion: v1
kind: Service
metadata:
name: eureka-dev
namespace: paas
spec:
ports:
- name: http
port: 8761
protocol: TCP
targetPort: 8761
selector:
app: eureka-dev
type: NodePort
3、StatefulSet 文件信息,eureka-sts.yaml ,需修改参数 EUREKA_CLIENT_SERVICEURL_DEFAULTZONE ,启动命令需配置configmap文件同步修改,可保持默认启动。
bash
apiVersion: apps/v1
kind: StatefulSet
metadata:
labels:
app: eureka-dev
name: eureka-dev
namespace: paas
spec:
replicas: 3
selector:
matchLabels:
app: eureka-dev
serviceName: eureka-dev
template:
metadata:
creationTimestamp: null
labels:
app: eureka-dev
spec:
containers:
- args:
- --spring.config.location=classpath:/bootstrap.yml,/opt/eureka/application.yml
command:
- java
- -jar
- /opt/eureka/eureka-server-1.0-SNAPSHOT.jar
env:
- name: EUREKA_INSTANCE_HOSTNAME
value: $(POD_NAME)
- name: EUREKA_INSTANCE_ID
value: $(POD_NAME)
- name: EUREKA_CLIENT_SERVICEURL_DEFAULTZONE
value: 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:latest
imagePullPolicy: IfNotPresent
name: eureka-dev
ports:
- containerPort: 8761
protocol: TCP
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
volumeMounts:
- mountPath: /opt/eureka/application.yml
name: eureka-config-dev
subPath: application.yml
volumes:
- configMap:
defaultMode: 420
items:
- key: application.yml
path: application.yml
name: eureka-config-dev
name: eureka-config-dev
4、查看集群部署状态
5、登录eureka集群,查看是否已添加登录认证,此处登录地址 http://masterIP:nodeport 方式登录
eureka-server-1.0-SNAPSHOT.jar 下载地址:
https://pan.baidu.com/s/1RVPxZ_1riYlAWcL6_At8Ew
提取码:kuer