CentOS 环境下 Kubernetes 资源管理实战指南
一 核心概念与单位
二 命名空间配额与准入控制
三 常用资源配置示例
apiVersion: v1
kind: Pod
metadata:
name: demo
spec:
containers:
- name: app
image: nginx:1.25
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
apiVersion: v1
kind: ResourceQuota
metadata:
name: ns-quota
namespace: team-a
spec:
hard:
requests.cpu: "2"
requests.memory: "4Gi"
limits.cpu: "4"
limits.memory: "8Gi"
pods: "10"
services: "5"
persistentvolumeclaims: "5"
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: demo-hpa
namespace: team-a
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: demo
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60
apiVersion: v1
kind: Pod
metadata:
name: gpu-demo
spec:
containers:
- name: cuda
image: nvidia/cuda:12.2-base
resources:
limits:
nvidia.com/gpu: 1
前提:节点已安装 NVIDIA 驱动 与 Device Plugin(如通过 DaemonSet 部署)。
四 调度与节点维度管理
五 监控 验证与优化建议
kubectl describe node <node>kubectl describe quota -n <ns>kubectl describe pod <pod>