.env file, you ensure your local process runs with the exact same configuration as in the cluster.
1. Intercept the Remote Service
Suppose you have aproducts service deployed in your Kubernetes cluster. To forward traffic from that service to your local machine, run:
3000 to your local port 8000, but it doesn’t pull in any environment variables by default.
2. Inspect the Deployment’s Environment Variables
Your Kubernetes deployment might define variables like this:API_URL, LOG_LEVEL, and any other container-specific settings.
3. Generate a Local .env File
Telepresence can automatically dump all container environment variables into a file. Simply add the --env-file flag to your intercept command:
.env file in your current directory containing:
You can choose any filename for the environment file (e.g.,
dev.env or products.env). Just update your intercept command accordingly.4. Load the .env File in Your Local Process
Most development tools support dotenv files out of the box. For example, with a Node.js application you can:
Avoid committing your
.env file to version control if it contains sensitive data. Add it to your .gitignore instead.5. Summary of Key Flags
| Flag | Description | Example |
|---|---|---|
--port | Forward remote port to local | --port 8000:3000 |
--env-file | Dump container environment variables to file | --env-file .env |