我的部署使用了两个卷,全部定义为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=[...]
然后将更改应用于此类部署的最佳策略是什么?为了使用相同的持久性卷,是否必须要有一些服务中断? (我不想创建新的卷-数据应该维护)
答案 0 :(得分:3)
由于访问模式的原因,您将需要在此处容忍中断。在创建新Pod之前,这将删除现有Pod(卸载卷)。
“重新创建”的部署策略-.spec.strategy.type
-将帮助实现这一目标:https://github.com/ContainerSolutions/k8s-deployment-strategies/blob/master/recreate/README.md
答案 1 :(得分:0)
最后我有了一个更好的解决方案,其中我所有的客户pod都是内容的阅读者,并且我有一个独立的CI流程来编写内容,我可以执行以下操作:
gs://my-storage
,然后重新启动所有前端Pod 如何实现: 在前端docker映像上,我从https://github.com/GoogleCloudPlatform/cloud-sdk-docker/blob/master/debian_slim/Dockerfile添加了gcloud安装块:
ARG CLOUD_SDK_VERSION=249.0.0
ENV CLOUD_SDK_VERSION=$CLOUD_SDK_VERSION
ARG INSTALL_COMPONENTS
ENV PATH "$PATH:/opt/google-cloud-sdk/bin/"
RUN apt-get update -qqy && apt-get install -qqy \
curl \
gcc \
python-dev \
python-setuptools \
apt-transport-https \
lsb-release \
openssh-client \
git \
gnupg \
&& easy_install -U pip && \
pip install -U crcmod && \
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - && \
apt-get update && apt-get install -y google-cloud-sdk=${CLOUD_SDK_VERSION}-0 $INSTALL_COMPONENTS && \
gcloud config set core/disable_usage_reporting true && \
gcloud config set component_manager/disable_update_check true && \
gcloud config set metrics/environment github_docker_image && \
gcloud --version
VOLUME ["/root/.config"]
在pod部署frontend.yaml
中,我添加了以下lifecycle
事件:
...
spec:
...
containers:
...
lifecycle:
postStart:
exec:
command: ["gsutil", "-m", "rsync", "-r", "gs://my-storage", "/usr/share/nginx/html"]
要在更新存储桶内容时“刷新”前端容器,我只需从CI中运行以下命令即可:
kubectl set env deployment/frontend K8S_FORCE=
日期+%s``
答案 2 :(得分:-1)
由于ReadWriteOnce访问模式,这似乎是一个错误。请记住,更新部署时,将创建新的Pod,然后删除较旧的Pod。因此,也许新的Pod尝试挂载已经挂载的卷,这就是为什么您收到该消息的原因。
您是否尝试过使用允许多个读取器/写入器的卷?您可以在Kubernetes Volumes documentation中查看当前卷的列表。