Mounting Files with ConfigMap in Kubernetes
2023-03-11 01:01 (2 years ago)
Here is how to create a ConfigMap from a local file and mount it to a Pod.
Creating a ConfigMap from a File
First, create a ConfigMap from a local file using the following command:
kubectl -n my-namespace create configmap my-config-file --from-file=../my-config-file.conf
Mounting the ConfigMap in a Deployment
Next, mount this ConfigMap in a Deployment by specifying the volumeMounts and volumes sections in your YAML file:
apiVersion: apps/v1
kind: Deployment
metadata:
namespace: torico
spec:
...
template:
spec:
containers:
- name: <container-name>
...
volumeMounts:
- name: my-config-file-volume
mountPath: /app/config/my-config-file.conf
subPath: my-config-file.conf
volumes:
- name: my-config-file-volume
configMap:
name: my-config-file
In this configuration, only the file my-config-file.conf inside my-config-file-volume will be mounted as /app/config/my-config-file.conf.
Currently unrated
The author runs the application development company Cyberneura.
We look forward to discussing your development needs.
We look forward to discussing your development needs.