為什麼 Amazon EKS Pod 停留在 ContainerCreating 狀態,並顯示錯誤 "failed to create pod sandbox (無法建立 Pod 沙盒)"?
Amazon Elastic Kubernetes Service (Amazon EKS) Pod 停留在 ContainerCreating 狀態,並顯示錯誤 "failed to create pod sandbox (無法建立 Pod 沙盒)"。
解決方案
由於多種原因,Amazon EKS Pod 可能會停留在 ContainerCreating 狀態,並顯示網路連線錯誤。根據您收到的錯誤訊息,使用以下疑難排解步驟。
來自常駐程式的錯誤回應: failed to start shim: fork/exec /usr/bin/containerd-shim: resource temporarily unavailable: unknown (啟動 shim 失敗: fork/exec /usr/bin/containerd-shim: 暫時無法取得資源: 未知)
發生此錯誤是由於定義的最大 PID 或最大檔案數的核心設定導致了作業系統限制。
執行下列命令以取得您 Pod 的相關資訊:
$ kubectl describe pod example_pod
範例輸出:
kubelet, ip-xx-xx-xx-xx.xx-xxxxx-x.compute.internal Failed to create pod sandbox: rpc error: code = Unknown desc = failed to start sandbox container for pod "example_pod": Error response from daemon: failed to start shim: fork/exec /usr/bin/containerd-shim: resource temporarily unavailable: unknown
若要暫時解決問題,請重新啟動節點。
若要對問題進行疑難排解,請執行以下操作:
- 收集節點日誌。
- 檢閱 Docker 日誌是否存在錯誤 "dockerd[4597]: runtime/cgo: pthread_create failed: Resource temporarily unavailable (dockerd[4597]: runtime/cgo: pthread_create failed:資源暫時無法使用)"。
- 檢閱 Kubelet 日誌中是否有下列錯誤:
- "kubelet[5267]: runtime: failed to create new OS thread (have 2 already; errno=11)" (kubelet[5267]:執行時間:無法建立新的作業系統執行緒 (已經有 2 個執行緒;errno=11))
- "kubelet[5267]: runtime: may need to increase max user processes (ulimit -u) (kubelet[5267]:執行時間:可能需要增加使用者處理序上限 (ulimit -u))"。
- 透過執行 ps 命令識別殭屍處理程序。輸出中列出為 Z 狀態的所有處理程序都是殭屍處理程序。
Network plugin cni failed to set up pod network: add cmd: failed to assign an IP address to container (網路插件 cni 無法設定 Pod 網路: 添加 cmd: 無法將 IP 地址指派給容器)
此錯誤指出容器網路界面 (CNI) 無法為新佈建的 Pod 指派 IP 地址。
以下是 CNI 無法為新建立的 Pod 提供 IP 地址的原因:
- 執行個體使用了允許的最大彈性網路界面和 IP 地址。
- Amazon Virtual Private Cloud (Amazon VPC) 子網路的 IP 地址計數為零。
以下是網路界面 IP 地址耗盡的範例:
Instance type Maximum network interfaces Private IPv4 addresses per interface IPv6 addresses per interface t3.medium 3 6 6
在此範例中,執行個體 t3.medium 最多有 3 個網路界面,每個網路界面最多有 6 個 IP 地址。第一個 IP 地址用於節點,且無法指派。這會留下 17 個網路界面可以配置的 IP 地址。
本機 IP 地址管理常駐程式 (ipamD) 日誌會在網路界面用完 IP 地址時顯示下列訊息:
"ipamd/ipamd.go:1285","msg":"Total number of interfaces found: 3 " "AssignIPv4Address: IP address pool stats: total: 17, assigned 17" "AssignPodIPv4Address: ENI eni-abc123 does not have available addresses"
執行下列命令以取得您 Pod 的相關資訊:
$ kubectl describe pod example_pod
範例輸出:
Warning FailedCreatePodSandBox 23m (x2203 over 113m) kubelet, ip-xx-xx-xx-xx.xx-xxxxx-x.compute.internal (combined from similar events): Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" network for pod "provisioning-XXXXXXXXXXXXXXX": networkPlugin cni failed to set up pod "provisioning-XXXXXXXXXXXXXXX" network: add cmd: failed to assign an IP address to container
檢閱子網路以識別子網路是否用盡了可用 IP 地址。您可以在 Amazon VPC 主控台的子網路區段下檢視每個子網路的可用 IP 地址。
Subnet: XXXXXXXXXX IPv4 CIDR Block 10.2.1.0/24 Number of allocated ips 254 Free address count 0
若要解決此問題,請將部分工作負載縮減規模以釋放可用的 IP 地址。如果有其他子網路容量可用,您可以選擇擴展節點。您還可以建立其他子網路。如需詳細資訊,請參閱如何將多個 CIDR 範圍用於 Amazon EKS? 依照使用新 CIDR 範圍建立子網路區段中的指示進行。
Error while dialing dial tcp 127.0.0.1:50051: connect: connection refused (撥號時發生錯誤 127.0.0.1:50051: 連線: 連線遭拒)
此錯誤表示 aws-node Pod 無法與 IPAM 通訊,因為 aws-node Pod 無法在節點上執行。
執行下列命令以取得 Pod 的相關資訊:
$ kubectl describe pod example_pod
$ kubectl describe pod/aws-node-XXXXX -n kube-system
輸出結果範例:
Warning FailedCreatePodSandBox 51s kubelet, ip-xx-xx-xx-xx.ec2.internal Failed create pod sandbox: rpc error: code = Unknown desc = [failed to set up sandbox container "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" network for pod "example_pod": NetworkPlugin cni failed to set up pod "example_pod" network: add cmd: Error received from AddNetwork gRPC call: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:50051: connect: connection refused", failed to clean up sandbox container
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" network for pod "example_pod": NetworkPlugin cni failed to teardown pod "example_pod" network: del cmd: error received from DelNetwork gRPC call: rpc error: code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:50051: connect: connection refused"]
若要疑難排解此問題,請確認 aws-node Pod 已部署且處於執行中狀態:
kubectl get pods --selector=k8s-app=aws-node -n kube-system
**注意:**請確定您正為叢集版本執行 VPC CNI 外掛程式的正確版本。
由於活躍度和準備度探查錯誤,Pod 可能處於擱置中狀態。根據相容性表格,請確保您擁有最新推薦的 VPC CNI 附加元件版本。
執行下列命令,以檢視 aws-node Pod 中的最後一個日誌訊息:
kubectl -n kube-system exec -it aws-node-XXX-- tail -f /host/var/log/aws-routed-eni/ipamd.log | tee ipamd.log
由於 Dockershim 掛載點無法掛載,因此也可能會發生此問題。以下是發生此問題時可以收到的範例訊息:
Getting running pod sandboxes from \"unix:///var/run/dockershim.sock\ Not able to get local pod sandboxes yet (attempt 1/5): rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial unix /var/run/dockershim.sock: connect: no such file or director
前面的訊息指出 Pod 無法掛載 var/run/dockershim.sock。
若要解決此問題,請嘗試以下操作:
- 重新啟動 aws-node Pod 以重新對應掛載點。
- 封鎖節點,並縮放節點群組中的節點。
- 將 Amazon VPC 網路界面升級至支援的最新叢集版本。
如果您在 AWS 管理主控台中將 CNI 新增為受管外掛程式,則 aws-node 將無法探查。受管外掛程式會覆寫服務帳戶。但是,服務帳户未設定選定的角色。若要解決此問題,請從 AWS 管理主控台關閉外掛程式,並使用清單檔案建立服務帳户。或者,編輯目前 aws-node 服務帳户以新增受管外掛程式上使用的角色。
Network plugin cni failed to set up pod "my-app-xxbz-zz" network: failed to parse Kubernetes args: pod does not have label vpc.amazonaws.com/PrivateIPv4Address (網路插件 cni 無法設定 Pod "my-app-xxbz-zz" 網路: 無法分析 Kubernetes args: Pod 沒有標籤 vpc.amazonaws.com/PrivateIPv4Address)
由於以下原因收到此錯誤:
- Pod 未正常執行。
- Pod 使用的憑證未成功建立。
此錯誤與 Amazon EKS 叢集上執行 Windows 工作負載所需的 Amazon VPC 許可控制器 Webhook 相關。此 Webhook 是在 kube-system 命名空間中執行 Pod 的外掛程式。此元件在 Linux 節點上執行,並允許 Windows 節點上傳入的 Pod 聯網。
執行下列命令以取得受影響的 Pod 清單:
kubectl get pods
範例輸出:
my-app-xxx-zz 0/1 ContainerCreating 0 58m <none> ip-XXXXXXX.compute.internal <none> my-app-xxbz-zz 0/1 ContainerCreating 0 58m <none>
執行下列命令以取得 Pod 的相關資訊:
$ kubectl describe pod my-app-xxbz-zz
範例輸出:
Failed to create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" network for pod "<POD_ANME>": networkPlugin cni failed to set up pod "example_pod" network: failed to parse Kubernetes args: pod does not have label vpc.amazonaws.com/PrivateIPv4Address
Reconciler worker 1 starting processing node ip-XXXXXXX.compute.internal. Reconciler checking resource vpc.amazonaws.com/PrivateIPv4Address warmpool size 1 desired 3 on node ip-XXXXXXX.compute.internal. Reconciler creating resource vpc.amazonaws.com/PrivateIPv4Address on node ip-XXXXXXX.compute.internal. Reconciler failed to create resource vpc.amazonaws.com/PrivateIPv4Address on node ip-XXXXXXX.compute.internal: node has no open IP address slots.
Windows 節點支援每個節點一個網路界面。每個 Windows 節點可以執行與每個網路介面可用 IP 地址相同數目減一的 Pod。若要解決此問題,請縱向擴展 Windows 節點的數目。
如果 IP 地址不是問題,請檢閱 Amazon VPC 許可控制器 Pod 事件和日誌。
執行以下命令以確認已建立 Amazon VPC 許可控制器 Pod:
$ kubectl get pods -n kube-system OR kubectl get pods -n kube-system | grep "vpc-admission"
範例輸出:
vpc-admission-webhook-5bfd555984-fkj8z 1/1 Running 0 25m
執行下列命令以取得 Pod 的相關資訊:
$ kubectl describe pod vpc-admission-webhook-5bfd555984-fkj8z -n kube-system
範例輸出:
Normal Scheduled 27m default-scheduler Successfully assigned kube-system/vpc-admission-webhook-5bfd555984-fkj8z to ip-xx-xx-xx-xx.ec2.internal Normal Pulling 27m kubelet Pulling image "xxxxxxx.dkr.ecr.xxxx.amazonaws.com/eks/vpc-admission-webhook:v0.2.7" Normal Pulled 27m kubelet Successfully pulled image "xxxxxxx.dkr.ecr.xxxx.amazonaws.com/eks/vpc-admission-webhook:v0.2.7" in 1.299938222s Normal Created 27m kubelet Created container vpc-admission-webhook Normal Started 27m kubelet Started container vpc-admission-webhook
執行下列命令以檢查 Pod 日誌是否有任何組態問題:
$ kubectl logs vpc-admission-webhook-5bfd555984-fkj8z -n kube-system
範例輸出:
I1109 07:32:59.352298 1 main.go:72] Initializing vpc-admission-webhook version v0.2.7. I1109 07:32:59.352866 1 webhook.go:145] Setting up webhook with OSLabelSelectorOverride: windows. I1109 07:32:59.352908 1 main.go:105] Webhook Server started. I1109 07:32:59.352933 1 main.go:96] Listening on :61800 for metrics and healthz I1109 07:39:25.778144 1 webhook.go:289] Skip mutation for as the target platform is .
前面的輸出顯示容器已成功啟動。然後,Pod 會將 vpc.amazonaws.com/PrivateIPv4Address 標籤新增至應用程式 Pod。不過,應用程式 Pod 的清單檔案必須包含節點選取器或親和性,以便在 Windows 節點上排程 Pod。
疑難排解問題的其他選項包括驗證下列項目:
- 您在 kube-system 命名空間中部署了 Amazon VPC 許可控制器 Pod。
- 日誌或事件未指向過期的憑證。如果憑證已過期且 Windows Pod 停留在容器建立狀態中,您必須刪除並重新部署 Pod。
- 沒有任何逾時或 DNS 相關問題。
如果您不建立 Amazon VPC 許可控制器,請為您的叢集開啟 Windows 支援。
**重要事項:**Amazon EKS 不需要您開啟 Amazon VPC 許可控制器來支援 Windows 節點群組。如果您已開啟 Amazon VPC 許可控制器,請從資料平面移除舊版 Windows 支援。
相關資訊

相關內容
- 已提問 4 個月前lg...
- 已提問 1 個月前lg...
- 已提問 1 個月前lg...
- 已提問 5 個月前lg...
- 已提問 6 個月前lg...
- AWS 官方已更新 4 個月前
- AWS 官方已更新 8 個月前
- AWS 官方已更新 1 年前