为什么我的 pods 没有使用多个节点?

Why are my pods not utilizing multiple nodes?

目前,我在 AWS 上有 2 个节点

NAME                                           STATUS   ROLES    AGE   VERSION
NODE-1-xxx-xxx-xxx-xxx.cn-north-1.compute.internal   Ready    <none>   15d   v1.16.13-eks-2ba888
NODE-2-xxx-xxx-xxx-xxx.cn-north-1.compute.internal   Ready    <none>   13d   v1.16.13-eks-2ba888

这也是我的 CPU 负载的屏幕截图

节点 1

节点 2

我的问题是,每当我将我的应用程序部署到生产环境时,我都会在 NODE 2 上最大化我的 cpu 使用率,这会减慢整个站点的速度

这是我的部署配置

apiVersion: apps/v1
kind: Deployment
metadata:
  name: backend # name of the deployment
  namespace: backend
  labels: # these labels apply to the deployment
    app: root
    component: backend

spec:
  replicas: 2
  minReadySeconds: 20
  selector:
    matchLabels:
      app: root
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: 1
      maxUnavailable: 0
  template:
    metadata:
      labels: # these labels apply to our container
        app: root
        component: backend
        version: xxx_${BITBUCKET_BUILD_NUMBER}
    spec:
      containers:
      - name: backend # name of our container
        image: xxx/xxx_main:${BITBUCKET_BUILD_NUMBER} # the URI that we got from ECR
        imagePullPolicy: Always
        envFrom:
        - configMapRef:
            name: env
        ports:
        - containerPort: 3000 # expose the running contianer on port 3000
          name: backend
          protocol: TCP
        readinessProbe:
          tcpSocket:
            port: backend
          initialDelaySeconds: 20
          periodSeconds: 5
          timeoutSeconds: 1
          successThreshold: 1
          failureThreshold: 20

      imagePullSecrets:
       - name: xxx

我是不是没有适当地扩展这里的内容?如果只使用一个节点,那么拥有两个节点有什么意义呢?我如何正确扩展我的应用程序以使用多个节点?

发生这种情况是因为节点调度算法基于优先级分数,不同的优先级算法对分数有贡献。一种这样的优先级算法是 ImageLocalityPriority,它为已经具有 pod 使用的图像的节点添加正优先级分数。因此,最初,已经拥有 pod 运行 的第一个副本的节点由于 ImageLocalityPriority 而获得了一个小的优先级提升。一旦添加了越来越多的副本,每个节点上 pods 运行 的数量就会变得均匀,因为 BalancedResourceAllocation 等其他优先级也会受到影响。

还有一个 SelectorSpreadPriority 有助于最小化 节点上属于同一服务的 pods 的数量。因此,如果您在创建部署之前创建 service 对象,可能会有所帮助。

要强制 pods 展开,您应该将 inter-pod anti-affinity constraints 添加到 pods。

您还应该考虑将 requests and limits 添加到您的容器中。这有助于分散 pods,因为 LeastRequestedPriority 优先级也开始起作用。(注意: 还有 MostRequestedPriority 为使用的节点增加优先级但默认情况下未启用)。