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,980 points
4,657 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,300 points

Related Questions In Kubernetes

0 votes
1 answer
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,890 points
1,103 views
0 votes
1 answer
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
• 52,350 points
1,434 views
+1 vote
1 answer
0 votes
3 answers

Error while joining cluster with node

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

answered Jan 17, 2019 in Others by anonymous
15,577 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,300 points
676 views
0 votes
1 answer

Using local docker images with Minikube

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

answered Jan 3, 2019 in Kubernetes by ajs3033
• 7,300 points
2,909 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP