我想用kubectl
挂载一个卷,并在环境中得到一个shell。
我试过这个:
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
我没有收到任何错误,但该卷在装载路径上不存在/home/store
:
~ # 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 ..
我正在寻找使用带有kubectl run
的卷进行调试的最直接方法。
TL;DR 我不知道问题是什么,但我最终通过使构建请求非常冗长来解决这个问题。
我最终通过将调试设置为非常详细(v=0
(并注意到我的卷挂载被kubectl
完全忽略并且没有出现在对 API 的请求中来解决此问题:
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":{}}
我复制粘贴了该请求,并对其进行了编辑以添加与上述相同的卷挂载,它起作用了:
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