问题描述
我在一个群集中有5个节点(测试)。 我已将它们标记为以下内容:
节点:
- namespace = A
- namespace = A
- namespace = B
- namespace = B
- namespace = C
我应用了污点和容差,nodeAffinity和podAntiAffinity。我们的节点已启用自动缩放。但是,我们的节点没有扩大规模,所有吊舱都在1个节点中进行。 我在此链接Kubernetes: Evenly distribute the replicas across the cluster中已读到,使用podAntiAffinity,节点亲和力,污点和公差不能保证这一要求。我们的要求是,应在节点上均匀部署1个pod,并相应地进行扩展。
我想念什么?
apiVersion: apps/v1
kind: StatefulSet
Metadata:
name: prometheus
labels:
app: prometheus
spec:
serviceName: "prometheus"
selector:
matchLabels:
name: prometheus
template:
Metadata:
labels:
name: prometheus
app: prometheus
spec:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeselectorTerms:
- matchExpressions:
- key: namespace
operator: In
values:
- A
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- podAffinityTerm:
labelSelector:
matchExpressions:
- key: app
operator: In
values:
- prometheus
topologyKey: kubernetes.io/hostname
weight: 100
containers:
- name: prometheus
image: quay.io/prometheus/prometheus:v2.6.0
resources:
limits:
memory: 200Mi
requests:
cpu: 100m
memory: 200Mi
terminationGracePeriodSeconds: 30
tolerations:
- key: namespace
operator: Equal
value: A
解决方法
您是否尝试过nodeSelector
,它将在您将标签附加到的节点上安排容器?
nodeSelector:
namespace: A