我想从我的Kubernetes集群中的命令行运行一次性容器Pod.我正在寻找相当于:
docker run --rm -it centos /bin/bash
Run Code Online (Sandbox Code Playgroud)
有kubectl
同等的吗?
Dmi*_*sky 21
看起来最简单的方法是:
kubectl run tmp-shell --rm -i --tty --image centos -- /bin/bash
Run Code Online (Sandbox Code Playgroud)
备注:
Deployment
命名tmp-shell
.这种情况在您使用时发生kubectl run
.--rm
Deployment
退出shell时,确保删除此及其所有组件.如果省略--rm
,可以手动删除kubectl delete deploy/tmp-shell
.--rm
.然后,您可以kubectl attach $pod-name -c $pod-container -i -t
在退出shell后重新附加:如果您的shell无法启动,请检查您的群集是否缺少资源(kubectl describe nodes
).您可以控制此部署请求的资源--requests
:
--requests='': The resource requirement requests for this container. For example, 'cpu=100m,memory=256Mi'. Note that server side components may assign requests depending on the server configuration, such as limit ranges.
Run Code Online (Sandbox Code Playgroud)(灵感来自https://gc-taylor.com/blog/2016/10/31/fire-up-an-interactive-bash-pod-within-a-kubernetes-cluster)
Uro*_* T. 11
为了Pod
创建而不是 aDeployment
并在退出时自行删除它,请尝试以下操作:
kubectl run curl-debug --rm -i --tty --restart=Never --image=radial/busyboxplus:curl -- /bin/sh
Run Code Online (Sandbox Code Playgroud)
该--restart=Never
标志是它说什么来创建Pod
一个替代Deployment
对象
此外 - 此图像轻量级,下载速度快,适合网络调试。
希望有帮助
归档时间: |
|
查看次数: |
4042 次 |
最近记录: |