环境

k8s master: 1个

k8s node: 3个

三个eureka 指定node启动,并且使用network=host

完整pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>org.lzw.ms</groupId>
<artifactId>eureka</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>eureka</name>
<description>eureka for Spring Boot</description> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Finchley.M9</spring-cloud.version>
<skipTests>true</skipTests>
</properties> <dependencies> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency> <dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependencies> <dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> <repositories>
<repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories> </project>

用于k8s 心跳健康检查

/**
* User: laizhenwei
* Date: 2018-04-12 Time: 16:09
*/
@RestController
@RequestMapping(path = "/")
public class Healthz {
@GetMapping(path = "/healthz",produces = MediaType.TEXT_PLAIN_VALUE)
public String healthz(){
return "ok";
}
}

启动类

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaApplication.class, args);
}
}

application.yml

spring:
application:
name: EUREKA

application-test.yml  available-replicas条件为

1.eureka.instance.appname 必须等于 spring.application.name 并且不可缺省,所以直接占位符 appname: ${spring.application.name}

2.prefer-ip-address: 必须为false 或者缺省

3.fetch-registry 必须非false 或者缺省

eureka:
instance:
appname: ${spring.application.name}
# prefer-ip-address: true
lease-expiration-duration-in-seconds: 90
server:
enable-self-preservation: true
#5秒清理一次
eviction-interval-timer-in-ms: 5000
client:
register-with-eureka: true
# fetch-registry: true
service-url:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/,http://${eureka-rs1.hostname}:${eureka-rs1.port}/eureka/,http://${eureka-rs2.hostname}:${eureka-rs2.port}/eureka/ logging:
config: classpath:logback-test.xml

打包成镜像

docker build -t ms-eureka .

上传到私有仓库

docker tag ms-eureka 192.168.91.137:/ms-eureka
docker push 192.168.91.137:/ms-eureka

编写 Deployment.yaml,因为使用host 部署,虽然部署在不同的k8s节点,但是因为k8s设计如果节点挂了可以在其他节点中拉起来保持副本集的数量,随便漂移,所以即使是使用host 并且指定k8s节点,其他节点部署也不能ip相同

这里只列出eureka-0, 剩下两个,自行修改参数

eureka-0

nodeName: k8s-node-0 这里指定只再 0号节点启动 eureka-0 
livenessProbe,readinessProbe为心跳检查,会请求到上面写的 Healthz Controller
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: eureka-0
namespace: ms
spec:
replicas: 1
selector:
matchLabels:
app: eureka-0
template:
metadata:
labels:
app: eureka-0
spec:
nodeName: k8s-node-0
terminationGracePeriodSeconds: 60
hostNetwork: true
containers:
- name: eureka
image: 192.168.91.137:5000/ms-eureka
command: ["java"]
args: ["-jar", "/usr/local/eureka.jar","--spring.profiles.active=test","--server.port=8000","--spring.application.name=eureka","--eureka.instance.appname=eureka","--eureka.instance.hostname=k8s-node-0","--eureka-rs1.hostname=k8s-node-1","--eureka-rs1.port=8001","--eureka-rs2.hostname=k8s-node-2","--eureka-rs2.port=8002"]
ports:
- name: http
containerPort: 8000
hostPort: 8000
livenessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 8000
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
readinessProbe:
failureThreshold: 3
httpGet:
path: /healthz
port: 8000
scheme: HTTP
initialDelaySeconds: 20
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
--- apiVersion: v1
kind: Service
metadata:
name: eureka-0
namespace: ms
labels:
app: eureka-0
spec:
ports:
- port: 8000
name: eureka-0
targetPort: 8000
selector:
app: eureka-0

启动3个 eureka

 kubectl create -f eureka-0.yaml
kubectl create -f eureka-1.yaml
kubectl create -f eureka-2.yaml

查看部署情况

打开eureka页面

