gpt4 book ai didi

kubernetes - 在部署更新时重新附加卷声明

转载 作者:行者123 更新时间:2023-12-02 11:34:26 25 4
gpt4 key购买 nike

我正在使用持久卷声明将数据存储在容器中:

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-pvc
labels:
type: amazonEBS
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi

规范中的声明:
spec:
volumes:
- name: test-data-vol
persistentVolumeClaim:
claimName: test-pvc
containers:
- name: test
image: my.docker.registry/test:1.0
volumeMounts:
- mountPath: /var/data
name: test-data-vol

当我第一次启动它时,这个卷安装正确。但是当我尝试更新容器镜像时:
-    image: my.docker.registry/test:1.0
+ image: my.docker.registry/test:1.1

此卷无法挂载到新 pod:
# kubectl get pods
test-7655b79cb6-cgn5r 0/1 ContainerCreating 0 3m
test-bf6498559-42vvb 1/1 Running 0 11m

# kubectl describe test-7655b79cb6-cgn5r
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 3m5s default-scheduler Successfully assigned test-7655b79cb6-cgn5r to ip-*-*-*-*.us-west-2.compute.internal
Warning FailedAttachVolume 3m5s attachdetach-controller Multi-Attach error for volume "pvc-2312eb4c-c270-11e8-8d4e-065333a7774e" Volume is already exclusively attached to one node and can't be attached to another
Normal SuccessfulMountVolume 3m4s kubelet, ip-*-*-*-*.us-west-2.compute.internal MountVolume.SetUp succeeded for volume "default-token-x82km"
Warning FailedMount 62s kubelet, ip-*-*-*-*.us-west-2.compute.internal Unable to mount volumes for pod "test-7655b79cb6-cgn5r(fab0862c-d1cf-11e8-8d4e-065333a7774e)": timeout expired waiting for volumes to attach/mount for pod "test-7655b79cb6-cgn5r". list of unattached/unmounted volumes=[test-data-vol]

Kubernetes 似乎无法将此卷从一个容器重新附加到另一个容器。如何正确处理?当旧版本停止时,我需要新版本的部署使用此卷数据。

最佳答案

这里的问题是 EBS 卷是 ReadWriteOnce并且只能挂载到单个 Pod,因此当您进行滚动更新时,旧 Pod 会保存该卷。为此,您必须使用 StatefulSet 或者您可以使用任何 ReadWriteMany 光伏类型。

Kubernetes Deployment有时更好地用于无状态 pod。

您始终可以使用蛮力方法,强制删除持有该卷的 pod。确保 Reclaim Policy 设置为 Retain .

关于kubernetes - 在部署更新时重新附加卷声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52848176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com