Skip to main content
In this guide, we’ll walk through intercepting the products deployment with Telepresence, exporting its Kubernetes environment variables into a .env file, and running the service locally so it can call the inventory service exactly as it does inside the cluster.

1. Reproducing the Error

First, start an intercept on the products deployment:
When you request multiple products, you’ll see this in your local logs:
This error shows that API_URL is undefined in your local environment.

2. Application Code (index.js)

The service reads API_URL from the environment and queries the inventory service:

3. Kubernetes Deployment Spec

Normally, the Pod spec injects API_URL:
Since Telepresence runs the container locally, those Pod environment variables won’t be available by default.

4. Pulling Environment Variables with Telepresence

  1. Stop and remove the current intercept
  2. Restart with .env dump and mount
    This generates my-envs.env:
The --mount=true flag ensures your local process can read my-envs.env as if it were on your filesystem.

5. Loading the .env File in Node.js

Install and configure dotenv:
At the top of index.js, override existing env vars:
Now when you run the intercept, process.env.API_URL matches the cluster’s value.

6. Testing the Setup

With the intercept active, send a request through your cluster’s LoadBalancer:
You should receive:
This confirms that your local service reads the same environment variables as in Kubernetes and correctly calls the inventory service.

Watch Video