apiVersion: v1
kind: Pod
metadata:
name: nodeselector-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
nodeSelector:
app: node-2
apiVersion: v1
kind: Pod
metadata:
name: nodeselector-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
nodeSelector:
app: node-1
apiVersion: v1
kind: Pod
metadata:
name: nodeselector-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
nodeSelector:
app: node-3
apiVersion: v1
kind: Pod
metadata:
name: nodeselector-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
nodeName: node-2
apiVersion: v1
kind: Pod
metadata:
name: nodeselector-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
nodeName: node-3
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
imagePullPolicy: IfNotPresent
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app
operator: In
values:
- node-2
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
imagePullPolicy: IfNotPresent
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: app
operator: In
values:
- node-3
apiVersion: v1
kind: Pod
metadata:
name: preferred-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
imagePullPolicy: IfNotPresent
affinity:
nodeAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- preference:
matchExpressions:
- key: app
operator: In
values:
- node-3
weight: 60
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app: myapk
spec:
containers:
- name: myapk
image: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
affinity:
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapk
topologyKey: kubernetes.io/hostname
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app: myapk
spec:
containers:
- name: myapk
image: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app: myapk
spec:
containers:
- name: myapk
image: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
affinity:
podAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapk
topologyKey: zone
weight: 60
软亲和性测试不明显
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app: myapk
spec:
containers:
- name: myapk
image: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapk
topologyKey: zone
kubectl label nodes node-1 zone=foo
kubectl label nodes node-2 zone=foo
apiVersion: v1
kind: Pod
metadata:
name: pod-first
labels:
app: myapk
spec:
containers:
- name: myapk
image: nginx
---
apiVersion: v1
kind: Pod
metadata:
name: required-affinity-demo
labels:
app: myapp
spec:
containers:
- name: myapp
image: nginx
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- myapk
topologyKey: zone
weight: 60