語境
我有一個帶有兩個容器的吊艙:
main它的簡單作業是顯示目錄的內容sidecar其職責是將 blob 存盤的內容同步到預定義的目錄中
為了使同步具有原子性,sidecar請將 blob 存盤內容下載到新的臨時目錄中,然后在目標目錄中切換符號鏈接。
使用emptyDir卷在兩個容器之間共享目標目錄。
問題
main 有符號鏈接,但不能列出后面的內容。
題
如何訪問最新的同步資料?
附加資訊
原因
我嘗試使用Git-Sync來實作Apache Airflow所做的事情,但我需要從 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
解決方案
我最初的嘗試有兩個錯誤:
- 卷中不存在符號鏈接目標
- 符號鏈接目標指向 sidecar 容器中的絕對路徑,因此,從主容器的角度來看,該檔案夾不存在
以下是修改后的例程:
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"
uj5u.com熱心網友回復:
符號鏈接只是一種包含檔案名的特殊檔案;它實際上并不以任何有意義的方式包含檔案內容,也不必指向存在的檔案。 mktemp (1)默認在 中創建目錄/tmp,該目錄可能不在共享卷中。
想象一下,將一個物理檔案夾放在一個物理檔案柜中,在便利貼上寫字the third drawer at the very front,然后開車到另一棟大樓,然后將便條交給同事。便利貼(符號鏈接)仍然存在,但在其他建筑物(容器檔案系統)的背景關系中,它命名的位置并不是特別有意義。
解決此問題的最簡單方法是要求mktemp直接在目標卷中創建檔案,然后創建一個相對路徑符號鏈接。
# extract the volume location (you may already have this)
volume_dir=$(dirname "$destination")
# force the download location to be inside the volume
# (mktemp --tmpdir option)
temp_dir=$(mktemp -d --tmpdir "$volume_dir")
# actually do the download
azcopy copy --recursive "$container/*" "$temp_dir"
# set the symlink to a relative-path symlink, since the directory
# and the link are in the same place; avoids problems if the volume
# is mounted in different places in the two containers
ln -sf $(basename "$temp_dir") "$destination"
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/338695.html
標籤:linux Kubernetes 空气流动 符号链接 持久卷
上一篇:linux中的簡單排序
