Here is how to create a ConfigMap from a local file and mount it to a Pod.
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
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
.
Comments