[英]How do I read a file from deployment's pods using fabric8 kubernetes java client?
How can I read a file from a deployment's pods?如何从部署的 pod 中读取文件? More specifically, I want fabric8's kubernetes java client equivalent of the following command:更具体地说,我希望 fabric8 的 kubernetes java 客户端等效于以下命令:
kubectl exec --stdin --tty deployment/otel-collector -n logcollection -- cat /otel-output/json-out.json
PS: you can ignore the --stdin
and --tty
flags. PS:您可以忽略--stdin
和--tty
标志。
It's fairly simple, to read file from a Pod
you can use the following syntax (see also fabric8 documentation ):这相当简单,从Pod
读取文件可以使用以下语法(另请参阅fabric8 文档):
try (InputStream is = client.pods().inNamespace(currentNamespace).withName(pod1.getMetadata().getName()).file("/msg").read()) {
String result = new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n"));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.