修改 application.yml
暴露接口
management:
endpoints:
web:
exposure:
include: "*"
client 强制下线接口:
curl -X "POST" "http://localhost:8888/actuator/service-registry?status=DOWN"
-H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8"
Eureka Server 强制下线接口:
PUT /eureka/apps/${appId}/${ip:port}/status?value=OUT_OF_SERVICE
配置 preStop
lifecycle:
preStop:
exec:
command:
- bash
- -c
- 'curl -X POST --data DOWN http://127.0.0.1:8888/service-registry/instance-status -H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8";sleep 90'
同时指定一下优雅终止宽限期
terminationGracePeriodSeconds: 90
完整 demo:
apiVersion: apps/v1
kind: Deployment
metadata:
name: {PROJECT}
namespace: {K8S_NAMESPACE}
labels:
app: {PROJECT}
spec:
replicas: {REPLICAS}
selector:
matchLabels:
app: {PROJECT}
template:
metadata:
labels:
app: {PROJECT}
spec:
imagePullSecrets:
- name: harbor-registry
terminationGracePeriodSeconds: 90
volumes:
- name: heap-dumps
emptyDir: {}
containers:
- name: {PROJECT}
image: {IMAGE_URL}
imagePullPolicy: Always
volumeMounts:
- name: heap-dumps
mountPath: /dumps
command: ["java"]
args: {ARGS}
ports:
- containerPort: 8888
env:
- name: ENV
value: {ENV}
lifecycle:
preStop:
exec:
command:
- bash
- -c
- 'curl -X POST --data DOWN http://127.0.0.1:8888/service-registry/instance-status -H "Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8";sleep 90'
# resources:
# requests:
# memory: "1Gi"
# cpu: "500m"
# limits:
# memory: "1200Mi"
# cpu: "500m"
readinessProbe:
httpGet:
path: /actuator/health
port: 8888
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 2
periodSeconds: 10
---
apiVersion: v1
kind: Service
metadata:
name: {PROJECT}
namespace: {K8S_NAMESPACE}
spec:
type: NodePort
ports:
- port: 8888
protocol: TCP
targetPort: 8888
selector:
app: {PROJECT}
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {ENV}-{PROJECT}
namespace: {K8S_NAMESPACE}
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: {ENV}-{PROJECT}.intramirror.cn
http:
paths:
- backend:
serviceName: {PROJECT}
servicePort: 8888
path: /
pathType: ImplementationSpecific
【参考链接】
实用技巧:Spring Cloud 中,如何优雅下线微服务?
http://www.itmuch.com/spring-cloud-sum/how-to-unregister-service-in-eureka/
Spring Cloud 服务优雅下线
https://www.jianshu.com/p/1e628a74ac90
在 k8s 中使用 eureka 的几种姿势
https://gitee.com/sunshanpeng/blog/blob/master/%E5%9C%A8k8s%E4%B8%AD%E4%BD%BF%E7%94%A8eureka%E7%9A%84%E5%87%A0%E7%A7%8D%E5%A7%BF%E5%8A%BF.md
Kubernetes Pod Hook
https://i4t.com/4424.html
使用 k8s 部署 springcloud 解决三大问题
https://www.cnblogs.com/sanduzxcvbnm/p/13212718.html
Eureka 客户端下线的几种方式比较
https://blog.csdn.net/CSDN_WYL2016/article/details/107336260
https://www.cnblogs.com/sanduzxcvbnm/category/1580444.html
https://github.com/hellorocky/blog
https://horus-k.github.io/
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于