Kubectl 将部署应用到指定的节点组 - ​​AWS EKS

Kubectl apply Deployment to specified Node Group - AWS EKS

我在我的 EKS 集群 中创建了多个堆栈(节点组),并且每个组 运行 在 不同的实例类型上 (例如,GPU 实例上的一组 运行s)。我在 mapRolesaws-auth-cm.yaml 文件中为每个节点组添加了一个条目。现在我想在另一个上部署一些 Deployments。部署文件如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-1
spec:
  replicas: 1
  selector:
    matchLabels:
      component: component-1
  template:
    metadata:
      labels:
        component: component-1
    spec:
      containers:
        - name: d1
          image: docker-container
          ports:
            - containerPort: 83

文档显示我可以运行标准命令kubectl apply。有没有办法指定组?也许像

kubectl apply -f server-deployment.yaml -group node-group-1

很遗憾,您提到的内容不存在,但您可以阅读 Affinity,它应该可以解决您的问题。

TL;DR 您必须在节点上添加标签或使用现有标签,并使用这些标签将 pods 分配给正确的节点。

假设您有标签 beta.kubernetes.io/instance-type=highmem

apiVersion: apps/v1
kind: Deployment
metadata:
  name: deployment-1
spec:
  replicas: 1
  selector:
    matchLabels:
      component: component-1
  template:
    metadata:
      labels:
        component: component-1
    spec:
      affinity:
        nodeAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            nodeSelectorTerms:
            - matchExpressions:
              - key: beta.kubernetes.io/instance-typ
                operator: In
                values:
                - highmem
      containers:
        - name: d1
          image: docker-container
          ports:
            - containerPort: 83

您可以使用 taints and tolerations 来确保您的 pods 最终出现在正确的节点上。当您有异构节点时,这是一个很好的做法。

例如,在我的部署中,我们有 2 个 类 节点,一个连接了 NVMe SSD,另一个没有连接。它们都受到不同的污染,运行 顶部的部署指定了容忍度,以确保它们最终只出现在具有该特定污染的节点上。

例如,节点将具有:

spec:
    ...
    taints:
    - effect: NoSchedule
      key: role
      value: gpu-instance

并且必须在这些节点之一上调度的 pod 必须具有:

spec:
    tolerations:
    - effect: NoSchedule
      key: role
      operator: Equal
      value: gpu-instance

完成此设置后,您只需执行常规 kubectl apply,pods 将正确定位到节点。 请注意,这是一种比节点选择器和标签更灵活的方法,因为它可以为您提供更细粒度的控制和可配置的驱逐行为。

nodeSelector 也应该适用于此,只要您标记了节点

这里有示例和更多信息:https://eksworkshop.com/beginner/140_assigning_pods/node_selector/ and here https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector