Edit on GitHub

Accessing your resource with endpoints

Access your resource with Kubernetes port forwarding

As you’re configuring resources in Tilt, you’ll often want to access an app within a Kubernetes resource, for example, a web app or a database server. Kubernetes provides port forwarding to allow you to access via your local machine with localhost. Tilt exposes this feature through a configuration in k8s_resource. For example, if you have in your Tiltfile:

k8s_resource(workload='blog-site', port_forwards=4002)

localhost:4002 will be connected to container port 4002. Tilt also displays a link at the top of the screen.

With:

k8s_resource(workload='blog-site', port_forwards='9000:4002')

localhost:9000 will be connected to container port 4002.

Naming port forwards

A resource may have multiple port forwards. You can configure them with:

k8s_resource(
   workload='blog-site',
   port_forwards=['9000:4002', '9001:4003']
)

And you would see:

In this case, a user may not know which port forward corresponds to which part of your app, without reading the Tiltfile. Tilt allows you to specify custom port forward names, displaying them instead of localhost:<port-forward>. For example, specifying this in the Tiltfile

k8s_resource(
   workload='blog-site',
   port_forwards=[
      port_forward(9000, 4002, name='blog-hero-post'), 
      port_forward(9001, 4003, name='blog-archives')
   ]
)

would show this in Tilt:

Read more in the port_forward API.

You can also associate aribitrary links with a resource, using link. For example, you may want to point users to a database URL for a database reset workflow. Specifying this in the Tiltfile:

k8s_resource(
   workload='blog-site',
   port_forwards=[
      port_forward(9000, 4002, name='blog-hero-post'), 
      port_forward(9001, 4003, name='blog-archives')
   ],
   links=[
      'blog-db.storage.acme.com',
      link('internal-eng.acme.com/docs/blog-db-reset', 'Blog db reset docs')
   ]
)

would show this in Tilt:

Arbitrary links are supported on both local_resource and k8s_resource.

 
 
 

Was this doc helpful?