Skaffold 不完全是 运行 所有的服务

Skaffold is not fully running all the services

我正在开发 this dummy project 并尝试通过 Skaffold 使其在本地运行。

我的项目中有 3 个服务(运行分别在端口 300130023003 上连接),通过 NATS server 连接。

问题是:每次 运行 skaffold debug 和 one/more 服务不工作时,我都会遇到不同类型的错误。

有时,我没有收到任何错误,而且所有服务都按预期运行。以下是部分错误:

Waited for <...>s due to client-side throttling, not priority and fairness,
request: GET:https://kubernetes.docker.internal:6443/api/v1/namespaces/default/pods?labelSelector=app%!D(MISSING). <...>%!C(MISSING)app.kubernetes.io%!F(MISSING)managed-by%!D(MISSING)skaffold%!C(MISSING)skaffold.dev%!F(MISSING)run-id%!D(MISSING)<...>` (from `request.go:668`)
- `0/1 nodes are available: 1 Insufficient cpu.` (from deployments)
- `UnhandledPromiseRejectionWarning: NatsError: CONNECTION_REFUSED` (from apps)
- `UnhandledPromiseRejectionWarning: Error: getaddrinfo EAI_AGAIN nats-service` (from apps)

我手足无措,再也控制不住自己了。我希望这里有人能够帮助我。

提前致谢。

PS: 下面是我机器的配置,以防是我机器的问题。

Processor: AMD Ryzen 7 1700 (8C/16T)
Memory: 2 x 8GB DDR4 2667MHz
Graphics: AMD Radeon RX 590 (8GB)
OS: Windows 10 Pro 21H1
$ docker version
Client:
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.12
 Git commit:        0ed913b8-
 Built:             07/28/2020 16:36:03
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:52:10 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.4", GitCommit:"3cce4a82b44f032d0cd1a1790e6d2f5a55d20aae", GitTreeState:"clean", BuildDate:"2021-08-11T18:10:22Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}

我使用 WSL2 (Debian) 并且 docker-desktop 是 Kubernetes 的上下文。

错误说明一切:

- `0/1 nodes are available: 1 Insufficient cpu.` (from deployments)

您请求或部署的应用程序超出了您的节点可以处理的数量。
在您的部署单元(DeploymentStatefulSetDeamoSet 等)中,您定义应用程序所需的资源,例如在这个 pod 中:

apiVersion: v1
kind: Pod
metadata:
  name: frontend
spec:
  containers:
  - name: app
    image: images.my-company.example/app:v4
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"
  - name: log-aggregator
    image: images.my-company.example/log-aggregator:v6
    resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

这是相关部分:

resources:
      requests:
        memory: "64Mi"
        cpu: "250m"
      limits:
        memory: "128Mi"
        cpu: "500m"

检查您的节点资源并增加您的节点或资源以便能够部署更多服务。


0/1 nodes are available: 1 Insufficient cpu. (from deployments)

此错误显然意味着您的部署没有足够的资源来启动。

我尝试在我的环境中部署同样的错误,2 CPU 不足以启动此映像。

您可能需要更高的资源或大节点来测试

https://github.com/msrumon/microservice-template/blob/master/k8s/nats.yaml

出现此类问题的主要原因是您正在设置 only CPU limit (without setting CPU request) so Kubernetes automatically assigns a CPU request which is equal to the CPU limit:

If you specify a CPU limit for a Container but do not specify a CPU request, Kubernetes automatically assigns a CPU request that matches the limit. Similarly, if a Container specifies its own memory limit, but does not specify a memory request, Kubernetes automatically assigns a memory request that matches the limit.

因此,由于请求等于限制,您的节点无法满足这些要求(您有 16 CPUs 可用;要启动所有服务,您需要 24 CPUs)- 那是为什么您会收到 0/1 nodes are available: 1 Insufficient cpu 错误消息。

如何解决?

但是...

你写道:

Should I also try setting up the requests key and set the lower limit too? Or what about completely omitting it? I tried that one, and still same issue.

因此,如果您从所有部署中删除了所有 CPU 限制,但您仍然遇到与 CPU 不足相关的错误,这清楚地表明您的应用太耗费资源。我建议在资源利用率方面优化应用程序。另一种选择是增加节点资源。