You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在AWS EKS集群中将Pod部署到同一指定节点

EKS集群中将Deployment所有Pod调度到指定节点的实现方法

完全可以实现,只需要在Deployment的Pod模板中配置调度规则,执行kubectl apply -f <deployment.yaml>后就会自动生效,常用的有两种方案:

方案1:nodeSelector(入门级,配置最简单)

适合明确需要固定绑定到某一个节点的场景,操作步骤如下:

  • 第一步:给目标节点打自定义标签,假设你要指定的节点名称为eks-worker-node-01,执行命令:
    kubectl label nodes eks-worker-node-01 schedule-target=my-app
    
  • 第二步:在Deployment的Pod spec中添加nodeSelector配置,匹配上面打的标签:
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: my-app
    spec:
      replicas: 5
      selector:
        matchLabels:
          app: my-app
      template:
        metadata:
          labels:
            app: my-app
        spec:
          # 新增nodeSelector配置,绑定标签对应的节点
          nodeSelector:
            schedule-target: my-app
          containers:
          - name: my-app
            image: nginx:stable
    

只要你只给一个节点打上schedule-target=my-app标签,该Deployment的所有Pod都会被调度到这个节点上。

方案2:nodeAffinity(进阶版,规则更灵活)

如果需要更灵活的调度策略,比如支持多节点匹配、软亲和(优先调度到目标节点,资源不足时可调度到其他节点),可以用nodeAffinity实现:

  • 强制绑定到指定标签节点的配置示例:
    spec:
      template:
        spec:
          affinity:
            nodeAffinity:
              requiredDuringSchedulingIgnoredDuringExecution:
                nodeSelectorTerms:
                - matchExpressions:
                  - key: schedule-target
                    operator: In
                    values:
                    - my-app
    
  • 如果要配置软亲和规则,只需要把requiredDuringSchedulingIgnoredDuringExecution替换为preferredDuringSchedulingIgnoredDuringExecution即可。

注意事项

  • 调度前请确认目标节点的CPU、内存等剩余资源足够承载该Deployment的所有Pod副本,否则Pod会进入Pending状态
  • 不建议直接用节点默认的kubernetes.io/hostname标签做匹配,EKS节点组滚动更新后节点hostname可能变化,用自定义标签的兼容性更好
  • 如果后续需要更换绑定的节点,只需要把旧节点的自定义标签删除,给新节点打上相同标签即可,无需修改Deployment配置

内容的提问来源于stack exchange,提问作者Hamza J

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 10:24:04