Networking
Networking is how applications can communicate with other applications or databases. There are two main ways this can be achieved:
- Public networking: Connections that are accessible from the Internet or external networks. This makes an Internet round-trip, so it can be slower than private networking. With Kinsta’s Application Hosting, you can connect to your application publicly using a specific port or TCP proxy.
- Private networking: Connections that stay within our network and are not directly accessible from the Internet. We strongly recommend this method if you’re connecting applications hosted on Kinsta or linking an application with a database also hosted on Kinsta. To use Kinsta’s private network, all applications and databases must use the same data center.
You can configure a port, add a TCP proxy, or add an internal connection within Applications > app name > Networking.
Public Networking
Expose HTTP(S) Traffic
![The domain, hostname and port of the application.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-expose-https-traffic-1024x198.png&w=2048&q=75)
By default, the port for your application’s web process is 8080. This port is available during application runtime on the $PORT environment variable. You can define a different port; however, it must be within the range 1-65535 except for the following ports used by our core system: 15000, 15001, 15004, 15006, 15008, 15009, 15020, 15021, 15053, and 15090.
To configure a specific port for your application, click Edit port, enter the new port, and click Update.
![Edit the port for the application web process.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-edit-port-1024x321.png&w=2048&q=75)
Private Networking
This shows the hostname for all of the application processes. You can use the hostname to connect to the processes on Kinsta’s private network.
![Hostnames for the application processes.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-hostnames-1024x248.png&w=2048&q=75)
Connected Services
This shows any applications or databases that are connected to the current application over Kinsta’s private network.
![Services connected to your application on Kinsta's private network.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-connected-services-1024x230.png&w=2048&q=75)
Add a Private Connection
You can add a private connection from an application’s Networking page or a database’s Overview page. Wherever you start the process, the result will be the same.
To add a connection from an application to another application or database, go to Applications > app name > Networking > in the Connected services section, click Add connection, and select the application or database you’d like to create the internal connection to.
![Add an internal connection from an application or database to an application in MyKinsta.](https://kinsta.com/wp-content/uploads/2023/11/application-add-internal-connection-1024x440.png)
Environment Variables
We can automatically populate an application’s environment variables from the connection details. Do not copy and paste the internal connection details into environment variables. Click Add connection or Add application and select the Add environment variables… checkbox. This will automatically populate the environment variables from the application or database you’re connecting to.
Some applications may expect environment variables (keys) with different names. You can edit the names in the list before adding the connection or edit them later on the application’s Environment variables page.
![Automatically fill environment variables from the database connection details.](https://kinsta.com/wp-content/uploads/2023/11/application-add-internal-connection-environment-variables-1024x936.png)
Private Connections and the Build Process
Private connections are only available during runtime; they are not available during the build process.
If your application tries to connect to a database using an internal connection during the build process, this causes an error that says the database is not running, which makes the build fail. This is expected because the internal connection is not live during the build; it can only be used during runtime.
There are a couple of ways to work around this.
Option 1: Move the logic that connects to the database from the application’s build command to the start command. For example: if you have a command like prisma migrate
in the build process and move that command to the start command, your application will only access the database during runtime, and the build will be successful.
Option 2: Add separate environment variables as needed for the database connection, one available for the build process, and the other only for runtime. The keys can be the same (e.g. DB_CONNECTION_URL
) as long as one is only available during the build process and the other is only available during runtime. Use the database’s External connection details (Databases > dbname > Overview > External connections) for the values of any variables to be used in the build process.
Ports
The port for internal connections to an application can be defined when you add your application or within Networking > Edit port. The port for internal connections to a database is 3306 and cannot be changed.
For applications, Kinsta automatically sets the PORT
environment variable. You do not need to define it yourself or hard-code it into the application. When an application is deployed, it is reachable on the internet on ports 80 and 443, and we route those ports to the container on the port defined by your application.
Remove a Private Connection
If you need to remove a connection, go to the Application’s Networking page, and under Connected services, click the delete (trash can) icon.
![Internal connections between databases and applications.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-connected-services-1024x230.png&w=2048&q=75)
In the Delete connection modal/pop-up, click Delete connection to confirm and remove the connection to the application.
![Removing an internal connection.](https://kinsta.com/_next/image/?url=https%3A%2F%2Fkinsta.com%2Fwp-content%2Fuploads%2F2023%2F11%2Fapplication-networking-delete-connection-1024x249.png&w=2048&q=75)