I am facing issues when mounting a path.My objective is to make the data persistent even when the pod restarts.But its creating a new directory which doesnt have any of my config files. How to mount a entire directory without overriding it? I should have all my database data inside the path eventhough the pod restarts.In my scenario,its creating a new path.
my dockerfile
FROM centos:7
ENV DIR /binaries
ENV PASS admin
WORKDIR ${DIR}
COPY libstdc++-4.8.5-39.el7.x86_64.rpm ${DIR}
COPY numactl-libs-2.0.12-3.el7.x86_64.rpm ${DIR}
COPY mysqlmonitor-8.0.18.1217-linux-x86_64-installer.bin ${DIR}
RUN yum install -y libaio && yum -y install gcc && yum -y install gcc-c++ && yum -y install compat-libstdc++-33 && yum -y install libstdc++-devel && yum -y install elfutils-libelf-devel && yum -y install glibc-devel && yum -y install libaio-devel && yum -y install sysstat
RUN yum install -y gcc && yum install -y make && yum install -y apr-devel && yum install -y openssl-devel && yum install -y java
RUN rpm -ivh numactl-libs-2.0.12-3.el7.x86_64.rpm
RUN useradd sql
RUN chown sql ${DIR}
RUN chmod 777 ${DIR}
RUN chmod 755 /home/sql
USER sql
WORKDIR ${DIR}
RUN ./mysqlmonitor-8.0.18.1217-linux-x86_64-installer.bin --installdir /home/sql/mysql/enterprise/monitor --mode unattended --tomcatport 18080 --tomcatsslport 18443 --adminpassword ### --dbport 13306
RUN rm -rf /binaries/*
VOLUME /home/mysql/mysql/enterprise/monitor/mysql/data
ENTRYPOINT ["/bin/bash", "-c", "/home/sql/mysql/enterprise/monitor/mysqlmonitorctl.sh start && tail -f /home/sql/mysql/enterprise/monitor/apache-tomcat/logs/mysql-monitor.log"]
my deployment file
apiVersion: apps/v1
kind: Deployment
metadata:
name: mypod
spec:
replicas: 1
selector:
matchLabels:
app: mem
template:
metadata:
labels:
app: mem
spec:
containers:
- name: mem
image: 22071997/mem
command:
volumeMounts:
- mountPath: /home/sql/mysql/enterprise/mysql/data
name: volume
volumes:
- name: volume
persistentVolumeClaim:
claimName: mem-pvc2
output:
[sql@mypod-67cb4f85b8-9km26 data]$ pwd
/home/sql/mysql/enterprise/mysql/data
[sql@mypod-67cb4f85b8-9km26 data]$ ls
[sql@mypod-67cb4f85b8-9km26 data]$
By default when you mount some volume over a existent path, the content of this existent path will be hidded.
If you want to keep both there is an option called subPath
, in this way you are able to mount each file individually using the same volume:
apiVersion: apps/v1
kind: Deployment
metadata:
name: echo
spec:
selector:
matchLabels:
app: echo
template:
metadata:
labels:
app: echo
spec:
volumes:
- name: task-pv-storage
persistentVolumeClaim:
claimName: task-pv-claim
containers:
- name: echo
image: nginx
ports:
- name: http
containerPort: 80
volumeMounts:
- name: task-pv-storage
mountPath: "/usr/share/nginx/html/index.htm"
subPath: "index.htm"
- name: task-pv-storage
mountPath: "/usr/share/nginx/html/teste.html"
subPath: "teste.html"
In this example I have only one volume called task-pv-storage, is a hostPath
volume and in the folder there are only 2 files: teste.yaml
and index.html
, and when I apply this config, both files will be placed beside the original files in the container:
$ kubectl exec echo-5955898b58-gvgh9 -- ls /usr/share/nginx/html
50x.html index.htm index.html teste.html
As you can see it is possible, but will cost an addional configuration, maybe you could keep all file only in the volume instead directly in the container.
References