Kubernetes 部署更新使 ReplicaSet 崩溃并创建了太多 Pods

Kubernetes Deployment update crashes ReplicaSet and creates too many Pods

我使用 Kubernetes 将应用程序部署到 Google Cloud Containerengine,集群上有 3 个小型实例。

在首次部署时,一切顺利,使用:

kubectl create -f deployment.yaml

并且:

kubectl create -f service.yaml

然后我更改 deployment.yaml 中的 image 并像这样更新它:

kubectl apply -f deployment.yaml

更新后,会发生一些事情:

所以我检查了我的 Pods 并遇到了这个错误:

FailedSync      Error syncing pod, skipping: network is not ready: [Kubenet does not have netConfig. This is most likely due to lack of PodCIDR]

我也不能再使用仪表板 kubectl proxy。页面显示:

{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "no endpoints available for service \"kubernetes-dashboard\"",
  "reason": "ServiceUnavailable",
  "code": 503
}

所以我决定强行删除所有pods:

kubectl delete pod <pod-name> --grace-period=0 --force

然后,触发创建三个Pods,因为这是在我的service.yaml中定义的。但是在使用 kubectl describe pods/<pod-name> 检查我的 Pods 后,我看到:

no nodes available to schedule pods

我不知道哪里出了问题。实际上,我所做的只是更新部署的图像。

有人有想法吗?

如果您只是想更新图片,请尝试使用 kubectl set image。这至少对我有用。

通过谷歌搜索 kubectl apply 似乎确实出现了很多已知问题。看到这个 issue for example or this one.

您没有post您部署的是哪个版本的kubernetes,如果您可以尝试将您的集群升级到最新版本,看看问题是否仍然存在。

我 运行 在 Kubernetes 上遇到过类似问题。根据你对我的问题的回复(见上):

I noticed that this happens only when I deploy to a micro instance on Google Cloud, which simply has insufficient resources to handle the deployment. Scaling up the initial resources (CPU, Memory) resolved my issue

在我看来,这里发生的事情是来自 Linux 内核的 OOM 杀手最终杀死了 kubelet,这反过来又使节点对集群无用(并变成 "Unknown" ).

这个问题的真正解决方案(防止整个节点退出服务)是添加 resource limits。确保您 只是 添加请求;添加 limits 因为你希望你的服务——而不是 K8s 系统服务——被杀死,以便它们可以被适当地重新安排(如果可能的话)。

也在集群设置中(特别是在节点池中——来自 https://console.cloud.google.com/kubernetes/list 的 select),有一个框你可以检查 "Automatic Node Repair" 至少部分重新解决这个问题,而不是给你一个不确定的停机时间。