Forward local ports to applications

Developers often need to interact directly with applications running in Spaces the same way as they do with applications running locally. For example, a developer might need to do this to debug or troubleshoot an application, or to obtain direct access to an internal API endpoint.

To make this application interaction possible, you can use the tanzu app port-forward command to forward a local port to a port on the remote application instance.

Examples of port forwarding

The following examples demonstrate different scenarios of port forwarding.

  • Forward local port 8080 to the remote port 80 of an application instance by running:

    tanzu app port-forward <app-instance-name> --port 8080:80
    
  • Listen on port 5000 locally, forwarding to the remote port 5000 of an application instance, by running:

    tanzu app port-forward <app-instance-name> --port 5000
    

    By only specifying one port value, the same port is used both locally and on the remote application instance.

  • Listen on port 8888 locally, forwarding to the remote port 5000 of an application instance, by running:

    tanzu app port-forward <app-instance-name> --port 8888:5000
    
  • If different application instances run in different Space replicas and the instances have the same name, specify the Space replica of the instance to which to forward the port by running:

    tanzu app port-forward <app-instance-name> --space-replica <space-name> <app-instance-name> --port 5000
    
    Note

    This scenario is rare.

Interactive mode

The tanzu app port-forward command includes an interactive mode. If you omit the name of the application instance, the Tanzu CLI prompts you to provide an application name and then to select a running instance of the application. For example:

tanzu app port-forward --port 5000

You can also provide an application name as input, in which case the Tanzu CLI prompts you to select a running instance of the application. For example:

tanzu app port-forward <app-name> --port 5000
check-circle-line exclamation-circle-line close-line
Scroll to top icon