配置方法:在k8s中,节点的调度主要由亲和性和污点来进行控制的。
而在亲和性部分由分为了节点亲和性和节点反亲和性。
节点亲和性是指在pod部署时,尽量(软策略)或者必须满足(硬策略)部署在某些节点上。
而节点反亲和性就是指,在节点部署中,对具有相同标签的pod不会部署在同一个节点中。
yaml:
apiVersion: apps/v1
kind: Deployment
metadata:
name: redis-cache
spec:
selector:
matchLabels:
app: store
replicas: 3
template:
metadata:
labels:
app: store
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchexpressions:
- key: app
operator: In
values:
- store
topologyKey: "kubernetes.io/hostname"
containers:
- name: redis-server
image: redis:3.2-alpine
在阿里云k8s控制台在这里进行设置:



