Azure Kubernetes - 每个节点只执行一个部署?
Azure Kubernetes - Enforce only one deployment per node?
我目前正在 Azure Kubernetes 中为生产环境创建一个 Kubernetes 集群。在我的集群中,节点池中有 2 个节点 - pool1。
现在,我想部署 2 个应用程序,但是这两个应用程序都将使用容器端口 5000,并且由于某些原因我将无法更改端口。
为简单起见,除了部署名称外,我为两个部署保留了相同的清单
部署清单 - 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
部署清单 - 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 中每个节点只允许一个部署(但不限制其他 pods,如代理、sidecar)。
最后应该是deployment-1到node-x,deployment-2到node-y,请指点。
你可以在你的情况下使用 nodeSelector:
nodeSelector
is the simplest recommended form of node selection
constraint. nodeSelector
is a field of PodSpec
. It specifies a map
of key-value pairs. For the pod to be eligible to run on a node, the
node must have each of the indicated key-value pairs as labels (it can
have additional labels as well). The most common usage is one
key-value pair.
nodeSelector
是节点选择约束的一种形式。 nodeSelector
是 PodSpec 的一个字段。这是一个简单的 Pod 调度功能,允许将 Pod 调度到标签与用户指定的 nodeSelector
标签相匹配的节点上。
还有Affinity and anti-affinity as well as Inter-pod affinity and anti-affinity that you could consider using. Notice the More Practical Use-cases应该符合你的要求:
Interpod Affinity
and AntiAffinity
can be even more useful when they
are used with higher level collections such as ReplicaSets,
StatefulSets, Deployments, etc. One can easily configure that a set of
workloads should be co-located in the same defined topology, eg., the
same node.
您可以在链接的文档中找到更多详细信息和示例。
我目前正在 Azure Kubernetes 中为生产环境创建一个 Kubernetes 集群。在我的集群中,节点池中有 2 个节点 - pool1。
现在,我想部署 2 个应用程序,但是这两个应用程序都将使用容器端口 5000,并且由于某些原因我将无法更改端口。
为简单起见,除了部署名称外,我为两个部署保留了相同的清单
部署清单 - 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
部署清单 - 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 中每个节点只允许一个部署(但不限制其他 pods,如代理、sidecar)。
最后应该是deployment-1到node-x,deployment-2到node-y,请指点。
你可以在你的情况下使用 nodeSelector:
nodeSelector
is the simplest recommended form of node selection constraint.nodeSelector
is a field ofPodSpec
. It specifies a map of key-value pairs. For the pod to be eligible to run on a node, the node must have each of the indicated key-value pairs as labels (it can have additional labels as well). The most common usage is one key-value pair.
nodeSelector
是节点选择约束的一种形式。 nodeSelector
是 PodSpec 的一个字段。这是一个简单的 Pod 调度功能,允许将 Pod 调度到标签与用户指定的 nodeSelector
标签相匹配的节点上。
还有Affinity and anti-affinity as well as Inter-pod affinity and anti-affinity that you could consider using. Notice the More Practical Use-cases应该符合你的要求:
Interpod
Affinity
andAntiAffinity
can be even more useful when they are used with higher level collections such as ReplicaSets, StatefulSets, Deployments, etc. One can easily configure that a set of workloads should be co-located in the same defined topology, eg., the same node.
您可以在链接的文档中找到更多详细信息和示例。