问题描述
我在通过掌舵创建的K8s集群中有一个测试执行器Pod
,它要求动态创建的PersistentVolume
用于存储测试结果.
I have a test executor Pod
in K8s cluster created through helm, which asks for a dynamically created PersistentVolume
where it stores the test results.
现在,我想获取此卷的内容.看起来很自然.我希望一些kubectl download pv <id>
.但是我什么都不能用谷歌搜索.
Now I would like to get the contents of this volume. It seems quite natural thing to do.I would expect some kubectl download pv <id>
. But I can't google up anything.
如何获取PersistentVolume
的内容?
How can I get the contents of a PersistentVolume
?
我在AWS EKS中;因此,AWS API也是一种选择.我也可以访问ECR,所以也许我可以以某种方式将其存储为图像并下载?
I am in AWS EKS; so AWS API is also an option. Also I can access ECR so perhaps I could somehow store it as an image and download?
或者,总的来说,我正在寻找一种转移目录的方法,甚至可以将其保存在存档中.但是应该在容器完成后 并且不再运行.
Or, in general, I am looking for a way to transfer a directory, can be even in an archive. But It should be after the container finished and doesn't run anymore.
推荐答案
我可以考虑两种方法来满足您的需求:
I can think about two options to fulfill your needs:
1)创建一个已附加PV的容器,然后使用kubectl cp
将其复制到所需的位置.例如,您可以使用类似于以下内容的PodSpec
:
1) create a pod with the PV attached to it and use kubectl cp
to copy the contents wherever you need. You could for example use a PodSpec
similar the following:
apiVersion: v1
kind: Pod
metadata:
name: dataaccess
spec:
containers:
- name: alpine
image: alpine:latest
command:
- sleep
- 999999
volumeMounts:
- name: mypvc
mountPath: /data
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: mypvc
请注意,mypvc应该是与要复制数据的PV绑定的PersistentVolumeClaim
的名称.
Please note that mypvc should be the name of the PersistentVolumeClaim
that is bound to the PV you want to copy data from.
pod运行后,您可以运行以下操作从任何配置了kubectl的计算机上复制数据:
Once the pod is running, you can run something like this to copy the data from any machine that has kubectl configured to connect to your cluster:
kubectl cp dataaccess:/data data/
2)将PV的EBS卷安装在EC2实例中,然后从那里复制数据.这种情况下,要进行详细说明不太容易,因为它需要更多有关您要实现的目标的上下文.
2) mount the PV's EBS volume in an EC2 instance and copy the data from there. This case is less simple to explain in detail because it needs a little more context about what you're trying to achieve.
这篇关于Kubernetes-如何下载PersistentVolume的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!