What I want is that mount a hostpath
pv
to my pod
directory for example /usr/share/nginx/html/
and my files at this directory be remain.
I have a nginx
image that i have index.html
file in it's /usr/share/nginx/html/
directory.
And when i want to orchestrate it with Kubernetes
and make a pod and use a PV
for make it persistent, it mount the hostpath
to container /usr/share/nginx/html/
directory and after that my index.html will be gone .
these are my manifests
Dockerfile
:
FROM nginx
WORKDIR /usr/share/nginx/html
COPY . /usr/share/nginx/html
EXPOSE 80
VOLUME /usr/share/nginx/html
And in my .
directory I have index.html
pod.yaml
:
kind: Pod
apiVersion: v1
metadata:
labels:
app: nginx
name: task-pv-pod23
spec:
volumes:
- name: task-pv-storage2
persistentVolumeClaim:
claimName: task-pv-claim2
containers:
- name: task-pv-container
image: meysambbb/nginx:2
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- name: task-pv-storage2
mountPath: /usr/share/nginx/html/
pv.yaml
:
kind: PersistentVolume
apiVersion: v1
metadata:
name: task-pv-volume2
labels:
type: local
spec:
capacity:
storage: 10Gi
accessModes:
- ReadOnlyMany
hostPath:
path: "/mnt/2/data/"
pvc.yaml
:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: task-pv-claim2
spec:
accessModes:
- ReadOnlyMany
resources:
requests:
storage: 3Gi
When I run my pod without VolumeMount
and when i run curl <POD_IP>
it show my index.html contents but when I use pv
and VolumeMount
it show 403 error
Is it possible to mount hostpath
and have container files in same directory?