Files
jenkins-pipeline/k8s_yaml/test/test-lessie-go-api.yaml

110 lines
4.0 KiB
YAML
Raw Normal View History

2025-10-30 11:20:06 +08:00
# ----------------------------
# Deployment
# ----------------------------
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-lessie-go-api-deployment
namespace: test-lessie
labels:
app: test-lessie-go-api
environment: test
project: lessie
spec:
replicas: 1
selector:
matchLabels:
app: test-lessie-go-api
environment: test
project: lessie
strategy:
type: RollingUpdate # 滚动更新策略
2025-10-30 11:20:06 +08:00
rollingUpdate:
maxSurge: 1 # 最大新增副本数
maxUnavailable: 0 # 最大不可用副本数
2025-10-30 11:20:06 +08:00
template:
metadata:
labels:
app: test-lessie-go-api
environment: test
project: lessie
spec:
imagePullSecrets:
- name: dxin-image-repository # 镜像仓库凭证Secret
volumes:
- name: go-logs-volume
hostPath:
path: /data/logs/lessie-go-api/
type: DirectoryOrCreate
containers:
- name: test-lessie-go-api # 容器名称
2025-11-07 11:25:23 +08:00
image: uswccr.ccs.tencentyun.com/lessietest/go_lessie-sourcing-api:v10_dxin_7f126d1_202511061217 # 容器镜像
imagePullPolicy: Always # 镜像拉取策略 ,总是拉
2025-10-30 11:20:06 +08:00
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: APP_ENV
value: "s1"
- name: APP_PORT
value: "8100"
ports:
- containerPort: 8100 # 容器暴露的端口
2025-10-30 11:20:06 +08:00
resources:
requests:
cpu: "100m" # 容器请求分配0.1个CPU核心这不是实际占用但调度会以这里进行参考
memory: "1.5Gi" # 容器请求分配1.5Gi内存(这会实际预留)
2025-10-30 11:20:06 +08:00
limits:
cpu: "1" # 最多可以使用1个CPU核心
memory: "3Gi" # 容器最多可以使用3Gi内存
2025-10-30 11:20:06 +08:00
volumeMounts:
- name: go-logs-volume
mountPath: /app/logs/
subPathExpr: go-log-$(POD_NAME)
readinessProbe: # 就绪探针,用于判断容器是否已准备好接收流量
httpGet:
path: /health
port: 8100
initialDelaySeconds: 5 # 就绪探测在容器启动后等待多少秒才开始第一次探测(避免应用启动未完成即被判为不就绪)
periodSeconds: 10 # 就绪探测的间隔秒数,每隔多少秒执行一次探测
timeoutSeconds: 5 # 单次就绪探测的超时时间(秒),超过则该次探测视为失败
failureThreshold: 3 # 连续失败多少次后认为就绪探测失败Pod 不再被视为就绪)
livenessProbe: # 存活探针,用于判断容器是否仍然健康,失败会触发重启
httpGet:
path: /health
port: 8100
initialDelaySeconds: 10 # 存活探测在容器启动后等待多少秒才开始第一次探测
periodSeconds: 30 # 存活探测的间隔秒数
timeoutSeconds: 5 # 单次存活探测的超时时间(秒)
failureThreshold: 3 # 连续失败多少次后认为容器不健康并触发重启
2025-10-30 11:20:06 +08:00
---
# ----------------------------
# Service
# 集群内部http://test-lessie-sourcing-api-svc.test-lessie.svc.cluster.local:8100
# 集群外部http://<Node-IP>:30810
# ----------------------------
apiVersion: v1
kind: Service
metadata:
name: test-lessie-go-api-svc
namespace: test-lessie
labels:
app: test-lessie-go-api
environment: test
project: lessie
spec:
type: NodePort
selector: # 必须匹配 Deployment 的 labels 才能关联 Pod
app: test-lessie-go-api
environment: test
project: lessie
ports:
- name: http
port: 8100 # ClusterIP 内部端口
targetPort: 8100 # 容器端口
nodePort: 30810 # 节点对外端口(30000-32767)