---
title: Kubernetes Requests Limits 与 HPA 配置指南
keywords:
- requests
- limits
- HPA
- metrics-server
- 资源度量
description: 理解并正确设置容器的资源请求与限制,结合 HPA 进行弹性伸缩,实现稳定与高效的资源利用。
date: 2025-11-25
draft: false
categories:
- 文章资讯
- 技术教程
---
Kubernetes Requests/Limits 与 HPA 配置指南
基本概念
- CPU 以核为单位,使用毫核标记(如
500m表示 0.5 核)。 - 内存以字节为单位,常用
Mi/Gi(如512Mi)。 requests决定调度与保障下限;limits约束上限并可能触发限制或 OOM。
资源与探针示例(Deployment 节选)
resources:
requests:
cpu: "500m"
memory: "512Mi"
limits:
cpu: "1"
memory: "1Gi"
readinessProbe:
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
livenessProbe:
httpGet:
path: /livez
port: 8080
initialDelaySeconds: 10
periodSeconds: 20
HPA v2 示例(基于 CPU 利用率)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: my-app-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: my-app
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
验证清单
- 确认
metrics-server正常工作:kubectl get deployment -n kube-system metrics-server。 - 使用
kubectl top pods与 HPA 状态(kubectl describe hpa)观察伸缩行为。

发表评论 取消回复