Mount ConfigMaps
Mount Kubernetes ConfigMaps into workspace containers to provide non-sensitive configuration data.
-
You have an active
kubectlsession with your namespace. See Overview of kubectl.By default, applying a
ConfigMapwith thecontroller.devfile.io/mount-to-devworkspace: 'true'label restarts all running workspaces in the namespace. To mount the ConfigMap only at workspace start and prevent automatic restarts, add thecontroller.devfile.io/mount-on-start: 'true'annotation.
-
Create a ConfigMap with the required labels and annotations:
kind: ConfigMap apiVersion: v1 metadata: name: my-config labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' annotations: controller.devfile.io/mount-as: file controller.devfile.io/mount-path: /etc/my-config data: settings.json: | { "editor.fontSize": 14, "editor.tabSize": 2 }where:
controller.devfile.io/mount-to-devworkspace-
Required label to mount the ConfigMap to all workspaces.
controller.devfile.io/watch-configmap-
Watch the ConfigMap for changes and update mounted files.
controller.devfile.io/mount-as-
Mount type:
file,subpath, orenv. controller.devfile.io/mount-path-
Path where the ConfigMap data is mounted.
-
Apply the ConfigMap to your namespace:
$ kubectl apply -f my-config.yaml -n <your_namespace> -
Optional: Add annotations to the ConfigMap to customize the mounting behavior.
Table 1. ConfigMap mounting annotations Annotation Description controller.devfile.io/mount-path: <path>Overrides the default mount path. The default mount path is
/etc/config/<ConfigMap_name>.controller.devfile.io/mount-as: fileEach key in the ConfigMap data becomes a file in the mount path directory.
controller.devfile.io/mount-as: subpathSimilar to
file, but uses subPath volumes for better compatibility.controller.devfile.io/mount-as: envEach key-value pair becomes an environment variable in all workspace containers.
controller.devfile.io/mount-on-start: 'true'When set to
true, the ConfigMap is mounted only when a workspace starts, not while it is already running. This prevents workspace restarts when the ConfigMap is created.controller.devfile.io/mount-to-devworkspace-include:Specifies a comma-separated list of
DevWorkspacename patterns. When set, the ConfigMap is mounted only to workspaces whose names match at least one pattern.controller.devfile.io/mount-to-devworkspace-exclude:Specifies a comma-separated list of
DevWorkspacename patterns. When set, the ConfigMap is mounted to all workspaces except those whose names match a pattern.When both controller.devfile.io/mount-to-devworkspace-includeandcontroller.devfile.io/mount-to-devworkspace-excludeannotations are set, the ConfigMap is mounted only to workspaces that match the include pattern and do not match the exclude pattern.For example, to mount ConfigMap data as environment variables:
kind: ConfigMap apiVersion: v1 metadata: name: my-env-config labels: controller.devfile.io/mount-to-devworkspace: 'true' controller.devfile.io/watch-configmap: 'true' annotations: controller.devfile.io/mount-as: env data: LOG_LEVEL: debug MAX_CONNECTIONS: "100" -
Start or restart your workspace to apply the mounted ConfigMap.
-
For
fileorsubpathmounts, verify the ConfigMap data is available at the mount path:$ cat /etc/my-config/settings.json -
For
envmounts, verify the environment variables are set:$ echo $LOG_LEVEL