Access a MLOps Studio notebook environment with kubectl port-forward

A MLOps Studio notebook environment can be accessed from a local machine by forwarding its service port with kubectl port-forward.

This method exposes the notebook service on a local port. You then open the notebook URL from an IDE or browser that supports remote Jupyter connections.

The terminal running the port-forward command must remain open while you work.

Prerequisites

Before you start, prepare the MLOps Studio workspace, running notebook, local kubectl configuration, and IDE support.

No. 1 MLOps Studio workspace access

You must be able to sign in to MLOps Studio and open the dashboard.

No. 2 Running MLOps Studio notebook

Start a MLOps Studio notebook before using port forwarding.

No. 3 kubectl and kubeconfig

The port-forward method requires kubectl on your local machine and a working KUBECONFIG file for the MLOps Studio namespace.

After configuring kubeconfig, verify that kubectl can reach the cluster:

kubectl get namespaces

If the command returns a list of namespaces, the local kubectl configuration is working.

Use the official Kubernetes installation instructions for your operating system:

No. 4 IDE support for remote Jupyter connections

The port-forward method can be used from any IDE that can connect to a remote Jupyter server. Visual Studio Code and PyCharm both support this type of connection.

Find the namespace, notebook, and service

First identify three values:

  • KUBEFLOW_NAMESPACE – the namespace that contains your notebook.

  • NOTEBOOK_NAME – the name of the notebook environment.

  • NOTEBOOK_SERVICE – the Kubernetes service that exposes the notebook.

List the namespaces available through your kubeconfig:

kubectl get namespaces

Use the namespace that contains your MLOps Studio notebook. In the examples below, this value is shown as KUBEFLOW_NAMESPACE.

List the notebooks in that namespace:

kubectl get notebooks -n KUBEFLOW_NAMESPACE

If the command returns notebook names, use the relevant value as NOTEBOOK_NAME.

If this command is not allowed in your namespace, use the notebook name shown in the MLOps Studio dashboard and continue by listing the services in the namespace.

Next, list the services in the same namespace:

kubectl get svc -n KUBEFLOW_NAMESPACE

The output usually contains service names, service types, cluster IP addresses, and ports. Look for the service whose name matches the notebook name or otherwise clearly identifies the notebook you want to open. In the examples below, this value is shown as NOTEBOOK_SERVICE.

To confirm the service port, describe the service:

kubectl describe svc NOTEBOOK_SERVICE -n KUBEFLOW_NAMESPACE

Check the Port field in the output. The examples below use service port 80, which is common for MLOps Studio notebook services.

Start the port-forward

Map a local port on your machine to the notebook service running in MLOps Studio.

If the notebook service uses port 80, run:

kubectl port-forward svc/NOTEBOOK_SERVICE 8888:80 -n KUBEFLOW_NAMESPACE

A successful port-forward shows output similar to:

Forwarding from 127.0.0.1:8888 -> 80
Forwarding from [::1]:8888 -> 80

Leave the terminal window open while you work. The port-forward stops when you close the terminal or interrupt the command.

If local port 8888 is already in use, choose another local port, for example 8889:

kubectl port-forward svc/NOTEBOOK_SERVICE 8889:80 -n KUBEFLOW_NAMESPACE

If the service uses a different service port, replace the value after the colon. For example, if the service port is 8888, use:

kubectl port-forward svc/NOTEBOOK_SERVICE 8888:8888 -n KUBEFLOW_NAMESPACE

Construct the notebook URL

After port forwarding is active, append the notebook base path to the local address.

If you forwarded local port 8888, use this format:

http://localhost:8888/notebook/KUBEFLOW_NAMESPACE/NOTEBOOK_NAME/

Replace KUBEFLOW_NAMESPACE with the namespace that contains your notebook, and NOTEBOOK_NAME with the notebook name identified earlier.

If you used another local port, replace 8888 with that port number.

Keep the trailing slash at the end of the URL. Some Jupyter-based notebook environments rely on the full base path and may not open correctly if the path is shortened.

Use the URL in your IDE

Use the constructed URL in an IDE that supports remote Jupyter connections, such as Visual Studio Code or PyCharm.

Keep the terminal with the port-forward command open for as long as you need the connection.

Notebook culling and port forwarding

Warning

Port forwarding does not prevent notebook culling.

If the notebook server is stopped because of kernel inactivity, the local notebook URL is no longer usable even if the kubectl port-forward command is still running.

Start the notebook server again from MLOps Studio, then restart the port-forward command if needed.

Troubleshooting port-forward access

If the port-forward command fails, check that the namespace, service name, and service port are correct:

kubectl get svc -n KUBEFLOW_NAMESPACE
kubectl describe svc NOTEBOOK_SERVICE -n KUBEFLOW_NAMESPACE

If local port 8888 is already in use, repeat the command with another local port, such as 8889.

If the IDE cannot open the notebook URL, confirm that the port-forward terminal is still running and that the URL contains the namespace, notebook name, selected local port, and trailing slash.

Stop port forwarding

To stop port forwarding, return to the terminal where the command is running and press Ctrl+C.

After the command stops, the local notebook URL is no longer available.

What to do next

After connecting from your IDE, you can write and run code locally while the execution remains inside the MLOps Studio environment.

For related notebook and MLOps Studio tasks, see:

For the alternative access method, see: