Files
dailyLove/deployment-temp.yml

102 lines
3.6 KiB
YAML
Raw Permalink Normal View History

2023-11-23 12:59:54 +08:00
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
2026-01-08 13:59:30 +08:00
app: $APP_NAME # 标签 用于选择器
2026-01-05 18:08:25 +08:00
version: $APP_TAG
2026-01-08 13:59:30 +08:00
name: $APP_NAME # Deployment名称
namespace: default # 一定要写名称空间
2023-11-23 12:59:54 +08:00
spec:
progressDeadlineSeconds: 600
2026-01-08 13:59:30 +08:00
replicas: 1 # 副本数 1个 pod
2026-01-05 18:08:25 +08:00
revisionHistoryLimit: 2
2023-11-23 12:59:54 +08:00
selector:
matchLabels:
2026-01-08 13:59:30 +08:00
app: $APP_NAME # 选择器 匹配 pod 标签
2023-11-23 12:59:54 +08:00
strategy:
rollingUpdate:
maxSurge: 50%
maxUnavailable: 50%
type: RollingUpdate
template:
metadata:
labels:
2026-01-08 13:59:30 +08:00
app: $APP_NAME # pod 标签
2026-01-05 18:08:25 +08:00
version: $APP_TAG
2023-11-23 12:59:54 +08:00
spec:
imagePullSecrets:
2026-01-08 13:59:30 +08:00
- name: dockerhub-id #提前在项目下配置访问私有镜像仓库的账号密码
2023-11-23 12:59:54 +08:00
containers:
2026-01-08 13:59:30 +08:00
- name: $APP_NAME # 容器名称
image: $REGISTRY/$IMAGE_NAMESPACE/$IMAGE_NAME:$APP_TAG # 镜像地址
2026-01-05 18:08:25 +08:00
imagePullPolicy: Always
2026-01-08 13:59:30 +08:00
# 存活探针配置
2026-01-05 18:08:25 +08:00
livenessProbe: # 存活探针:失败意味着应用彻底挂了,需要重启来恢复
2023-11-23 12:59:54 +08:00
httpGet:
2026-01-08 13:59:30 +08:00
path: /actuator/health/liveness # 探针路径
port: 13145 # 探针端口
scheme: HTTP # 协议
initialDelaySeconds: 20 # 容器启动后延迟 xx秒开始检查
periodSeconds: 10 # 每隔 15秒检查一次
timeoutSeconds: 5 # 10秒未返回结果则超时
# 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 秒,让流量切走
2023-11-23 12:59:54 +08:00
ports:
2026-01-08 13:59:30 +08:00
- containerPort: 13145 # 应用端口
2023-11-23 12:59:54 +08:00
protocol: TCP
2026-01-08 13:59:30 +08:00
# 资源限制
2023-11-23 12:59:54 +08:00
resources:
limits:
2026-01-08 13:59:30 +08:00
cpu: 99m # 最多 0.1核 CPU
memory: 65Mi # 最多 65m 内存
# 环境变量配置
2023-11-23 15:45:57 +08:00
env:
- name: TZ
value: "Asia/Shanghai"
2026-01-05 18:08:25 +08:00
2023-11-23 12:59:54 +08:00
---
apiVersion: v1
kind: Service
metadata:
labels:
2023-11-23 15:08:12 +08:00
app: $APP_NAME
name: $APP_NAME
namespace: default
2023-11-23 12:59:54 +08:00
spec:
2026-01-05 18:08:25 +08:00
type: NodePort
externalTrafficPolicy: Local
2023-11-23 12:59:54 +08:00
ports:
- name: http
protocol: TCP
2026-01-05 18:08:25 +08:00
port: 13145
nodePort: 30045
2023-11-23 12:59:54 +08:00
selector:
2023-11-23 15:08:12 +08:00
app: $APP_NAME