kubernetes 无法放置Pod,

6ojccjat  于 2023-10-17  发布在  Kubernetes
关注(0)|答案(1)|浏览(101)

无论我多么努力地调整它,我都无法使Pod均匀地分布在AWS EKS集群中的四个节点上。这是豆荚山药

nodeSelector:
    node_env: my-node-name
  affinity:
    nodeAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        nodeSelectorTerms:
          - matchExpressions:
            - key: node_env
              operator: In
              values:
                - my-node-name
    podAntiAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
            - key: app
              operator: In
              values:
              - my-app-name
          topologyKey: topology.kubernetes.io/hostname
    podAffinity:
      requiredDuringSchedulingIgnoredDuringExecution:
        - labelSelector:
            matchExpressions:
              - key: app
                operator: In
                values:
                  - my-app-name
          topologyKey: node_env
  topologySpreadConstraints:
    - maxSkew: 1
      nodeAffinityPolicy: Honor
      topologyKey: kubernetes.io/hostname
      whenUnsatisfiable: DoNotSchedule
      labelSelector:
        matchExpressions:
        - key: app
          operator: In
          values:
          - my-app-name

EKS集群下有七个节点-四个用于apps pod,两个用于envoy pod,一个用于杂项pod。
我希望放置一个豆荚的四个副本,并均匀地分布在这些应用程序的豆荚节点。

fv2wmkja

fv2wmkja1#

虽然可以将topologySpreadConstraintspodAntiAffinity/podAffinity一起使用,但我不建议这样做。我建议您查看以下答案以进行比较:
https://stackoverflow.com/a/73159361/19206466
如果您的目标是实现跨节点的均匀分布,则可以通过组合nodeAffinitytopologySpreadConstraints来实现。使用nodeAffinity选择适当的节点,确保您的EKS节点附加了node_env: my-node-name标签。要列出节点的标签,可以使用kubectl describe node <eks_node>
然后,使用topologySpreadConstraints将pod均匀分布在这些节点上;设置maxSkew: 1应该足以在所选节点上均匀分布Pod。此外,请确保app: my-app-name标签存在于您的app pod模板中。

**重要提示:**如果您正在为EKS群集使用自动缩放器(例如,Karpenter)您可能还需要定义自Kubernetes 1.25以来支持的minDomainstopologySpreadConstraints属性。在您的情况下,它将定义所需EKS节点的最小数量。

有关详细信息,请参阅:https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/#spread-constraint-definition

affinity:
  nodeAffinity:
    requiredDuringSchedulingIgnoredDuringExecution:
      nodeSelectorTerms:
        - matchExpressions:
          - key: node_env
            operator: In
            values:
              - my-node-name
topologySpreadConstraints:
  - maxSkew: 1
    nodeAffinityPolicy: Honor
    topologyKey: kubernetes.io/hostname
    whenUnsatisfiable: DoNotSchedule
    labelSelector:
      matchLabels:
        app: my-app-name

参考文献

相关问题