如何使用Kubectl cp自动将文件从本地系统复制到带有列表过滤器的kubernetes Pod [英] How to use kubectl cp to copy files automatically from a local system to kubernetes Pods with list filter

查看:960
本文介绍了如何使用Kubectl cp自动将文件从本地系统复制到带有列表过滤器的kubernetes Pod的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