k8s topologyKey详述
在Kubernetes中,topologyKey是用来指定Pod亲和性或反亲和性规则中的拓扑键。它用于定义Pod间的物理位置或资源的位置。拓扑键是表示系统中计算节点的可识别属性的字符串。在多节点的集群中,这些节点可能会根据其位置、硬件类型、集群分区等被分配到不同的区域(Zone)、区域内的区段(Region)或其他拓扑结构。
例如,如果你的集群跨越多个区域,并且你想要将Pod均匀地分布到这些区域,你可以使用topologyKey来指定这个规则。
以下是一个使用topologyKey的Pod反亲和性规则的例子:
把生产环境下的这两个pod调度到 shanghai 区域
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx1
namespace: prod
spec:
replicas: 2
selector:
matchLabels:
app: nginx1
template:
metadata:
name: nginx1
labels:
app: nginx1
spec:
containers:
- name: nginx1
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
livenessProbe:
httpGet:
port: 80
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
topologyKey: shanghai
把灰度环境下的这两个pod调度到 beijing 区域
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx1
namespace: gray
spec:
replicas: 2
selector:
matchLabels:
app: nginx1
template:
metadata:
name: nginx1
labels:
app: nginx1
spec:
containers:
- name: nginx1
image: nginx
imagePullPolicy: IfNotPresent
ports:
- containerPort: 80
livenessProbe:
httpGet:
port: 80
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
topologyKey: beijng
页:
[1]