[英]Port forward from OpenShift via Java
How to programmatically execute如何以编程方式执行
oc port-forward <podName> <podPort>:<localPort>
via Java?通过 Java?
At the moment I managed to get the list of pods under through the library io.fabric8:openshift-client.目前,我设法通过库 io.fabric8:openshift-client 获取了 pod 列表。
OpenShiftClient config = new DefaultOpenShiftClient();
client.pods().inNamespace("namespace").list().getItems();
But in this library don't exist port-forwarding functionality and I didn't find any information on the net但是在这个库中不存在端口转发功能,我在网上没有找到任何信息
Something like this works like a charm:像这样的东西就像一个魅力:
OpenShiftClient client = new KubernetesClientBuilder().build().adapt(OpenShiftClient.class);
Resource<Namespace> openShiftProject = client.namespaces().withName(yourNamespace);
PodResource openShiftPod = client.pods().inNamespace(yourNamespace).withName(yourPodName);
openShiftPod.portForward(REMOTE_PORT_NBR, LOCAL_PORT_NBR);
Feel free to add some checks ( isReady
for instance) to secure your code.随意添加一些检查(例如
isReady
)来保护您的代码。 And don't forget to close the client once its job is over.并且不要忘记在其工作结束后关闭客户端。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.