节点选择器中的正则

发布于 01-22 10:42 字数 292 浏览 1 评论 0原文

我有4个K8的节点,例如苹果,球,猫,戴尔节点。如果我想为选择性节点分配一个POD(使用的类型是部署/statefullset),那么我可以为其使用node_selector。我将实现节点的垂直自动化。如果发生节点的自动化,则POD可以分配给任何节点。我需要仅使用节点选择器来完成此操作。所以可以做什么。节点选择器或任何想法中是否有任何可能的正则是可能的? 我在下面尝试了一个,但无法实现

nodeSelector:
   kubernetes.io/hostname: "apple([-A-Za-z0-9_.]*)"

I have 4 k8's nodes, let's say apple, ball, cat, dell nodes. If I want to assign a pod(the kind used is deployment/statefullset) to a selective node then I could use node_selector for it. I'm going to implement vertical autoscaling of nodes. If autoscaling of node occurs then, the pod can allocate to any nodes. I need this to be done using node selector only. So what could be done. Is there any possibility of regex in node selector or any idea ?
I tried a below but unachievable

nodeSelector:
   kubernetes.io/hostname: "apple([-A-Za-z0-9_.]*)"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

仄言2025-01-29 10:42:21

这是节点标签进行营救的区域。您应该在创建阶段标记节点。如果您在EKS上(因为选择了EC2标签),则在使用带有自动缩放组的节点组时,应添加自动标签。如果您使用任何其他K8S发行版,则可以在Ansible/用户数据脚本上进行。

基本上,您可以为每个“ Apple,Ball,Cat,Dell”节点创建多个自动化组,并分配节点标签,例如:“节点组:Apple”。然后,您可以在pod spec上使用此信息:(您应该仅使用首选或每个节点组所需的这只是一个示例以向您展示这两个)

spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: node-group
            operator: In
            values:
            - cat
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: node-group
            operator: In
            values:
            - apple

您可以在Kubernetes Docs上了解更多信息:< a href =“ https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/”分配 - 播放节点/

This is an area where node labels comes to rescue. You should label your nodes in the creation phase. If you are on EKS(because you selected ec2 tag), it should add automatic labels when you use node groups with auto scaling groups. If you are using any other k8s distribution you can do it on ansible/user data scripts.

Basically you can create multiple autoscaling groups for each "apple, ball, cat, dell" nodes and assign them node labels like: "node-group: apple". Then you can use this on pod spec:(you should use only preferred or required per node-group this is just an example to show you both)

spec:
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
        - matchExpressions:
          - key: node-group
            operator: In
            values:
            - cat
      preferredDuringSchedulingIgnoredDuringExecution:
      - weight: 1
        preference:
          matchExpressions:
          - key: node-group
            operator: In
            values:
            - apple

You can learn more about this on the kubernetes docs: https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文