forked from chaseSpace/k8s-tutorial-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpod_affinityPod.yaml
34 lines (34 loc) · 1.43 KB
/
pod_affinityPod.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
apiVersion: v1
kind: Pod
metadata:
name: go-http-podaffinity
spec:
containers:
- name: go-http
image: leigg/hellok8s:v1
# nodeSelector: 如果和亲和性同时配置,则必须都满足
affinity:
# podAffinity 可以和 podAntiAffinity 同时存在
podAffinity: # pod亲和性
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- { key: app, operator: In, values: [ "go" ] }
topologyKey: kubernetes.io/os # 必须指定,它是你希望调度Pod的目标节点群共有的标签,亲和性规则也仅会在此节点群生效
# namespaces: ["dev","test"] 允许指定命名空间,不指定则是当前Pod所在的空间
# namespaceSelector: # 或者 使用标签筛选命令空间
# matchExpressions:
# - key:
# operator:
# matchLabels:
# - environment: production
# preferredDuringSchedulingIgnoredDuringExecution:
# - podAffinityTerm:
# topologyKey:
# weight:
podAntiAffinity: # pod反亲和性
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- { key: highcpu, operator: In, values: [ "true" ] }
topologyKey: kubernetes.io/hostname # 反亲和性中,此key的值固定为 kubernetes.io/hostname