Skip to content

Latest commit

 

History

History
120 lines (84 loc) · 5.1 KB

mounting-config-as-files.md

File metadata and controls

120 lines (84 loc) · 5.1 KB
description
Mounting application configuration maps and secrets as files

Mounting ConfigMaps and Secrets as files

In Kubernetes, you can mount application configurations or secrets as files.

Creating and mounting a Kubernetes ConfigMap

{% hint style="warning" %} Before you create and mount the Kubernetes ConfigMap, you must create a DuploCloud Service. {% endhint %}

Creating a Kubernetes ConfigMap

  1. In the DuploCloud Portal, navigate to Kubernetes -> Config Maps.
  2. Click Add. The Add Kubernetes Config Map pane displays.
  3. Give the ConfigMap a name, such as my-config-map.
  4. In the Data field, add a key/value pair for each file in your config map, separated by a colon (:). The key is the file name, and the value is the file's contents.
  5. Click Create.

Add Kubernetes Config Map pane

Editing the DuploCloud Service

  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.

Actions menu on the Services page

Mounting the Kubernetes ConfigMap as a volume

  1. On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.
  2. In the Volumes field on the Advanced Options page, enter the configuration YAML to mount the ConfigMap as a volume.

Example: mounting a ConfigMap as a volume

For example, to mount a config map named my-config-map to a directory named /app/my-config enter the following YAML code block in the Volumes field:

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

Mouting ConfigMap as a volume in the Advanced Options page

Example: adding a Key value to select individual ConfigMap items

If you want to select individual ConfigMap items and specify the subpath for mounting, you can use a different configuration. For example, if you want the key named my-file-name to be mounted to /app/my-config/config-file use the following YAML:

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

Creating and Mounting a Kubernetes Secret

Before you create and mount a Kubernetes Secret, you must create a DuploCloud Service.

Creating a Kubernetes Secret

  1. In the DuploCloud Portal, navigate to Kubernetes -> Secrets.
  2. Click Add. The Add Kubernetes Secret pane displays.
  3. Give the secret a name, such as my-secret-files.
  4. Add Secret Details such as a key/value pair for each file in your secret separated by a colon (:). The key is the file name, and the value is the file's contents.
  5. Click Add to create the secret.

Add Kubernetes Secret pane

Creating a multi-line Kubernetes Secret

  1. Follow the steps in creating a Kubernetes Secret, defining a Key value using the PRIVATE_KEY_FILENAME in the Secret Details field, as shown below.
  2. Click Add to create the multi-line secret.

Mounting a Kubernetes Secret as a volume

  1. In the DuploCloud Portal, edit the DuploCloud Service.
  2. On the Edit Service: service_name Basic Options page, click Next to navigate to the Advanced Options page.
  3. In the Volumes field on the Advanced Options page, enter the configuration YAML to mount the Secret as a volume.

Example: mounting a Kubernetes Secret as a volume

For example, to mount a Secret named my-secret-files to a directory named /app/my-config Enter the following YAML code block in the Volumes field:

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

Mouting a Secret as a volume in the Advanced Options page

Example: adding a Key value to select individual Secret items

If you want to select individual Secret items and specify the subpath for mounting, you can use a different configuration. For example, if you want the key named secret-file to be mounted to /app/my-config/config-file use the following YAML:

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