You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes emptyDir共享卷下sidecar同步的symlink无法访问如何解决

背景

我有一个包含两个容器的Pod:

  • main容器:职责为展示指定目录的内容
  • sidecar容器:职责为将blob存储的内容同步到预定义目录

为了保证同步操作原子性,sidecar会先将blob存储内容下载到临时目录,再通过切换目标目录下的symlink完成更新。目标目录通过emptyDir卷在两个容器间共享。

问题

main容器可以看到symlink,但无法读取其指向的内容,如何才能访问到最新的同步数据?

补充信息

需求背景

我希望实现类似Apache Airflow搭配Git-Sync的能力,但需要同步的源是Azure Blob存储而非Git。该方案是必要的,原因有二:1. 我的同步内容以动态内容为主;2. azureFile卷类型存在较为严重的性能问题。

初始同步脚本

declare -r container='https://mystorageaccount.dfs.core.windows.net/mycontainer'
declare -r destination='/shared/container'

declare -r temp_dir="$(mktemp -d)"
azcopy copy --recursive "$container/*" "$temp_dir"

declare -r temp_file="$(mktemp)"
ln -sf "$temp_dir" "$temp_file"
mv -Tf "$temp_file" "$destination"

最终生成的目录结构如下:

$ ls /shared
container -> /tmp/tmp.doGz2U0QNy
$ ls /shared/container
file1.txt file2.txt
解决方案

初始方案存在两个错误:

  1. symlink的目标路径不在共享卷内
  2. symlink指向的是sidecar容器内的绝对路径,从main容器视角看该路径不存在

修改后的同步脚本如下:

declare -r container='https://mystorageaccount.dfs.core.windows.net/mycontainer'
declare -r destination='/shared/container'
declare -r cache_dir="$(dirname $destination)"

declare -r temp_dir="$(mktemp -d -p $cache_dir)"
azcopy copy --recursive "$container/*" "$temp_dir"

ln -sf "$(basename $temp_dir)" "$cache_dir/symlink"
mv -Tf "$cache_dir/symlink" "$destination"

内容的提问来源于stack exchange,提问作者Flavi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 21:27:01