[英]Can kubernetes provide a pod with an emptyDir volume from the host backed by a specific filesystem different than the host's?
[英]Kubernetes emptyDir and symlinks
我有一個帶有兩個容器的吊艙:
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
我最初的嘗試有兩個錯誤:
以下是修改后的例程:
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"
符號鏈接只是一種包含文件名的特殊文件; 它實際上並不以任何有意義的方式包含文件內容,也不必指向存在的文件。 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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.