问题描述
我在kubernetes系统中有很多Pod,其名称随机为wordpress.xxx.xx.
I have many pods in a kubernetes system with randomly name wordpress.xxx.xx.
以下是 pod的列表
我想将一个命令与另一个kubectl cp
一起使用,以将文件从一个部署复制到所有Pod.
I want to use one command with kubectl cp
in other to copy files to all pods from one deployment.
就我而言,我不想使用卷,因为它们安装在已经隐藏该文件夹中现有内容的路径中.
In my case I don't want to use volumes because they mount into a path that already the existing content of that folder will be hidden.
请问该怎么做?
谢谢您的回答.
推荐答案
kubectl cp
命令将文件复制到Pod中的单个容器中.要轻松地将文件复制到多个容器中,可以使用以下shell脚本.
The kubectl cp
command copies files to a single container in a pod. To copy files in multiple containers easily, the below shell script can be used.
for pod in `kubectl get pods -o=name | grep wordpress | sed "s/^.\{4\}//"`; do echo "copying to $pod"; kubectl cp file.txt $pod:/; done
或
for pod in `kubectl get pods -o=name | grep wordpress | sed "s/^.\{4\}//"`
do
echo "copying file to $pod"
kubectl cp file.txt $pod:/
done
两个脚本都是相同的,单行还是多行.
Both the scripts are same, single vs multi-line.
这篇关于如何使用Kubectl cp自动将文件从本地系统复制到带有列表过滤器的kubernetes Pod的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!