我需要将文件树 rsync 到 kubernetes 集群中的特定 pod。如果只有一个人可以说服 rsync 相信 kubectl 的行为有点像 rsh,那似乎应该是可能的。就像是:
rsync --rsh='kubectl exec -i podname -- ' -r foo x:/tmp
Run Code Online (Sandbox Code Playgroud)
...除了这会遇到 x 问题,因为 rsync 假设需要一个主机名:
exec: "x": executable file not found in $PATH
Run Code Online (Sandbox Code Playgroud)
我似乎找不到帮助 rsync 构建 rsh 命令的方法。有没有办法做到这一点?或者可以通过管道实现相对高效的文件传输的其他方法?
(我知道gcloud compute copy-files
,但它只能在节点上使用?)
Kar*_*nch 33
要 rsync 到 pod,我使用以下帮助程序:
pod=$1;shift;kubectl exec -i $pod -- "$@"
Run Code Online (Sandbox Code Playgroud)
我把它放在一个名为“rsync-helper.sh”的文件中,然后像这样运行rsync:
rsync -av --progress --stats -e './rsync-helper.sh' source-dir/ thePodName:/tmp/dest-dir
Run Code Online (Sandbox Code Playgroud)
如果你想要一个简单的脚本来包装这一切,请将其保存为 krsync:
#!/bin/bash
if [ -z "$KRSYNC_STARTED" ]; then
export KRSYNC_STARTED=true
exec rsync --blocking-io --rsh "$0" $@
fi
# Running as --rsh
namespace=''
pod=$1
shift
# If use uses pod@namespace rsync passes as: {us} -l pod namespace ...
if [ "X$pod" = "X-l" ]; then
pod=$1
shift
namespace="-n $1"
shift
fi
exec kubectl $namespace exec -i $pod -- "$@"
Run Code Online (Sandbox Code Playgroud)
然后您可以在通常使用 rsync 的地方使用 krsync:
krsync -av --progress --stats src-dir/ pod:/dest-dir
Run Code Online (Sandbox Code Playgroud)
或者您可以设置命名空间:
krsync -av --progress --stats src-dir/ pod@namespace:/dest-dir
Run Code Online (Sandbox Code Playgroud)
注意:您必须在 pod 映像中具有 rsync 可执行文件才能使其工作。
最后,我编写了一个Python脚本来充当tar文件的接收器。 你可以这样做:
tar cf - . | kubectl exec shinken -i catcher -v /etc/shinken/custom_configs
Run Code Online (Sandbox Code Playgroud)
请注意,这仅适用于集群节点为 kubernetes 1.1 或更高版本的情况。
归档时间: |
|
查看次数: |
15707 次 |
最近记录: |