k8s-topology-spread-constraints
link
集群级别的默认约束
内置默认约束
defaultConstraints:
- maxSkew: 3
topologyKey: "kubernetes.io/hostname"
whenUnsatisfiable: ScheduleAnyway
- maxSkew: 5
topologyKey: "topology.kubernetes.io/zone"
whenUnsatisfiable: ScheduleAnyway
sample
nginx deployment
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
labels:
app: nginx
name: nginx
spec:
replicas: 5
selector:
matchLabels:
app: nginx
strategy: {}
template:
metadata:
creationTimestamp: null
labels:
app: nginx
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: "kubernetes.io/hostname"
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: nginx
containers:
- image: nginx
name: nginx
resources: {}
status: {}
pod
kind: Pod
apiVersion: v1
metadata:
name: mypod
labels:
app: nginx
spec:
topologySpreadConstraints:
- maxSkew: 1
# topologyKey: "kubernetes.io/hostname"
topologyKey: "topology.kubernetes.io/zone"
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: nginx
containers:
- name: pause
image: registry.k8s.io/pause:3.1
result