Kubernetes部署SpringCloud(一) Eureka 集群,解决unavailable-replicas,available-replicas条件的更多相关文章

  1. F版本SpringCloud 5—Eureka集群和自我保护机制

    源码地址:https://gitee.com/bingqilinpeishenme/Java-Tutorials 前言 上篇文章中,通过代码搭建了Eureka注册中心和客户端,是Eureka的简单应用 ...

  2. 三(2)、springcloud之Eureka集群配置

    1)原理说明** 服务启动后向Eureka注册,Eureka Server会将注册信息向其他Eureka Server进行同步,当服务消费者要调用服务提供者,则向服务注册中心获取服务提供者地址,然后会 ...

  3. SpringCloud之Eureka集群

    前面我们介绍了SpringCloud注册中心Eureka,但是存在一个单点故障的问题,一个注册中心远远不能满足实际的生产环境,现在我们介绍一下如何搭建一个Eureka集群. 一:集群环境搭建 我们先建 ...

  4. Kubernetes 部署 Nebula 图数据库集群

    Kubernetes 是什么 Kubernetes 是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes 的目标是让部署容器化的应用简单并且高效,Kubernetes 提供了应 ...

  5. Kubernetes 部署 Nacos 1.4 集群

    文章转载自:http://www.mydlq.club/article/104/ 系统环境: Nacos 版本:1.4.1 Mysql 版本:8.0.19 Kubernetes 版本:1.20.1 一 ...

  6. SpringCloud搭建Eureka集群

    第一部分:搭建Eureka Server集群 Step1:新建工程,引入依赖 依赖文件pom.xml如下 <?xml version="1.0" encoding=" ...

  7. Kubernetes master无法加入etcd 集群解决方法

    背景:一台master磁盘爆了导致k8s服务故障,重启之后死活kubelet起不来,于是老哥就想把它给reset掉重新join,接着出现如下报错提示是说etcd集群健康检查未通过: error exe ...

  8. kubernetes部署Percona XtraDB Cluster集群

    PXC介绍 全称percona-xtradb-cluster,提供了MySQL高可用的一种实现方法.PXC集群以节点组成(推荐至少3节点,便于故障恢复),每个节点都是基于常规的 MySQL Serve ...

  9. 十六、springcloud(二)Eureka集群

    1.创建子工程spring-cloud-peer(jar) 2.创建application-peer1.properties,application-peer2.properties applicat ...

随机推荐

  1. AngularJS中自定义有关一个表格的Directive

    本篇体验在AngularJS中自定义一个有关表格的Directive.表格的需求包括: ● 表格结构 <table>    <thead>        <tr>  ...

  2. Sql Server中sql语句自己主动换行

    怎么让sql server中的sql语句自己主动换行呢? 例如以下图: 工具--选项--全部语言 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvamlhbm ...

  3. SSE图像算法优化系列三:超高速导向滤波实现过程纪要(欢迎挑战)

    自从何凯明提出导向滤波后,因为其算法的简单性和有效性,该算法得到了广泛的应用,以至于新版的matlab都将其作为标准自带的函数之一了,利用他可以解决的所有的保边滤波器的能解决的问题,比如细节增强.HD ...

  4. LeetCode 90:Subsets II

    Given a collection of integers that might contain duplicates, nums, return all possible subsets. Not ...

  5. 抓取epsg.io的内容

    简述 epsg.io是一个查询EPSG坐标系相关信息的好网站,内容很全.有各种格式的定义可以直接下载,也有坐标系的范围名称等相关信息,所以想抓取这些信息下来,方便对接各个系统. epsg.io本身是开 ...

  6. MySQL5.7在JSON解析后丢失小数部分的Bug

    在MySQL Bugs上提交了 https://bugs.mysql.com/bug.php?id=84935 . 已经在MySQL8.0.1中修复 重现步骤 -- Prepare the table ...

  7. 【概念原理】四种SQL事务隔离级别和事务ACID特性

    摘要: SQL事务隔离级别和事务的ACID特性 事务是一组读写操作,并且具有只有所有操作都成功才算成功的特性.   事务隔离级别 SQL事务隔离级别由弱到强分别是:READ_UNCOMMITTED.R ...

  8. Swift Guard 守护

    前言 guard 语句和 if 语句有点类似,都是根据其关键字之后的表达式的布尔值决定下一步执行什么. guard 语句只会有一个代码块,不像 if 语句可以 if else 多个代码块. guard ...

  9. 蓝牙发现服务UUID(service UUID)

    出至<蓝牙标准Core_V4.0>2.5.1 uuid(1576页) 其中 Bluetooth_Base_UUID定义为 00000000-0000-1000-8000-00805F9B3 ...

  10. struts2:使用JQuery、JSON和AJAX处理请求

    目的 在struts2中使用JQuery.JSON.AJAX等技术处理用户请求,并返回结果.返回结果可以是以JSONObject的方式返回,也可以是以JSONArray方式返回结果. 实现 1. 创建 ...