K8S_CONFLICT cicd config_error ai_generated true

来自服务器的错误(冲突):无法完成对 pod "my-app-5d4f8b7c6-abcde" 的操作:对象已被修改;请将更改应用于最新版本并重试

Error from server (Conflict): Operation cannot be fulfilled on pods "my-app-5d4f8b7c6-abcde": the object has been modified; please apply your changes to the latest version and try again

ID: cicd/kubectl-apply-pending

其他格式: JSON · Markdown 中文 · English
85%修复率
86%置信度
1证据数
2024-03-12首次发现

版本兼容性

版本状态引入弃用备注
Kubernetes 1.28 active
Kubernetes 1.29 active
kubectl 1.29.0 active

根因分析

当两个或多个控制器或 CI 作业尝试同时修改同一 Kubernetes 资源时,会发生资源更新冲突,导致第二个更新因 resourceVersion 过期而失败。

English

A Kubernetes resource update conflict occurs when two or more controllers or CI jobs try to modify the same resource concurrently, causing the second update to fail due to stale resourceVersion.

generic

官方文档

https://kubernetes.io/docs/reference/using-api/api-concepts/#conflicts

解决方案

  1. 在短暂延迟(例如 10 秒)后重新运行 CI 作业,以允许冲突操作完成并更新 resourceVersion。
  2. 使用 `kubectl apply --server-side=true`,它使用服务器端应用来合并更改而不会出现冲突错误。
  3. 在 CI 脚本中添加重试循环:`for i in 1 2 3; do kubectl apply -f deployment.yaml && break || sleep 5; done`

无效尝试

常见但无效的做法:

  1. 60% 失败

    Deleting and recreating the resource manually; this causes downtime and may trigger cascading failures in dependent services.

  2. 70% 失败

    Using `kubectl replace --force` which deletes and recreates the resource; this bypasses conflict detection but can delete other dependent objects.

  3. 90% 失败

    Ignoring the error and retrying the same CI job without changes; the conflict persists because the resourceVersion hasn't been updated.