I am new to Kubernetes, but I have been using Docker and Docker Compose for a long time. I am trying to find more information about how Kubernetes handles shared/read only config files compared to Docker Compose.
In my docker-compose.yaml
file I am sharing specific config files to my containers using bind mounts, similar to this:
...
elasticsearch:
image: elasticsearch:7.3.2
environment:
- discovery.type=single-node
networks:
mycoolapp:
aliases:
- elasticsearch
ports:
- "9200:9200"
- "9300:9300"
volumes:
- elasticdata:/usr/share/elasticsearch/data
- ./elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
...
I have been reading up on Persistent Volumes and I believe this is what I need, however, my understanding still isn't 100% clear on a few issues.
azureFile
for my volume type, and I have copied my configs into the file share. How do I mount a sub folder of the file share into my container? mountPath
only appears in volumeMounts
, and I can't find where the corresponding location within the volume are.Kubernetes ConfigMap object will come handy here.
A ConfigMap is an API object used to store non-confidential data in key-value pairs.
Example:
apiVersion: v1
kind: ConfigMap
metadata:
name: elastic-demo
data:
# property-like keys; each key maps to a simple value; available as env var
properties_file_name: "database.properties"
# file-like keys
database.properties: |
data1=value1
data2=value2
You can mount the above ConfigMap in volume in read only mode.
apiVersion: v1
kind: Pod
metadata:
name: mypod
spec:
containers:
- name: mypod
image: elasticsearch
volumeMounts:
- name: elastic-volume
mountPath: "/etc/foo"
readOnly: true
volumes:
- name: elastic-volume
configMap:
name: elastic-demo
As @Pulak said it correctly you can use configmap. I saw you want to import a folder containing 100s of files into a configmap. What I think is, you can do this in another way. That is using zip/jar file as ConfigMap support binary file, so after mounting it can be unzipped into your desired path inside the container.
For example you have below structure in the folder:
.
├── test1.html
├── test2.css
├── test3.xml
└── testN.html
Now you can make them jar/zip and can create a configmap by kubectl create configmap example --from-file=./
Another thing is configmap size (in terms of MiB) should not be large. So, if you really have lot of things than can use kubernetes typical volumes.