Skip to main content

Custom Ports

Purpose​

Custom ports serve a crucial role in publishing APIs or Frontend applications to the internet or integrating different resources within a namespace. These ports can be opened and managed using CGC ingress.

Using Ports for Applications​

Applications, like Streamlit frontend or FastAPI, can be initiated from a Jupyter Notebook using the built-in terminal and then published via a specified port using CGC ingress.

To restrict access only within your namespace, you can utilize the --no-ingress flag, preventing exposure to the public internet.

Managing Compute Ports​

CGC provides a set of commands to manage ports associated with compute resources:

cgc compute port --help

This command provides several options:

  • add: Add a port to a running resource
  • delete: Delete a port from a running resource
  • list: List all ports for a running resource
  • update: Update a port in a running resource

Adding Ports​

To open a port for a specific compute resource:

cgc compute port add <RESOURCE_NAME> -n <PORT_NAME> -p <PORT_NUMBER>

For internal use within your namespace, add the -ni or --no-ingress flag.

Listing and Deleting Ports​

List all opened ports for a given compute resource:

cgc compute port list <RESOURCE_NAME>

To delete an unnecessary port:

cgc compute port delete <RESOURCE_NAME> -n <PORT_NAME>

Example Scenario​

Imagine you're building a Streamlit frontend for a GPU-accelerated application. Besides the default path leading to the Jupyter webUI, you can introduce a suffix like /app to serve your application.

Application Setup​

Assuming a compute resource named llm-testing in the dynamic-startup namespace, the base URL to access the development environment's webUI would be:

https://llm-testing.dynamic-startup.cgc-krk-01.comtegra.cloud/?token=YOUR-TOKEN

Under this environment, you've created a Streamlit script serving the frontend at port 9000.

warning

Ensure that the host for your custom application always points to 0.0.0.0 as it's containerized, and network routing is managed by Kubernetes.

Creating a Port​

As your frontend is served internally, other pods or internet traffic cannot access it. To make it accessible, set up a new port:

cgc compute port add llm-testing -p 9000 -n custom-app
Save your work

Note that your compute resource will be reloaded.

Upon completion of the reload, the port 9000 of your compute resource (Streamlit frontend) will be accessible at:

https://llm-testing.dynamic-startup.cgc-krk-01.comtegra.cloud/custom-app

To restrict access to the namespace network only, use the -ni or --no-ingress flag.

Considerations​

If your custom app lacks an authentication mechanism, it will be accessible to everyone. Be cautious when publishing sensitive data. Always use API keys or authentication to secure your endpoints.