Skip to main content
Version: 6.x (Latest)

Port Forwarding

DevSpace allows you to forward network traffic from your local machine to the dev container and vice versa:

  • Port forwarding for traffic forwarding from local machine to the dev container
  • Reverse port forwarding for traffic forwarding from the dev container to your local machine (e.g. to let your application connect to your IDE for debugging)
Think kubectl port-forward on Steroids

You can think of the port forwarding in DevSpace as a much faster and smarter version of kubectl port-forward that continuously reconnect whenever the connection gets lost and that is also able to reverse port forward from the container to your local machine.

Port Forwarding vs Reverse Port Forwarding

When you define 8080:80:

  • as value in ports then you can connect to localhost:8080 on your local machine and it will be the same as connecting to localhost:80 from within the container
  • as value in reversePorts then a service inside your dev container can connect to localhost:80 from inside the container and it will be the same as connecting to localhost:8080 on your local machine

Port-forwarding allows you to access your application on localhost:[PORT] by forwarding the network traffic from a localhost port to a specified port of a container.

Port Forwarding

When starting the development mode, DevSpace starts port forwarding as configured in the dev.*.ports section of the devspace.yaml.

devspace.yaml
deployments:
app-backend:
helm:
values:
containers:
- image: john/devbackend

dev:
app:
imageSelector: ghcr.io/org/project/image # The dev container you are selecting
ports:
- port: "8080:80" # Map localhost port 8080 to container port 80
Unique Local Port

The localhost port must be unique to avoid conflicting ports.

System Ports

Using a port < 1024 is likely to cause problems as these ports are reserved as system ports.

Reverse Port Forwarding

Reverse port-forwarding allows you to forward traffic from within your containers to your local machine. This can be useful when:

  • using certain remote debuggers that connect to your IDE instead of the other way around
  • developing a service on localhost which should be accessed from other services that run within the cluster, i.e. using the Telepresence development model but with DevSpace to get better performance and cross-platform support

With reverse port-forwarding, you can access localhost:[PORT] inside the container and it will redirect to a program that runs on your local dev machine.

When starting the development mode, DevSpace starts reverse port-forwarding as configured in the dev.*.reversePorts section of the devspace.yaml.

devspace.yaml
deployments:
app-backend:
helm:
values:
containers:
- image: ghcr.io/org/project/image

dev:
app:
imageSelector: ghcr.io/org/project/image
ports:
- port: "8080:80" # Map localhost port 8080 to remote port 80
reversePorts:
- port: "5678:6678" # Map localhost port 5678 to remote port 6678

Config Reference

Port Forwarding

reversePorts required object[]

ReversePorts are port mappings to make local ports available inside the container

port required string

Port is a port mapping that maps the localPort:remotePort. So if you port forward the remote port will be available at the local port. If you do reverse port forwarding, the local port will be available at the remote port in the container. If only port is specified, local and remote port are the same.

bindAddress required string

BindAddress is the address DevSpace should listen on. Optional and defaults to localhost.

ports required object[]

Ports defines port mappings from the remote pod that should be forwarded to your local computer

port required string

Port is a port mapping that maps the localPort:remotePort. So if you port forward the remote port will be available at the local port. If you do reverse port forwarding, the local port will be available at the remote port in the container. If only port is specified, local and remote port are the same.

bindAddress required string

BindAddress is the address DevSpace should listen on. Optional and defaults to localhost.