Search code examples
kubernetesopenshiftremote-debugging

Select Python interpreter from remote OpenShift


I am looking for a way to connect to OpenShift from PyCharm Pro. I can select SSH, but I shouldn't configure ssh on my container. I can only use oc rsh.

Is there a way to run remote Python from OpenShift container in local IDE?

I tried SSH on PyCharm, but it can not connect. oc rsh works, and I have access to all files in container. I tried OpenShift and Kubernetes plugins, but I think they don't help with that stuff.


Solution

  • Fundamentally you are trying to connect to ssh from outside the cluster. That means you are going to have to expose port 22 in some way.

    If this is just sort of a development hack where you temporarily making a connection to the pod you could use port-forwarding to forward port 22. https://docs.openshift.com/container-platform/4.13/nodes/containers/nodes-containers-port-forwarding.html

    But for a more permanent solution, presuming you have a single pod, you could wrap that single pod in a LoadBalancer or NodePort Service. Then use whatever IP/port that is exposed from that service to connect via SSH.

    (EDIT: Subtle point. I don't really mean it has to be port 22. Especially externally. The real point was that the core of this question doesn't seem to have anything to do with Python or PyCharm. It, at its heart, really seems to be about how can I access a port inside my OCP cluster from outside my OCP cluster.)