gpt4 book ai didi

docker - 在不同节点上运行两个 kubernetes pod

转载 作者:行者123 更新时间:2023-12-02 08:54:18 25 4
gpt4 key购买 nike

有没有办法告诉 Kubernetes 永远不要在同一个节点上运行两个 Pod,例如我有两个 Pod 副本,我希望它们始终分布在 zone1/zone2 上,而不是分布在同一区域在一起。

apiVersion: app/v1
kind: Deployment
metadata:
name: testApp
labels:
app: testApp-front
namespace:
spec:
replicas: 2
selector:
matchLabels:
app: testApp-front
template:
metadata:
labels:
app: testApp-front
spec:
nodeSelector:
failure-domain.beta.kubernetes.io/zone: zone1

最佳答案

似乎可以通过 Interpod Affinity 来完成,您可以看到:

apiVersion: apps/v1
kind: Deployment
metadata:
name: web-server
spec:
selector:
matchLabels:
app: testApp-front
replicas: 3
template:
metadata:
labels:
app: testApp-front
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- testApp-front
topologyKey: "kubernetes.io/hostname"
podAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- store
topologyKey: "kubernetes.io/hostname"
containers:
- name: web-testApp-front
image: nginx:1.12-alpine

您可以看到完整的example here

关于docker - 在不同节点上运行两个 kubernetes pod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56888727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com