<p>I have a command to run docker,</p>

<pre><code>docker run --name pre-core -itdp 8086:80 -v /opt/docker/datalook-pre-core:/usr/application app
</code></pre>

<p>In above command, /opt/docker/datalook-pre-core is host directory, /usr/application is container directory. The purpose is that container directory maps to host directory. So when container crashes, the directory functions as storage and data on it would be saved. </p>

<p>When I am going to use kubernetes to create a pod for this containter, how to write pod.yaml file?</p>

<p>I guess it is something like following:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  name: app-ykt
  labels:
    app: app-ykt
    purpose: ykt_production
spec:
  containers:
  - name: app-ykt
    image: app
    imagePullPolicy: IfNotPresent
    ports:
      - containerPort: 80
    volumnMounts:
      - name: volumn-app-ykt
        mountPath: /usr/application
  volumns:
      - name: volumn-app-ykt
      ？？？？
</code></pre>

<p>I do not know what's the exact properties in yaml I shall write in my case?</p>

user84592
<p>This would be a <code>hostPath</code> volume: <a href="https://kubernetes.io/docs/concepts/storage/volumes/" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/storage/volumes/</a></p>

<pre><code>  volumes:
  - name: volumn-app-ykt
    hostPath:
      # directory location on host
      path: /opt/docker/datalook-pre-core
      # this field is optional
      type: Directory
</code></pre>

<p>However remember that while a container crash won't move things, other events can cause a pod to move to a different host so you need to be prepared to both deal with cold caches and to clean up orphaned caches.</p>
