EKS pod 在 Fargate 部署中卡在 "Pending" 状态?

EKS pod stuck in "Pending" state in Fargate deployment?

所以我使用以下清单为 Fargate 创建了一个 EKS 集群,并且创建成功。我想 运行 Fargate 中的应用程序,而不是 EC2 工作节点中的应用程序,所以我没有创建节点组(正确吗?)。

$ eksctl create -f cluster.yaml
cluster.yaml
------------
metadata:
  name: sandbox
  region: us-east-1
  version: "1.18"

fargateProfiles:
  - name: fp-default
    selectors:
      # All workloads in the "default" Kubernetes namespace will be
      # scheduled onto Fargate:
      - namespace: default
      # All workloads in the "kube-system" Kubernetes namespace will be
      # scheduled onto Fargate:
      - namespace: kube-system
  - name: fp-sandbox
    selectors:
      # All workloads in the "sandbox" Kubernetes namespace matching the
      # following label selectors will be scheduled onto Fargate:
      - namespace: sandbox
        labels:
          env: sandbox
          checks: passed

$ kubectl get nodes
NAME                                     STATUS   ROLES    AGE    VERSION
fargate-ip-192-168-100-23.ec2.internal   Ready    <none>   3h2m   v1.18.8-eks-7c9bda
fargate-ip-192-168-67-135.ec2.internal   Ready    <none>   3h2m   v1.18.8-eks-7c9bda

然后我创建了一个命名空间

$ kubectl create namespace sandbox

现在我在 sandbox 命名空间中创建部署以匹配我的 fp-sandbox Fargate 配置文件中的命名空间,并且卡在 Pending 状态

$ kubectl create deploy hello-world-node --image=redacted.dkr.ecr.us-east-1.amazonaws.com/hello-world-node:latest --namespace=sandbox
$ kubectl get po -n sandbox
NAME                                READY   STATUS    RESTARTS   AGE
hello-world-node-544748b68b-4bghr   0/1     Pending   0          18m

$ kubectl describe pod hello-world-node-544748b68b-4bghr -n sandbox
....
Events:
Type     Reason            Age                 From               Message
----     ------            ----                ----               -------
Warning  FailedScheduling  12s (x15 over 19m)  default-scheduler  0/2 nodes are available: 2 Too many pods.

为什么说0/2 nodes are available?我错过了什么?请记住,我想 运行 Fargate 中的应用程序,而不是 EC2 工作节点中的应用程序。

注意:我可以在本地 运行 容器。它只是一个简单的 NodeJS 应用程序,可以响应“Hello World”。

UPDATE:我在集群中添加了一个 manageNodeGroups,pod 出现了。然而,为什么会这样?为什么没有节点组的 Fargate 中的 pods 运行?

@Chris,你好:)

在您的 YAML 文件中

      # All workloads in the "sandbox" Kubernetes namespace matching the
      # following label selectors will be scheduled onto Fargate:

上面两个句子之间有一个AND条件,所以你的pods应该分配env=sandboxchecks=passed标签。

快速修复

kubectl --namespace sandbox label pods --all env=sandbox
kubectl --namespace sandbox label pods --all checks=passed

更好的修复方法是编写 deployment.yaml 文件并在相关位置添加标签。

参考资料

根据 Meir 的 help/advise(再次大声笑),我改用了部署清单,并且有效。这是

apiVersion: apps/v1
kind: Deployment
metadata:
  name: hello-world-node
  namespace: sandbox
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world-node
      env: sandbox
      checks: passed
  template:
    metadata:
      labels:
        app: hello-world-node
        env: sandbox
        checks: passed
    spec:
      containers:
        - name: hello-world-node
          image: redacted.dkr.ecr.us-east-1.amazonaws.com/hello-world-node:latest
          ports:
            - containerPort: 8080

然后应用

$ kubectl apply -f deployment.yaml
$ kubectl get po -n sandbox
NAME                                READY   STATUS    RESTARTS   AGE
hello-world-node-58f86974c4-7tnzb   1/1     Running   0          3m58s