Search code examples
dockerkubernetesvolumedocker-volume

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


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

Solution

  • 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