Kubernetes部署SpringCloud(一) Eureka 集群,解决unavailable-replicas,available-replicas条件
环境
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条件的更多相关文章
- F版本SpringCloud 5—Eureka集群和自我保护机制
源码地址:https://gitee.com/bingqilinpeishenme/Java-Tutorials 前言 上篇文章中,通过代码搭建了Eureka注册中心和客户端,是Eureka的简单应用 ...
- 三(2)、springcloud之Eureka集群配置
1)原理说明** 服务启动后向Eureka注册,Eureka Server会将注册信息向其他Eureka Server进行同步,当服务消费者要调用服务提供者,则向服务注册中心获取服务提供者地址,然后会 ...
- SpringCloud之Eureka集群
前面我们介绍了SpringCloud注册中心Eureka,但是存在一个单点故障的问题,一个注册中心远远不能满足实际的生产环境,现在我们介绍一下如何搭建一个Eureka集群. 一:集群环境搭建 我们先建 ...
- Kubernetes 部署 Nebula 图数据库集群
Kubernetes 是什么 Kubernetes 是一个开源的,用于管理云平台中多个主机上的容器化的应用,Kubernetes 的目标是让部署容器化的应用简单并且高效,Kubernetes 提供了应 ...
- Kubernetes 部署 Nacos 1.4 集群
文章转载自:http://www.mydlq.club/article/104/ 系统环境: Nacos 版本:1.4.1 Mysql 版本:8.0.19 Kubernetes 版本:1.20.1 一 ...
- SpringCloud搭建Eureka集群
第一部分:搭建Eureka Server集群 Step1:新建工程,引入依赖 依赖文件pom.xml如下 <?xml version="1.0" encoding=" ...
- Kubernetes master无法加入etcd 集群解决方法
背景:一台master磁盘爆了导致k8s服务故障,重启之后死活kubelet起不来,于是老哥就想把它给reset掉重新join,接着出现如下报错提示是说etcd集群健康检查未通过: error exe ...
- kubernetes部署Percona XtraDB Cluster集群
PXC介绍 全称percona-xtradb-cluster,提供了MySQL高可用的一种实现方法.PXC集群以节点组成(推荐至少3节点,便于故障恢复),每个节点都是基于常规的 MySQL Serve ...
- 十六、springcloud(二)Eureka集群
1.创建子工程spring-cloud-peer(jar) 2.创建application-peer1.properties,application-peer2.properties applicat ...
随机推荐
- 如何正确地使用android中的progressdialog
网上有很多关于progressdialog的用法的介绍,下面这个是最具代表性的: http://sd8089730.iteye.com/blog/1441610 其核心代码: Handler hand ...
- c# 以换行(\r\n)拆分字符串
c# 以换行(\r\n)拆分字符串 字符串数组形式: string[] striparr = strip.Split(new string[] { "\r\n" }, String ...
- 如何自动播放光盘、解决win7电脑不能播放光盘
如何设置光盘自动播放.允许光盘自动运行呢? 在使用电脑光驱播放光盘文件的时候,经常出现的一个问题是,光驱不能自动播放光盘,但是打开光盘的文件手动操作没有任何问题,这给使用造成了很多麻烦.那么,如何让光 ...
- 推荐一款在线编辑JSON的网站
推荐一款在线编辑JSON的网站 https://github.com/DavidDurman/FlexiJsonEditor 开源地址:https://github.com/DavidDurman/F ...
- linux网络设备—mdio总线
一.结构体 struct mii_bus { const char *name; //总线名 char id[MII_BUS_ID_SIZE]; //id void *priv; //私有数据 int ...
- JVM 基础:回收哪些内存/对象 引用计数算法 可达性分析算法 finalize()方法 HotSpot实现分析
转自:https://blog.csdn.net/tjiyu/article/details/53982412 1-1.为什么需要了解垃圾回收 目前内存的动态分配与内存回收技术已经相当成熟,但为什么还 ...
- 基于ubuntu搭建 Discuz 论坛
系统要求:Ubuntu 16.04.1 LTS 64 位操作系统 安装 Apache2 ubuntu 需要安装 Apache2 ,使用 apt-get 安装 Apache2(安装好后,您可以通过访问实 ...
- WineBottler for Mac(Mac 运行 exe 程序工具)安装
1.软件简介 WineBottler 是 macOS 系统上一款模拟 Windows 环境的工具,让你能够在 Mac 上安装 Windows 软件,类似于知名的 Crossover,但 Wine ...
- C++赋值兼容原则
C++赋值兼容原则(派生类对象是基类对象,反之不成立) –基类指针强制转换成派生类指针 –派生类中重定义基类成员(同名覆盖) 假设, 一个基类 "普通人", 一个派生类 " ...
- 字符串与Unicode码的相互转换
//1,字符串转换为unicode码 var s = '吴'; //2,unicode码转字符串 '\u5434'.toString(16) //吴 或者 String.fromCharCode(21 ...