最近服务迁移至K8S集群中,因为要做一些压力测试,需要给各服务资源进行限制,记录一下
apiVersion: apps/v1
kind: Deployment
metadata:
name: pay-app
namespace: pay
labels:
app: pay-app
group: pay-app-group
spec:
replicas: 1
selector:
matchLabels:
app: pay-app
template:
metadata:
labels:
app: pay-app
group: pay-app-group
spec:
containers:
- name: pay-app
image: docker-dev.***:8443/pay-app:20240712062211
args: ["--spring.profiles.active=uat"]
volumeMounts:
- name: keys-storage
subPath: pay/config/pay-app
mountPath: /config
- name: keys-storage
subPath: pay/keys
mountPath: /keys
- name: keys-storage
subPath: pay/pay-app/logs
mountPath: /logs
ports:
- containerPort: 8092
# 资源限制,每个应用必须对资源做好规划
resources:
limits:
cpu: "2"
memory: 2Gi
requests:
cpu: "2"
memory: 2Gi
# pod退出前设置休眠短暂的时间(给程序足够的时间处理未完成的请求),优雅退出
lifecycle:
preStop:
exec:
command: ["/bin/sh","-c", "sleep 10"]
# 存活探针
livenessProbe:
tcpSocket:
port: 8092
failureThreshold: 3
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
# 就绪探针
readinessProbe:
tcpSocket:
port: 8092
failureThreshold: 3
initialDelaySeconds: 3
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 1
volumes:
- name: keys-storage
persistentVolumeClaim:
claimName: pvc-keys
---
apiVersion: v1
kind: Service
metadata:
name: pay-app
namespace: pay
spec:
selector:
app: pay-app
group: pay-app-group
ports:
- protocol: TCP
port: 8092
targetPort: 8092
type: ClusterIP