> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Demo Volumes

> Guide to using Telepresence to mount Kubernetes pod volumes including ConfigMap files to your local machine for development and intercepting services so local processes can access in-cluster configuration

In this lesson we'll learn how to access Kubernetes volumes attached to a pod when intercepting that service with Telepresence for Kubernetes. By mounting pod volumes on your local machine you can let a local process read the same ConfigMaps or files the in-cluster pod uses — enabling a dev workflow where your local service behaves like the cluster service.

Key pieces:

* A local Node.js application that simulates the service.
* A Deployment that mounts a ConfigMap as a volume.
* The ConfigMap with the data keys.
* Telepresence intercept steps that mount the pod volume locally.

## Local Node.js example (local service)

This Node.js example reads configuration from the environment (`process.env`) but, when using Telepresence mounts, you can also read values from files placed by a ConfigMap mount.

```javascript theme={null}
require('dotenv').config({ override: true });
const express = require('express');
const app = express();
const port = 8000;

const apiURL = process.env.API_URL;
console.log('API_URL:', apiURL);

const products = [
  {
    id: 1,
    name: "iphone 14",
    price: 900,
    category: "electronics",
    onSale: false,
  }
];

app.get('/products', (req, res) => {
  res.json(products);
});

app.listen(port, () => {
  console.log(`Products service listening on port ${port}`);
});
```

## Deployment volume configuration (mounting a ConfigMap)

This snippet shows the Deployment mounting a ConfigMap named `db-info` as a volume called `db-config` into the pod at `/tmp`.

```yaml theme={null}
spec:
  selector:
    matchLabels:
      app: products
  template:
    metadata:
      labels:
        app: products
    spec:
      volumes:
      - name: db-config
        configMap:
          name: db-info
      containers:
      - name: products
        image: sanjeevkt720/telepresence-products
        imagePullPolicy: Always
        volumeMounts:
        - name: db-config
          mountPath: /tmp
        ports:
        - containerPort: 3000
          name: web
        env:
          # environment entries (if any)
```

## ConfigMap (db-info)

The ConfigMap contains DB connection values that will appear as files when mounted as a volume.

```yaml theme={null}
apiVersion: v1
kind: ConfigMap
metadata:
  name: db-info
data:
  DB_HOST: "prod.db"
  DB_PASSWORD: "mypassword123"
  DB_USERNAME: "myusername123"
```

## How it works — explanation

* The Deployment mounts the `db-info` ConfigMap into the pod at `/tmp` using a volume named `db-config`.
* When the ConfigMap is mounted as a volume, Kubernetes creates files in the container filesystem — one file per key (`DB_HOST`, `DB_PASSWORD`, `DB_USERNAME`) with the corresponding content.
* When you run a Telepresence intercept that mounts pod volumes, Telepresence mirrors that volume onto your local filesystem so your local process can access the same files.
* Telepresence either creates a random mount path by default or you can request a specific mount path.

<Callout icon="warning" color="#FF6B6B">
  Mounting a ConfigMap as files does not populate process environment variables (e.g., `process.env`). If your application expects env vars, either: (a) use `envFrom` or explicit `env` entries in the Deployment for in-cluster pods, (b) read the files from the Telepresence mount in your local app, or (c) generate a local `.env` or export variables before running your local process.
</Callout>

## Quick reference table

| Resource | Purpose | Example / Notes |
| - | - | - |
| Node.js app | Local service for development | Reads `process.env` or files from Telepresence mount |
| Deployment volume | Mounts ConfigMap into pod filesystem | volume `db-config` -> mountPath `/tmp` |
| ConfigMap `db-info` | Stores DB keys as plain data | Keys become files: `DB_HOST`, `DB_PASSWORD`, `DB_USERNAME` |
| Telepresence intercept | Mounts pod volumes to local filesystem | `telepresence intercept products-depl -p 8000 --env-file .env --mount=true` |

## Telepresence commands and examples

Check current intercepts:

```bash theme={null}
telepresence list
# Example output:
# auth-depl       : ready to intercept (traffic-agent already installed)
# inventory-depl  : ready to intercept (traffic-agent not yet installed)
# products-depl   : ready to intercept (traffic-agent already installed)
```

Create an intercept and mount volumes (automatic/random mount location):

```bash theme={null}
telepresence intercept products-depl -p 8000 --env-file .env --mount=true
```

When you run that command, Telepresence prints details similar to:

```text theme={null}
Workload kind              : Deployment
Destination                : 127.0.0.1:8000
Service Port Identifier   : 3000/TCP
Volume Mount Point        : /tmp/telfs-2189772442
Intercepting              : all TCP connections
```

Open a new shell and inspect the automatic mount point (use the mount path shown in your Telepresence output):

```bash theme={null}
# change into the Telepresence mount folder shown in output
cd /tmp/telfs-2189772442/tmp

ls
cat DB_HOST
cat DB_PASSWORD
# mypassword123
```

Note: Telepresence exposes the ConfigMap keys as files in the mount directory. Your local application must either read those files (or use symlinks) or you must set environment variables locally so the app can access config via `process.env`.

<Callout icon="lightbulb" color="#1CB2FE">
  If you prefer a consistent local path instead of a random Telepresence mount path, you can specify a fixed mount path with the `--mount=` option. Ensure the target directory is writable by Telepresence.
</Callout>

### Specify a custom mount path

1. Leave the current intercept:

```bash theme={null}
telepresence leave products-depl
```

2. Re-intercept and provide a mount path (example ` /tmp/example123`):

```bash theme={null}
telepresence intercept products-depl -p 8000 --env-file .env --mount=/tmp/example123
```

Inspect the chosen path:

```bash theme={null}
cd /tmp/example123/tmp

ls
cat DB_HOST
# prod.db
```

## Summary

* Telepresence for Kubernetes can mount Kubernetes volumes (including ConfigMaps mounted as volumes) into a local directory when you intercept a service.
* By default Telepresence creates a mount at a random path; use `--mount=/path` to choose a fixed path.
* Mounting a ConfigMap exposes its keys as files — it does not automatically create environment variables in your local process. Adjust your local application to read the Telepresence mount, create symlinks, or export variables before running.

## Links and references

* Telepresence course: [Telepresence for Kubernetes](https://learn.kodekloud.com/user/courses/telepresence-for-kubernetes)
* Project docs: [Telepresence documentation](https://www.telepresence.io/)
* Kubernetes docs: [ConfigMap](https://kubernetes.io/docs/concepts/configuration/configmap/) and [Volumes](https://kubernetes.io/docs/concepts/storage/volumes/)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/telepresence-for-kubernetes/module/0eb5dcb6-2e2a-40d9-9caa-bd3149741aeb/lesson/c92e854c-3059-4a2d-9082-e9c021269560" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.