使用新的 PersistentVolume 重新创建由 StatefulSet 管理的 Pod

lop*_*pek 6 kubernetes kubernetes-statefulset

有时,我需要对 StatefulSet 中的所有 Pod 进行滚动替换,以便所有 PV 也从头开始重新创建。这样做的原因是摆脱所有使用旧版本加密密钥的底层硬盘驱动器。此操作不应与常规滚动升级相混淆,为此我仍然希望卷能够在 Pod 终止后继续存在。到目前为止,我认为最好的例程如下:

  1. 删除PV。
  2. 删除 PVC。
  3. 删除 Pod。
  4. 等待所有删除完成。
  5. 手动重新创建在步骤 2 中删除的 PVC。
  6. 等待新 Pod 完成 StatefulSet 中其他 Pod 的数据流传输。
  7. 对于下一个 Pod,从步骤 1. 开始重复。

我对第 5 步不满意。我希望 StatefulSet 为我重新创建 PVC,但不幸的是它没有。我必须自己做,否则 Pod 创建失败并出现以下错误:

Warning  FailedScheduling   3s (x15 over 15m)  default-scheduler   persistentvolumeclaim "foo-bar-0" not found
Run Code Online (Sandbox Code Playgroud)

有更好的方法吗?

小智 5

我最近不得不这样做。以下对我有用:

# Delete the PVC
$ kubectl delete pvc <pvc_name>

# Delete the underlying statefulset WITHOUT deleting the pods
$ kubectl delete statefulset <statefulset_name> --cascade=false 

# Delete the pod with the PVC you don't want
$ kubectl delete pod <pod_name>

# Apply the statefulset manifest to re-create the StatefulSet, 
# which will also recreate the deleted pod with a new PVC
$ kubectl apply -f <statefulset_yaml>

Run Code Online (Sandbox Code Playgroud)


Ben*_*eld 3

https://github.com/kubernetes/kubernetes/issues/89910中对此进行了描述。那里提出的解决方法是删除处于挂起状态的新 Pod,它可以工作,并且在第二次被替换时会创建一个新的 PVC。它被标记为https://github.com/kubernetes/kubernetes/issues/74374的副本,并报告为可能在 1.20 中修复。