偶尔,我需要对StatefulSet中的所有Pod进行滚动替换,以便也可以从头开始重新创建所有PV。这样做的原因是摆脱使用旧版本加密密钥的所有基础硬盘驱动器。此操作不应与常规滚动升级混淆,对此,我仍然希望卷能够在Pod终止后继续生存。到目前为止,我认为最好的例程是:
我对步骤5不满意。我希望StatefulSet为我重新创建PVC,但不幸的是,它没有。我必须自己做,否则Pod创建会失败,并显示以下错误:
Warning FailedScheduling 3s (x15 over 15m) default-scheduler persistentvolumeclaim "foo-bar-0" not found
有更好的方法吗?
答案 0 :(得分:3)
我最近不得不这样做。以下对我有用:
# 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>
答案 1 :(得分:1)
这在 https://github.com/kubernetes/kubernetes/issues/89910 中有描述。那里提出的解决方法是删除卡在挂起的新 Pod,并且在第二次被替换时会创建一个新的 PVC。它被标记为 https://github.com/kubernetes/kubernetes/issues/74374 的副本,并报告为可能在 1.20 中修复。
答案 2 :(得分:0)
似乎您在以错误的方式使用“ Persistent”卷。其设计目的是在每次推出之间保留数据,而不是删除数据。还有其他不同的方式来更新密钥。可以使用k8s Secret
和ConfigMap
将密钥安装到Pod中。然后,您只需要在滚动更新期间重新创建Secret