Ports & Service Links

How ports are allocated across parallel environments, how to pin a port manually, and how services automatically connect to each other.

Running multiple branches side by side usually breaks in two ways: port collisions and services failing to find each other. This page explains how Kovra handles both.

Port allocation

  • Main environment: Uses the project’s default configured ports.
  • Other environments: Each service starts from its default port and steps by 10 to find a free port—for example 8001, then 8011, 8021, and so on. Once assigned, the port stays fixed for that environment.

Kovra checks the port again right before starting a service to verify it is actually free. If another program is holding the port, Kovra shows a clear warning.

Pin a port manually

To assign a specific port to a service in an environment, click its port in the service page header or the Overview list and enter a number in the popover:

  • Must be between 1 and 65535;
  • Cannot collide with another environment or service in the same project;
  • If the port is already in use by another program or below 1024, Kovra shows a warning but still allows saving.

Automatic allocation never overwrites or claims a port you pinned manually.

Single-instance services

Some services hardcode their port and cannot accept one externally. Kovra marks these as single-instance: all other environments borrow the main environment’s instance rather than starting a separate one.

If Kovra detected the wrong default port for a service, you can change it in service settings.

Passing ports to services

Kovra passes the assigned port using whichever mechanism the service expects:

  • Environment variables: For example, SERVER_PORT for Spring Boot or PORT for Node services.
  • CLI arguments: For example, vite --port or flask run --port, via {{port}} in the start command.

See Supported Stacks for how each stack receives its port.

Frontends typically need to know the backend’s address, such as a dev server proxy target. Kovra scans these files to discover which environment variable points to which service:

  • .env*
  • vite.config.*
  • application*.yml
  • Python entry files

For example, env.VITE_API_PROXY_TARGET || 'http://127.0.0.1:8001' is detected as VITE_API_PROXY_TARGET pointing to the api service.

At startup, Kovra sets that variable to the actual address of the target service in the same environment. Anything it cannot detect is left untouched.

Kovra only injects environment variables—it never modifies your files, nor does it load or inject your repository’s .env file.

Merge modes: append and replace

Service links support two merge modes:

  • append: When the original value is a comma-separated list of URLs, Kovra keeps the existing entries and appends the current environment’s address.
  • replace: In all other cases, Kovra replaces the entire value with the current environment’s address.

When not specified, Kovra infers the mode from the variable’s original value in your project files. To set it explicitly, specify mode: append or mode: replace in the project file. If the computed value matches the original value, Kovra skips injecting it.

Environment variable precedence

When the same variable is defined in multiple places, later sources override earlier ones:

  1. System environment variables;
  2. Service env settings and profile;
  3. Service links;
  4. Kovra-managed variables: the port variable, KOVRA_ENV, and KOVRA_PORT.

See Project File YAML Reference for configuration syntax.

Edit this page on GitHub ↗