Pods with vloumes using kubectl run

0 votes

I'm trying to create a pod with a volume attached to it. I tried using this command:

kubectl run -i --rm --tty ubuntu --overrides='{ "apiVersion":"batch/v1", "spec": {"containers": {"image": "ubuntu:14.04", "volumeMounts": {"mountPath": "/home/store", "name":"store"}}, "volumes":{"name":"store", "emptyDir":{}}}}' --image=ubuntu:14.04 --restart=Never -- bash

But there is no volume in bash. Is there any other way to do this?

Oct 16, 2018 in Kubernetes by Damon Salvatore
• 5,490 points
339 views

1 answer to this question.

0 votes

The JSON format you're using to override is incorrect. And kubectl ignores the fields it cannot recognise.

kubectl run -i --rm --tty ubuntu --overrides='
{
  "apiVersion": "batch/v1",
  "spec": {
    "template": {
      "spec": {
        "containers": [
          {
            "name": "ubuntu",
            "image": "ubuntu:14.04",
            "args": [
              "bash"
            ],
            "stdin": true,
            "stdinOnce": true,
            "tty": true,
            "volumeMounts": [{
              "mountPath": "/home/store",
              "name": "store"
            }]
          }
        ],
        "volumes": [{
          "name":"store",
          "emptyDir":{}
        }]
      }
    }
  }
}
'  --image=ubuntu:14.04 --restart=Never -- bash

For debugging run the command you specified and then on another terminal run this command:

kubectl get job ubuntu -o json

You'll notice that the actual job structure is different from the one you used (you were missing the nested template/spec, and volumes, volumeMounts, and containers need to be arrays).

answered Oct 16, 2018 by ajs3033
• 7,240 points

Related Questions In Kubernetes

0 votes
1 answer

deleting pods using kubernetes replication controller

The pods which are managed by ReplicationController ...READ MORE

answered Jul 24, 2018 in Kubernetes by DareDev
• 6,810 points
170 views
0 votes
1 answer
0 votes
1 answer

Unable to access pods using nodeIP

Your kubernetes cluster is missing the ingress ...READ MORE

answered Sep 7, 2018 in Kubernetes by Kalgi
• 37,320 points
38 views
0 votes
1 answer

permissions related to AWS ECR

if you add allowContainerRegistry: true, kops will add those permissions ...READ MORE

answered Oct 9, 2018 in Kubernetes by Kalgi
• 37,320 points
47 views
0 votes
1 answer
0 votes
3 answers

Error while joining cluster with node

Hi Kalgi after following above steps it ...READ MORE

answered Jan 17 in Others by anonymous
1,118 views
0 votes
1 answer

Accessing remote kubernetes cluster on azure using kubectl

So, try this. Edit your kube config ...READ MORE

answered Sep 11, 2018 in Kubernetes by ajs3033
• 7,240 points
50 views
0 votes
1 answer

Using local docker images with Minikube

You can reuse the Docker daemon from ...READ MORE

answered Jan 3 in Kubernetes by ajs3033
• 7,240 points
270 views