gpt4 book ai didi

Azure Kubernetes - 每个节点仅执行一次部署?

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

我目前正在 Azure Kubernetes 中为生产环境创建 Kubernetes 集群。在我的集群中,节点池中有 2 个节点 - pool1。

现在,我想部署 2 个应用程序,但是这两个应用程序都将使用容器端口 5000,并且由于某些原因我将无法更改端口。

为了简单起见,除了部署名称之外,我为两个部署保留了相同的 list

部署 list - 1:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-1
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1
ports:
- containerPort: 5000

部署 list - 2:

apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment-2
spec:
selector:
matchLabels:
app: nginx
replicas: 1
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.16.1
ports:
- containerPort: 5000

由于两个部署使用相同的容器端口,因此第二个部署失败,因为它部署在部署第一个应用程序的同一节点上。

我想强制执行一项策略,其中 Azure Kubernetes 中的每个节点仅允许一个部署(但不限制代理、sidecar 等其他 Pod)。

最后,deployment-1应该转到node-x,deployment-2应该转到node-y,请建议。

最佳答案

您可以在您的情况下使用 nodeSelector :

nodeSelector is the simplest recommended form of node selectionconstraint. nodeSelector is a field of PodSpec. It specifies a mapof key-value pairs. For the pod to be eligible to run on a node, thenode must have each of the indicated key-value pairs as labels (it canhave additional labels as well). The most common usage is onekey-value pair.

nodeSelector是节点选择约束的形式之一。 nodeSelector 是 PodSpec 的一个字段。这是一个简单的 Pod 调度功能,允许将 Pod 调度到标签与用户指定的 nodeSelector 标签匹配的节点上。

还有Affinity and anti-affinity以及Inter-pod affinity and anti-affinity您可以考虑使用。请注意More Practical Use-cases因为它应该符合您的要求:

Interpod Affinity and AntiAffinity can be even more useful when theyare used with higher level collections such as ReplicaSets,StatefulSets, Deployments, etc. One can easily configure that a set ofworkloads should be co-located in the same defined topology, eg., thesame node.

您可以在链接的文档中找到更多详细信息和示例。

关于Azure Kubernetes - 每个节点仅执行一次部署?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64329183/

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