How to programmatically execute
oc port-forward <podName> <podPort>:<localPort>
via Java?
At the moment I managed to get the list of pods under through the library io.fabric8:openshift-client.
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. And don't forget to close the client once its job is over.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.