# Mounting ConfigMaps and Secrets as files

In Kubernetes, you can mount ConfigMap or Secret data as files into a container, allowing your workloads to read configuration values at runtime without hardcoding them into images or code.

## Prerequisites

Before you can mount a ConfigMap or Secret as a file in a container, complete the following setup:

* **Create a DuploCloud Service.**\
  The Service defines the container into which the ConfigMap or Secret will be mounted.\
  You can create a Service by navigating to **Kubernetes** → **Services** in the DuploCloud Portal.
* **Create the ConfigMap or Secret.**
  * To create a ConfigMap, see [Creating a Kubernetes ConfigMap](#creating-a-kubernetes-configmap).
  * To create a Secret, see [Creating a Kubernetes Secret](#creating-a-kubernetes-secret).

Each ConfigMap or Secret should include the file data you want to mount, using key/value pairs where the key is the filename and the value is the file’s contents.

## Mounting a Kubernetes ConfigMap as a Volume

1. In the DuploCloud Portal, navigate to **Kubernetes** -> **Services**.
2. Select the Service you want to modify from the **Name** column.
3. Click the **Actions** menu and select **Edit**.
4. Click **Next**. The **Advanced Options** page displays.
5. In the **Volumes** field on the **Advanced Options** page, enter the appropriate YAML configuration to define the volume mount. See examples below.

**Example: Mounting a ConfigMap as a Volume**

To mount a ConfigMap named `my-config-map` to a directory named `/app/my-config`, use the following configuration:

```yaml
- Name: my-config
  Path: /app/my-config
  Spec:
    ConfigMap:
      Name: my-config-map
```

<figure><img src="https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2FYJlu2hlcdssEGZzLaBhf%2FAzure_edit_serv_2.png?alt=media&#x26;token=2abd5d44-921e-4369-9308-4203df2d8f1a" alt=""><figcaption><p>The <strong>nginx Service</strong> <strong>Advanced Options</strong> page in the DuploCloud Portal</p></figcaption></figure>

**Example: Mounting an Individual File from a ConfigMap**

To mount an individual file (e.g., `my-file-name`) from the ConfigMap to a specific location (e.g., `/app/my-config/config-file`), use the following configuration:

```yaml
  Path: /app/my-config
  Spec:
    ConfigMap:
      Name: my-config-map
      Items:
      - Key: my-file-name
        Path: config-file
```

6. Select **Update** to save the configuration. The ConfigMap will now be mounted into the container at runtime.

## Mounting a Kubernetes Secret as a Volume

1. In the DuploCloud Portal, navigate to **Kubernetes** -> **Services**.
2. Select the Service you want to modify from the **Name** column.
3. Click the **Actions** menu and select **Edit**.
4. Click **Next**. The **Advanced Options** page displays.<br>

   ![The nginx Service Advanced Options page in the DuploCloud Portal](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2FaM3XSjTc3hK6k6X06uNt%2FScreen%20Shot%202022-03-21%20at%2012.52.19%20PM.png?alt=media\&token=7ffd55cd-a6e3-4e4a-bdeb-edc27f3c3af8)
5. In the **Volumes** field on the **Advanced Options** page, enter the appropriate YAML configuration to define the volume mount. See examples below.

**Example: Mounting a Secret as a Volume**

To mount a Secret named `my-secret-files` to a directory named `/app/my-config`, use the following configuration:

```yaml
- Name: my-config
  Path: /app/my-config
  Spec:
    Secret:
      SecretName: my-secret-files
```

**Example: Mounting an Individual Secret Item**

If you want to select individual Secret items (e.g., `secret-file`) and specify the subpath for mounting (e.g., `/app/my-config/config-file`) use the following configuration:

```yaml
- Name: my-config
  Path: /app/my-config
  Spec:
    Secret:
      SecretName: my-secret-files
      Items:
      - Key: secret-file
        Path: config-file
```

6. Select **Update** to save the configuration. The Secret will now be mounted into the container at runtime.
