kubernetes - 更新使用 ReadWriteOnce 卷的部署将在挂载时失败
问题描述
我的部署使用了几个卷,全部定义为ReadWriteOnce
.
将部署应用到干净的集群时,Pod 已成功创建。
但是,如果我更新我的部署(即更新容器映像),当为我的部署创建一个新的 pod 时,它总是会在卷挂载时失败:
/Mugen$ kubectl get pods
NAME READY STATUS RESTARTS AGE
my-app-556c8d646b-4s2kg 5/5 Running 1 2d
my-app-6dbbd99cc4-h442r 0/5 ContainerCreating 0 39m
/Mugen$ kubectl describe pod my-app-6dbbd99cc4-h442r
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 9m default-scheduler Successfully assigned my-app-6dbbd99cc4-h442r to gke-my-test-default-pool-671c9db5-k71l
Warning FailedAttachVolume 9m attachdetach-controller Multi-Attach error for volume "pvc-b57e8a7f-1ca9-11e9-ae03-42010a8400a8" Volume is already used by pod(s) my-app-556c8d646b-4s2kg
Normal SuccessfulMountVolume 9m kubelet, gke-my-test-default-pool-671c9db5-k71l MountVolume.SetUp succeeded for volume "default-token-ksrbf"
Normal SuccessfulAttachVolume 9m attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-2cc1955a-1cb2-11e9-ae03-42010a8400a8"
Normal SuccessfulAttachVolume 9m attachdetach-controller AttachVolume.Attach succeeded for volume "pvc-2c8dae3e-1cb2-11e9-ae03-42010a8400a8"
Normal SuccessfulMountVolume 9m kubelet, gke-my-test-default-pool-671c9db5-k71l MountVolume.SetUp succeeded for volume "pvc-2cc1955a-1cb2-11e9-ae03-42010a8400a8"
Normal SuccessfulMountVolume 9m kubelet, gke-my-test-default-pool-671c9db5-k71l MountVolume.SetUp succeeded for volume "pvc-2c8dae3e-1cb2-11e9-ae03-42010a8400a8"
Warning FailedMount 52s (x4 over 7m) kubelet, gke-my-test-default-pool-671c9db5-k71l Unable to mount volumes for pod "my-app-6dbbd99cc4-h442r_default(affe75e0-1edd-11e9-bb45-42010a840094)": timeout expired waiting for volumes to attach or mount for pod "default"/"my-app-6dbbd99cc4-h442r". list of unmounted volumes=[...]. list of unattached volumes=[...]
那么,将更改应用于此类部署的最佳策略是什么?为了使用相同的持久性卷,是否必须发生一些服务中断?(我不想创建新卷 - 数据应该保持)
解决方案
由于访问模式,您需要容忍这里的中断。这将在创建新 Pod 之前删除现有 Pod(卸载卷)。
“重新创建”的部署策略.spec.strategy.type
将有助于实现这一目标:https ://github.com/ContainerSolutions/k8s-deployment-strategies/blob/master/recreate/README.md
推荐阅读
- python - 了解 Django (Python) 和数据库
- javascript - 如何从 json 中的每个元素获取索引并输出为数组
- javascript - 如何创建像 nodejs 这样的 Javascript 运行时
- python - 如何在给定元组列表的情况下创建倒排索引?
- android - android模拟器中没有互联网
- server - 我无法从网络中的其他设备访问本地主机的原因是什么?
- java - Perl 校验和计算迁移到 Java
- javascript - 用正则表达式替换/删除 2 个 javascript 注释之间的文本
- javascript - 鹅毛笔编辑器斜体文本为红色
- html - 无法将图像放入网格单元格中