How to map a host directory with a kubernetes docker image directory

5/18/2020

I need to map a directory in my local machine with a directory exist in a docker container which runs inside my kubernetes cluster . Could someone please help me on this?

host dir : /opt/dev/project1
kube image location: /var/logs
-- ShanWave007
docker
docker-volume
kubernetes
volume

1 Answer

5/18/2020

You can mount your host directory into kubernetes pod using hostpath

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /var/logs
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /opt/dev/project1
      # this field is optional
      type: Directory
-- hoque
Source: StackOverflow