--- 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 节选) ```yaml resources: requests: cpu: "500m" memory: "512Mi" limits: cpu: "1" memory: "1Gi" ``` ```yaml readinessProbe: httpGet: path: /healthz port: 8080 initialDelaySeconds: 5 periodSeconds: 10 livenessProbe: httpGet: path: /livez port: 8080 initialDelaySeconds: 10 periodSeconds: 20 ``` ## HPA v2 示例(基于 CPU 利用率) ```yaml 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`)观察伸缩行为。

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部