[英]I am trying to create an EKS cluster with cluster.yaml deployment.yaml and service.yaml but nodeSelector is not working as expected
I am trying to create an EKS cluster which has Jenkins running on Jenkins nodes and Nexus running on Nexus nodes for this I am trying to use nodeSelector which is not working as expected I don't understand which part I am missing.我正在尝试创建一个 EKS 集群,它有 Jenkins 在 Jenkins 节点上运行,Nexus 在 Nexus 节点上运行,为此我正在尝试使用 nodeSelector,它没有按预期工作我不明白我缺少哪一部分。
My cluster.yaml for creating the EKS cluster is as follows:我的创建EKS集群的cluster.yaml如下:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: Devops-Test
region: ap-south-1
vpc:
id: vpc-xxxxxx
cidr: "192.168.0.0/16"
subnets:
public:
ap-south-1a:
id: subnet-xxxx
ap-south-1b:
id: subnet-xxxx
private:
ap-south-1a:
id: subnet-xxxx
ap-south-1b:
id: subnet-xxxx
nodeGroups:
- name: jenkins-public-node-group
tags: { role: "jenkins" }
instanceType: t2.medium
desiredCapacity: 2
- name: jenkins-private-node-group
tags: { role: "jenkins" }
instanceType: t2.medium
desiredCapacity: 2
privateNetworking: true
- name: nexus-public-node-group
tags: { role: "nexus" }
instanceType: t2.medium
desiredCapacity: 2
- name: nexus-private-node-group
tags: { role: "nexus" }
instanceType: t2.medium
desiredCapacity: 2
privateNetworking: true
My deployment.yaml is as follows我的deployment.yaml如下
apiVersion: apps/v1
kind: Deployment
metadata:
name: devops-tools
namespace: devops
spec:
replicas: 2
selector:
matchLabels:
role: jenkins
template:
metadata:
labels:
role: jenkins
spec:
nodeSelector:
role: jenkins
containers:
- name: jenkins
image: jenkins:2.60.3
ports:
- containerPort: 8080
Finally my service.yaml is as follows最后我的service.yaml如下
apiVersion: v1
kind: Service
metadata:
name: jenkins-service
namespace: devops
spec:
type: NodePort
selector:
role: jenkins
ports:
- nodePort: 31429
port: 8080
targetPort: 8080
I am expecting Jenkins to run only on nodes tagged with role:jenkins but it is also running on nodes without that tag I have even tried applying label with我期望 Jenkins 仅在标记有角色的节点上运行:jenkins 但它也在没有该标记的节点上运行我什至尝试过应用 label
kubectl label nodes role=jenkins kubectl label 节点角色=詹金斯
and then applying deployment.yaml but deployment still happens on nodes without that label.然后应用 deployment.yaml 但部署仍然发生在没有 label 的节点上。
You should use labels
instead of tags
in your cluster.yaml
file.您应该在cluster.yaml
文件中使用labels
而不是tags
。
See these docs for more information.有关详细信息,请参阅这些文档。
Tags apply to AWS tags, which are irrelevant to Kube.netes.标签适用于 AWS 标签,与 Kube.netes 无关。 Only labels are relevant when trying to apply node selectors.尝试应用节点选择器时,只有标签是相关的。
BTW - you should also make sure that your node selectors are applied as prescribed to your pods - since pods shouldn't be allowed on nodes without the specified label. From the behavior you are describing - it seems like the pods are being created without a node selector at all.顺便说一句 - 你还应该确保你的节点选择器按照规定应用到你的 pod - 因为在没有指定 label 的节点上不应该允许 pod。从你描述的行为来看 - 似乎创建的 pod 没有节点选择器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.