I have a postgres instance that I generally spin up using a docker-compose.yml
file. It mounts some configuration files like this:
volumes:
- postgres-volume:/var/lib/postgresql/data
- ./postgresql.conf:/etc/postgresql.conf
- ./logs:/logs
- ./pg_hba.conf:/etc/pg_hba.conf
These files are located in the same folder as the docker-compose.yml
file is.
My question is: how do I make a Pod that contains this container also mount these configuration files? I read something about PVC in Kubernetes but I'm having a hard time connecting the dots and going from the docker-compose way of thinking to the Kubernetes way of thinking.
Any help is greatly appreciated.
CodePudding user response:
Easiest approach would be to store the files in a ConfigMap
and mount those as volumes in the container.
apiVersion: v1
kind: ConfigMap
metadata:
name: my-config
data:
my.properties: |
url=example.com
username=username
password=password
index.html: |
Hello world
[...]
containers:
- name: my-container
image: some-registry/some-image
volumeMounts:
- name: config-volume
mountPath: /etc/config/my.properties
subPath: my.properties
- name: config-volume
mountPath: /some/different/path/index.html
subPath: index.html
volumes:
- name: config-volume
configMap:
name: my-config
[...]
By that the my.properties
file is mounted into /etc/config
and index.html
into /some/different/path
of the my-container
file system.
You can also generate the configmap from the file by kubectl create configmap my-config --from-file /path/to/my.properties --from-file /path/to/index.html
See docs for more info on that.