gpt4 book ai didi

kubernetes - 如何跨节点分布部署?

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

我有一个 Kubernetes 部署,看起来像这样(用“....”替换了名称和其他内容):

# Please edit the object below. Lines beginning with a '#' will be ignored,
# and an empty file will abort the edit. If an error occurs while saving this file will be
# reopened with the relevant failures.
#
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
annotations:
deployment.kubernetes.io/revision: "3"
kubernetes.io/change-cause: kubectl replace deployment ....
-f - --record
creationTimestamp: 2016-08-20T03:46:28Z
generation: 8
labels:
app: ....
name: ....
namespace: default
resourceVersion: "369219"
selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/....
uid: aceb2a9e-6688-11e6-b5fc-42010af000c1
spec:
replicas: 2
selector:
matchLabels:
app: ....
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
app: ....
spec:
containers:
- image: gcr.io/..../....:0.2.1
imagePullPolicy: IfNotPresent
name: ....
ports:
- containerPort: 8080
protocol: TCP
resources:
requests:
cpu: "0"
terminationMessagePath: /dev/termination-log
dnsPolicy: ClusterFirst
restartPolicy: Always
securityContext: {}
terminationGracePeriodSeconds: 30
status:
availableReplicas: 2
observedGeneration: 8
replicas: 2
updatedReplicas: 2

我观察到的问题是 Kubernetes 将两个副本(在我要求的部署中需要两个)放置在同一节点上。如果该节点出现故障,我会丢失两个容器并且服务也会离线。

我希望 Kubernetes 做的是确保它不会在容器类型相同的同一节点上加倍容器 - 这只会消耗资源,不会提供任何冗余。我浏览了有关部署、副本集、节点等的文档,但找不到任何可以让我告诉 Kubernetes 执行此操作的选项。

有没有办法告诉 Kubernetes 我想要一个容器在节点之间有多少冗余?

编辑:我不确定标签是否有效;标签限制节点的运行位置,以便它可以访问本地资源(SSD)等。我想做的就是确保节点离线时不会停机。

最佳答案

There is now a proper way of doing this.如果您只想将其分布在所有节点上,则可以使用“kubernetes.io/hostname”中的标签。这意味着如果您有一个 Pod 的两个副本和两个节点,如果它们的名称不同,每个副本都应该获得一个。

示例:

apiVersion: apps/v1
kind: Deployment
metadata:
name: my-service
labels:
app: my-service
spec:
replicas: 2
selector:
matchLabels:
app: my-service
template:
metadata:
labels:
app: my-service
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: my-service
containers:
- name: pause
image: k8s.gcr.io/pause:3.1

关于kubernetes - 如何跨节点分布部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39092090/

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