Create kubernet module with volume using kubectl run

I understand that you can create a module with Deployment / Job using kubectl run. But is it possible to create one with a volume attached to it? I tried to execute 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 the volume is not displayed in interactive bash.

Is there a better way to create a block with a volume that you can connect to?

+8
kubernetes kubectl
source share
1 answer

Your JSON redefinition is incorrect. Unfortunately, kubectl works, it simply ignores fields that it does not understand.

 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 

To debug this problem, I ran the command you specified, and then in another terminal:

 kubectl get job ubuntu -o json 

From there, you can see that the actual structure of the work is different from your json override (you lack a nested template / specification, and volumes, volumes and containers must be arrays).

+12
source share

All Articles