<p>I want to mount a volume with <code>kubectl</code> and get a shell in the environment.</p>

<p>I've tried this:</p>

<pre><code>kubectl run -i --rm --tty alpine --overrides='
{
  "apiVersion": "v1",
  "spec": {
    "template": {
      "spec": {
        "containers": [
          {
            "name": "alpine",
            "image": "alpine:latest",
            "args": [
              "sh"
            ],
            "stdin": true,
            "stdinOnce": true,
            "tty": true,
            "volumeMounts": [{
              "mountPath": "/home/store",
              "name": "store"
            }]
          }
        ],
        "volumes": [{
          "name":"store",
          "emptyDir":{}
        }]
      }
    }
  }
}
'  --image=alpine:latest --restart=Never -- sh
</code></pre>

<p>I'm not getting any errors but the volume is not present at the mount path <code>/home/store</code>:</p>

<pre><code>~ # ls -lah /home/
total 8
drwxr-xr-x    2 root     root        4.0K Sep 11 20:23 .
drwxr-xr-x    1 root     root        4.0K Sep 29 09:47 ..
</code></pre>

<p>I'm looking for the most direct way to use a volume with <code>kubectl run</code> for debugging purposes.</p>

<p><em>TL;DR I don't know what the issue was but I ended up solving this by making the build request very verbose.</em></p>

<p>I ended up solving this by setting debug to very verbose (<code>v=0</code>) and noticing that my volume mount was completely ignored by <code>kubectl</code> and not present in the request to the API:</p>

<pre><code>I0929 13:31:22.429307   14616 request.go:897] Request Body: {"kind":"Pod","apiVersion":"v1","metadata":{"name":"alpine","creationTimestamp":null,"labels":{"run":"alpine"}},"spec":{"volumes":[{"name":"store","emptyDir":{}}],"containers":[{"name":"alpine","image":"alpine:latest","args":["sh"],"resources":{},"terminationMessagePath":"/dev/termination-log","terminationMessagePolicy":"File","imagePullPolicy":"IfNotPresent","stdin":true,"stdinOnce":true,"tty":true}],"restartPolicy":"Never","terminationGracePeriodSeconds":30,"dnsPolicy":"ClusterFirst","securityContext":{},"schedulerName":"default-scheduler"},"status":{}}
</code></pre>

<p>I copy pasted that request, and edited it to add the same volume mount as above, and it worked:</p>

<pre><code>kubectl run -i --rm --tty alpine --overrides='
{
    "kind": "Pod",
    "apiVersion": "v1",
    "metadata": {
        "name": "alpine",
        "creationTimestamp": null,
        "labels": {
            "run": "alpine"
        }
    },
    "spec": {
        "containers": [{
            "name": "alpine",
            "image": "alpine:latest",
            "args": ["sh"],
            "resources": {},
            "terminationMessagePath": "/dev/termination-log",
            "terminationMessagePolicy": "File",
            "imagePullPolicy": "IfNotPresent",
            "stdin": true,
            "stdinOnce": true,
            "tty": true,
            "volumeMounts": [{
              "mountPath": "/home/store",
              "name": "store"
            }]
        }],
        "volumes": [{
          "name":"store",
          "emptyDir":{}
        }],
        "restartPolicy": "Never",
        "terminationGracePeriodSeconds": 30,
        "dnsPolicy": "ClusterFirst",
        "securityContext": {},
        "schedulerName": "default-scheduler"
    },
    "status": {}
}
'  --image=alpine:latest -v=9 --restart=Never -- sh
</code></pre>
