[英]Azure Kubernetes - Enforce only one deployment per node?
I'm currently creating a Kubernetes cluster in Azure Kubernetes for a production environment.我目前正在 Azure Kubernetes 中为生产环境创建 Kubernetes 集群。 In my cluster, I will have 2 nodes in the node pool - pool1.
在我的集群中,我将在节点池中有 2 个节点 - pool1。
Now, I want to deploy 2 applications however both the application will use the container port 5000 and I will not be able to change the ports due to some reasons.现在,我想部署 2 个应用程序,但是这两个应用程序都将使用容器端口 5000,并且由于某些原因我将无法更改端口。
For simplicity, I kept the same manifest for both deployments except the name of the deployment为简单起见,除了部署名称之外,我为两个部署保留了相同的清单
Deployment manifest - 1:部署清单 - 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
Deployment manifest - 2:部署清单 - 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
As both the deployments uses the same containerPort, the 2nd deployment fails as it is deployed on the same node where 1st app is deployed.由于两个部署使用相同的 containerPort,第二个部署失败,因为它部署在部署第一个应用程序的同一节点上。
I want to enforce a policy where only one deployment (but not restricting other pods like proxy, sidecar) is allowed per node in Azure Kubernetes.我想强制执行一项策略,其中 Azure Kubernetes 中的每个节点只允许一个部署(但不限制其他 pod,如代理、sidecar)。
At the end, deployment-1 should go to node-x and deployment-2 goes to node-y, please suggest.最后,deployment-1 应该去 node-x,deployment-2 去 node-y,请建议。
What you could use in your case is the nodeSelector :您可以在您的情况下使用的是nodeSelector :
nodeSelector
is the simplest recommended form of node selection constraint.nodeSelector
是最简单的推荐形式的节点选择约束。nodeSelector
is a field ofPodSpec
.nodeSelector
是的场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).
要使 pod 有资格在节点上运行,该节点必须将每个指定的键值对作为标签(它也可以有其他标签)。 The most common usage is one key-value pair.
最常见的用法是一对键值对。
nodeSelector
is one of the forms of node selection constraint. nodeSelector
是节点选择约束的一种形式。 nodeSelector
is a field of PodSpec. nodeSelector
是nodeSelector
的一个字段。 This is a simple Pod scheduling feature that allows scheduling a Pod onto a node whose labels match the nodeSelector
labels specified by the user.这是一个简单的 Pod 调度功能,允许将 Pod 调度到标签与用户指定的
nodeSelector
标签匹配的节点上。
There are also Affinity and anti-affinity as well as Inter-pod affinity and anti-affinity that you could consider using.您还可以考虑使用Affinity 和 anti-affinity以及Inter-pod 亲和性和反亲和性。 Notice the More Practical Use-cases as it should fit your requirements:
请注意更实用的用例,因为它应该符合您的要求:
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.当 Interpod
Affinity
和AntiAffinity
与更高级别的集合(例如 ReplicaSets、StatefulSets、 Deployments等)一起使用时,它们会更加有用。可以轻松配置一组工作负载应位于相同定义的拓扑中,例如,同一个节点。
You can find more details and examples in the linked documentation.您可以在链接的文档中找到更多详细信息和示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.