Mounting ConfigMaps and Secrets as files
Mounting Kubernetes ConfigMaps and Secrets as files
Last updated
Was this helpful?
Mounting Kubernetes ConfigMaps and Secrets as files
Last updated
Was this helpful?
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.
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 .
To create a Secret, see .
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.
In the DuploCloud Portal, navigate to Kubernetes -> Services.
Select the Service you want to modify from the Name column.
Click the Actions menu and select Edit.
Click Next. The Advanced Options page displays.
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:
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:
Select Update to save the configuration. The ConfigMap will now be mounted into the container at runtime.
In the DuploCloud Portal, navigate to Kubernetes -> Services.
Select the Service you want to modify from the Name column.
Click the Actions menu and select Edit.
Click Next. The Advanced Options page displays.
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:
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:
Select Update to save the configuration. The Secret will now be mounted into the container at runtime.