使用kubectl run创建具有卷的kubernetes吊舱
问题描述:
我知道您可以使用kubectl run创建一个具有Deployment/Job的吊舱。但是是否有可能创建一个带有卷的卷?我试着运行这个命令:使用kubectl run创建具有卷的kubernetes吊舱
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
但是这个卷并没有出现在交互式bash中。
有没有更好的方法来创建一个容量可以附加到容器的容器?
答
您的JSON覆盖指定有误。不幸的是,kubectl运行只是忽略了它不理解的领域。
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
要调试这个问题,我跑了您指定的命令,然后在另一端然:
kubectl get job ubuntu -o json
从那里,你可以看到实际的工作结构从您的JSON覆盖不同(你是缺少嵌套的模板/规格,而volume,volumeMounts和容器需要是数组)。
+0
谢谢,尤其是调试它的提示。看起来像做一个创造,然后附加可能是一个更好的方式去...只要我能得到它的工作。 (出于某种原因,我甚至无法让skydns验证步骤起作用,attach/exec步骤就会挂起。)关于调试这些情况,您有任何提示吗? –
我也尝试过使用kubectl创建,然后做一个exec/attach但它没有为我工作。但这可能是因为我遇到了这个bug: https://github.com/kubernetes/kubernetes/issues/16670 –