Port forwarding VS route in Open shift - unix1998/technical_notes GitHub Wiki

make service accessible to the outside of the OpenShift cluster using port forwarding, even if you do not "expose" the service. Here’s how you can do it:

  1. Deploy the Application: Ensure your application is deployed and a service is created for it within the OpenShift cluster.

  2. Start Port Forwarding: Use the oc port-forward command to forward a local port to the service port within the OpenShift cluster. This command allows you to access the service through a port on your local machine.

    oc port-forward svc/<service-name> <local-port>:<service-port>

    For example, if your service is named my-service and it runs on port 8080, you can forward it to port 9090 on your local machine using:

    oc port-forward svc/my-service 9090:8080
  3. Access the Service: Once port forwarding is set up, you can access the service on your local machine using the local port you specified. In the above example, you can access it via http://localhost:9090.

Considerations

  • Local Access: Port forwarding primarily makes the service accessible from your local machine. If you need to make it accessible to other external clients or systems, you might need additional configurations, such as setting up an SSH tunnel from a remote machine to your local machine.

  • Persistent Access: Port forwarding is session-based and typically used for development or debugging. If you need a more persistent solution for exposing the service, consider using an OpenShift Route or Ingress.

Exposing the Service

Alternatively, if you want a more permanent and scalable solution, you can expose the service using an OpenShift Route:

oc expose svc/<service-name>

This command will create a route that makes the service accessible externally through a URL.

By understanding both methods, you can choose the one that best fits your use case. Port forwarding is great for temporary access during development, while creating a route is suitable for production environments requiring persistent external access

########################################## oc port-forward --address 0.0.0.0 svc/my-service 9090:8080

which can use all local IPs

⚠️ **GitHub.com Fallback** ⚠️