I am deploy eureka in kubernetes cluster(v1.15.2),this is my yaml:
apiVersion: v1
kind: Service
metadata:
name: eureka
labels:
app: eureka
spec:
clusterIP: None
ports:
- name: server
port: 8761
targetPort: 8761
- name: management
port: 8081
selector:
app: eureka
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: eureka
labels:
app: eureka
spec:
serviceName: eureka-service
replicas: 1
podManagementPolicy: Parallel #Pod启停顺序管理
selector:
matchLabels:
app: eureka
template:
metadata:
labels:
app: eureka
spec:
terminationGracePeriodSeconds: 10 #当删除Pod时,等待时间
containers:
- name: eureka
image: registry.cn-hangzhou.aliyuncs.com/dabai_app_k8s/dabai_fat/soa-eureka:v1.0.0
ports:
- name: server
containerPort: 8761
- name: management
containerPort: 8081
env:
- name: APP_NAME
value: "eureka"
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: APP_OPTS
value: "
--spring.application.name=${APP_NAME}
--eureka.instance.hostname=${POD_NAME}.${APP_NAME}
--registerWithEureka=true
--fetchRegistry=true
--eureka.instance.preferIpAddress=false
--eureka.client.serviceUrl.defaultZone=http://eureka-0.${APP_NAME}:8761/eureka/,http://eureka-1.${APP_NAME}:8761/eureka/
"
resources:
limits:
cpu: 2000m
memory: 1024Mi
requests:
cpu: 2000m
memory: 1024Mi
readinessProbe: #就绪探针
initialDelaySeconds: 20 #延迟加载时间
periodSeconds: 5 #重试时间间隔
timeoutSeconds: 10 #超时时间设置
failureThreshold: 5 #探测失败的重试次数
httpGet:
path: /actuator/health
port: 8081
livenessProbe: #存活探针
initialDelaySeconds: 60 #延迟加载时间
periodSeconds: 5 #重试时间间隔
timeoutSeconds: 5 #超时时间设置
failureThreshold: 3 #探测失败的重试次数
httpGet:
path: /actuator/health
port: 8081
all service created successfully but give this error message:
Readiness probe failed: Get http://172.30.224.17:8081/actuator/health: dial tcp 172.30.224.17:8081: connect: connection refused
Back-off restarting failed container
The management port should be the same with eureka service port? what exactly I would do to implement probe service?
Eureka server is a spring boot application which starts an embedded tomcat and you specify the port in the application.yml of the eureka server. The default port is set to 8761.You can use the 8761 port for probe and that's what I would recommend. You need to have a rest endpoint at actuator/health
which returns 200 Ok
which I believe added by spring actuator by default so you don't need to implement it yourself.
In short changing the port from 8081 to 8761 in your probe should work.