Kubernetes 在 CentOS 上的资源调度机制
一 调度流程与核心组件
二 调度依据与常用策略
三 资源请求 Limits 与 QoS 对调度与运行的影响
四 拓扑感知与专用资源调度
五 在 CentOS 上的落地配置示例
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: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 3
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values: ["web"]
topologyKey: kubernetes.io/hostname
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: disktype
operator: In
values: ["ssd"]
containers:
- name: app
image: nginx:1.25
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
# 给节点打上污点
kubectl taint nodes node-gpu1 accelerator=nvidia:NoSchedule
# Pod 容忍该污点以调度到 GPU 节点
# tolerations:
# - key: "accelerator"
# operator: "Equal"
# value: "nvidia"
# effect: "NoSchedule"
apiVersion: apps/v1
kind: Deployment
metadata:
name: web
spec:
replicas: 6
selector:
matchLabels:
app: web
template:
metadata:
labels:
app: web
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: web
containers:
- name: app
image: nginx:1.25
resources:
requests:
memory: "128Mi"
cpu: "250m"
limits:
memory: "256Mi"
cpu: "500m"
上述示例覆盖了调度所需的关键维度:requests/limits(调度与 QoS)、亲和/反亲和(布局策略)、污点/容忍(专用节点)、拓扑分布(容错与均衡)。