服务器错误(冲突):无法完成对statefulsets.apps 'my-statefulset' 的操作:对象已被修改;请将您的更改应用到最新版本并重试
Error from server (Conflict): Operation cannot be fulfilled on statefulsets.apps 'my-statefulset': the object has been modified; please apply your changes to the latest version and try again
ID: kubernetes/statefulset-update-rollback-failed
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Kubernetes 1.25 | active | — | — | — |
| Kubernetes 1.26 | active | — | — | — |
| Kubernetes 1.27 | active | — | — | — |
根因分析
对StatefulSet的并发更新(例如由控制器或其他用户)导致在应用更改时发生资源版本冲突,从而产生409冲突错误。
English
A concurrent update to the StatefulSet (e.g., by a controller or another user) caused a resource version conflict when trying to apply a change, resulting in a 409 Conflict error.
官方文档
https://kubernetes.io/docs/concepts/architecture/garbage-collection/解决方案
-
重新获取StatefulSet清单:`kubectl get statefulset my-statefulset -o yaml > statefulset.yaml`。编辑文件,然后重新应用:`kubectl apply -f statefulset.yaml`。这确保您拥有最新的资源版本。
-
使用`kubectl patch`进行策略合并补丁以更新特定字段,无需完全替换:`kubectl patch statefulset my-statefulset --type='strategic' -p '{"spec":{"replicas":3}}'`。这通过合并避免版本冲突。
无效尝试
常见但无效的做法:
-
90% 失败
Force-applying with `--force` flag does not exist for kubectl apply; it only works for `kubectl replace --force` which can cause data loss.
-
80% 失败
Retrying the same command without re-fetching the latest object version will hit the same conflict because the resource version is still stale.