RollingUpdate
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-boot-probes
labels:
app: spring-boot-probes
spec:
replicas: 4
strategy:
# 配置 滚动更新 策略
type: RollingUpdate
rollingUpdate:
# 更新时增加新的 pods 数量(4 + 2 = 6)
maxSurge: 2
# 更新时允许最大 pods 数量不对外服务
maxUnavailable: 1
# 新的 pods 就绪状态观察时间。
# 必须保证处于就绪状态的 pod 能经历一个完整的活性探测周期。
minReadySeconds: 120
selector:
matchLabels:
app: spring-boot-probes
template:
metadata:
labels:
app: spring-boot-probes
version: v1.0.0
spec:
containers:
- name: spring-boot-probes
image: registry.cn-hangzhou.aliyuncs.com/log-service/spring-boot-probes:1.0.0
ports:
- containerPort: 8080
name: http
# resources 资源限制
resources:
limits:
cpu: 500m
memory: 400Mi
requests:
cpu: 200m
memory: 200Mi
# 就绪探针 如果探针判断失败,则不会有流量发往到这个pod。
readinessProbe:
# http Get请求
httpGet:
path: /actuator/health
port: 8080
# 初始化检测时间, 指启动后30s开始探针检测
initialDelaySeconds: 30
# 探针探测的时间间隔为10s
periodSeconds: 10
# 探针探测失败后, 最少连续探测成功多少次才被认定为成功
successThreshold: 1
# 探测成功后, 最少连续探测失败多少次才被认定为失败
failureThreshold: 1
# periodSeconds = 10s failureThreshold = 1 大约 10 秒后就不会有流量发往它
# 活性探测 如果探针判断失败, 则会重启这个 pod。
livenessProbe:
# http Get请求
httpGet:
path: /actuator/health
port: 8080
# 初始化检测时间, 指启动后40s开始探针检测
# 必须在 readinessProbe 探针检测之后
initialDelaySeconds: 40
# 探针探测的时间间隔为20s
periodSeconds: 20
# 探针探测失败后, 最少连续探测成功多少次才被认定为成功
successThreshold: 1
# 探测成功后, 最少连续探测失败多少次才被认定为失败
failureThreshold: 3
# periodSeconds = 20s failureThreshold = 3 当容器异常时, 大约 60 秒后就不会被重启。
---
apiVersion: v1
kind: Service
metadata:
labels:
app: spring-boot-probes
name: spring-boot-probes-svc
spec:
ports:
- port: 8080
name: http
targetPort: 8080
protocol: TCP
selector:
app: spring-boot-probes