增加探针配置
All checks were successful
Build Push and Deploy Image / build (push) Successful in 22m32s

This commit is contained in:
bamanker
2026-01-08 13:59:30 +08:00
parent 54202d8fd7
commit 06cfebccab
3 changed files with 77 additions and 20 deletions

View File

@@ -2,17 +2,17 @@ apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
labels: labels:
app: $APP_NAME app: $APP_NAME # 标签 用于选择器
version: $APP_TAG version: $APP_TAG
name: $APP_NAME name: $APP_NAME # Deployment名称
namespace: default #一定要写名称空间 namespace: default # 一定要写名称空间
spec: spec:
progressDeadlineSeconds: 600 progressDeadlineSeconds: 600
replicas: 1 replicas: 1 # 副本数 1个 pod
revisionHistoryLimit: 2 revisionHistoryLimit: 2
selector: selector:
matchLabels: matchLabels:
app: $APP_NAME app: $APP_NAME # 选择器 匹配 pod 标签
strategy: strategy:
rollingUpdate: rollingUpdate:
maxSurge: 50% maxSurge: 50%
@@ -21,31 +21,62 @@ spec:
template: template:
metadata: metadata:
labels: labels:
app: $APP_NAME app: $APP_NAME # pod 标签
version: $APP_TAG version: $APP_TAG
spec: spec:
imagePullSecrets: imagePullSecrets:
- name: dockerhub-id #提前在项目下配置访问阿里云的账号密码 - name: dockerhub-id #提前在项目下配置访问私有镜像仓库的账号密码
containers: containers:
- image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG - name: $APP_NAME # 容器名称
name: $APP_NAME image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG # 镜像地址
imagePullPolicy: Always imagePullPolicy: Always
# 存活探针配置
livenessProbe: # 存活探针:失败意味着应用彻底挂了,需要重启来恢复 livenessProbe: # 存活探针:失败意味着应用彻底挂了,需要重启来恢复
httpGet: httpGet:
path: /test path: /actuator/health/liveness # 探针路径
port: 13145 port: 13145 # 探针端口
initialDelaySeconds: 10 # 延迟xx秒开始执行 scheme: HTTP # 协议
periodSeconds: 15 # 每隔15秒执行一次 initialDelaySeconds: 20 # 容器启动后延迟 xx秒开始检查
timeoutSeconds: 10 # 10秒未返回结果则超时 periodSeconds: 10 # 每隔 15秒检查一次
failureThreshold: 10 # 探测失败后的重试次数,当达到这个次数后就判定结果为失败 timeoutSeconds: 5 # 10秒未返回结果则超时
# successThreshold: 5 # successThreshold: 1 # 成功 1 次就认定为健康
failureThreshold: 3 # 探测失败后的重试次数,当达到这个次数后就判定结果为失败,重启容器
#就绪探针配置
readinessProbe:
httpGet:
path: /actuator/health/readiness # 探针路径
port: 13145 # 探针端口
scheme: HTTP # 协议
initialDelaySeconds: 10 # 容器启动后等 30 秒再开始检查
periodSeconds: 5 # 每 5 秒检查一次,比存活探针频繁
timeoutSeconds: 5 # 超时时间 3 秒
# successThreshold: 1 # 成功 1 次就认为就绪
failureThreshold: 2 # 失败 3 次才认为未就绪,会从负载均衡摘掉
# 启动探针配置(可选,启动慢的应用必须配)
# startupProbe:
# httpGet:
# path: /actuator/health/liveness # 用存活探针的路径
# port: 13145
# scheme: HTTP
# initialDelaySeconds: 0 # 立即开始检查
# periodSeconds: 5 # 每 5 秒检查一次
# timeoutSeconds: 3 # 超时时间 3 秒
# successThreshold: 1 # 成功 1 次就认为启动完成
# failureThreshold: 30 # 失败 30 次150 秒)才认为启动失败
# 生命周期钩子,优雅关闭
lifecycle:
preStop:
sleep:
seconds: 10 #容器停止前先等 10 秒,让流量切走
ports: ports:
- containerPort: 13145 - containerPort: 13145 # 应用端口
protocol: TCP protocol: TCP
# 资源限制
resources: resources:
limits: limits:
cpu: 99m cpu: 99m # 最多 0.1核 CPU
memory: 65Mi memory: 65Mi # 最多 65m 内存
# 环境变量配置
env: env:
- name: TZ - name: TZ
value: "Asia/Shanghai" value: "Asia/Shanghai"

View File

@@ -87,6 +87,11 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId> <artifactId>spring-boot-autoconfigure</artifactId>
</dependency> </dependency>
<!-- Spring Boot Actuator提供健康检查端点 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>dailylove</finalName> <finalName>dailylove</finalName>

View File

@@ -56,4 +56,25 @@ logging:
level: level:
com.bamanker.dailylove.service: debug #指定openfeign日志以什么级别监控哪个接口可多个 com.bamanker.dailylove.service: debug #指定openfeign日志以什么级别监控哪个接口可多个
scanclass: false scanclass: false
# Actuator 配置
management:
# 端点配置
endpoints:
web:
exposure:
# 暴露健康端点,生产环境要慎重,别把敏感信息暴露了
include: health,info
# 健康端点配置
endpoint:
health:
# 显示详细的健康信息,方便调试
# 生产环境建议设为 when-authorized需要认证才能看详情
show-details: always
# 开启探针支持,这个必须设置
probes:
enabled: true
# 在主端口上也暴露探针路径
# 这样 K8s 探针可以直接访问应用端口,不用单独配置 management 端口
add-additional-paths: true