k8s部署使用有状态服务statefulset部署eureka集群,需登录认证

一、构建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

相关推荐
百流8 分钟前
Pyspark中pyspark.sql.functions常用方法(4)
1024程序员节
qq210846295312 分钟前
【Ubuntu】Ubuntu22双网卡指定网关
1024程序员节
YueTann29 分钟前
APS开源源码解读: 排程工具 optaplanner II
1024程序员节
kinlon.liu37 分钟前
安全日志记录的重要性
服务器·网络·安全·安全架构·1024程序员节
爱编程— 的小李42 分钟前
开关灯问题(c语言)
c语言·算法·1024程序员节
是程序喵呀1 小时前
Uni-App-02
uni-app·vue·1024程序员节
A_aspectJ2 小时前
Spring 框架中都用到了哪些设计模式?
spring·设计模式·1024程序员节
双子座断点2 小时前
QT 机器视觉 (3. 虚拟相机SDK、测试工具)
qt·1024程序员节
20岁30年经验的码农2 小时前
爬虫基础
1024程序员节