本文介绍了Kubnetl复制命令的Kubernetes Java API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个容器在Kubernetes集群内部(在POD内)与许多其他容器(在其自己的POD中)一起运行,并且我的容器是一个普通的容器.现在,我想将文件从其他容器中拉出(复制)到我的普通容器中.我研究了一些选项,发现可以使用kubectl副本.但是,为此,我需要在公共容器中包含kubectl命令行工具.我不确定这是否正确.因此,我想到了使用Java Kubernetes API进行相同的操作.Kubectl复制命令是否具有等效的Kubernetes REST API?我经历了kubernetes API,找不到任何这样的API ..

I have a container running inside Kubernetes cluster (within POD) along side many other containers (in their own PODs) and my container is a common container. Now, I want to pull (copy) the files from other containers to my common container. I investigated for some options and found that kubectl copy can be used. But, for that, I need to include kubectl command line tool inside my common container. I'm not sure if this is right approach. So, I thought of using Java Kubernetes APIs to do the same.Is there equivalent Kubernetes REST API for Kubectl copy command ? I gone through the kubernetes APIs and could not find any such API ..

谢谢

推荐答案

这是因为 kubectl cp是通过tar 实现的,因此实际上发生的是kubectl exec $pod -- tar -cf - /the/container/file | tar -xf -,这是我期望的Java API也需要这样做.

That's because kubectl cp is implemented via tar, so what is actually happening is kubectl exec $pod -- tar -cf - /the/container/file | tar -xf -, which is what I would expect your Java API would need to do, as well.

但是,您可能-根据您的需要-能够摆脱在kubectl cp到达之前我曾经做过的事情:kubectl exec $pod -- /bin/cat /the/container/file > local-file在您的情况下,这可能会容易得多,因为我希望API会将这些字节具体化为InputStream,从而使您无需再进行tar格式解析业务

However, you may -- depending on your needs -- be able to get away with how I used to do it before kubectl cp arrived: kubectl exec $pod -- /bin/cat /the/container/file > local-file which in your circumstance may be a ton easier since I would expect the API would materialize those bytes as an InputStream, saving you the need to get into the tar-format-parsing business

这篇关于Kubnetl复制命令的Kubernetes Java API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 21:05
查看更多