如何在Kubernetes中从命令行运行容器(如docker run)? [英] How do I run a container from the command line in Kubernetes (like docker run)?
本文介绍了如何在Kubernetes中从命令行运行容器(如docker run)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从Kubernetes集群的命令行中运行一个一次性容器Pod.我正在寻找的等效项:
I would like to run a one-off container Pod from the command line in my Kubernetes cluster. I am looking for the equivalent of:
docker run --rm -it centos /bin/bash
是否有等效的kubectl
?
推荐答案
最简单的方法是:
kubectl run tmp-shell --rm -i --tty --image centos -- /bin/bash
注释:
- 这将显示一个名为
tmp-shell
的整体Deployment
.只要您使用kubectl run
,就会发生这种情况. -
--rm
确保退出外壳程序时删除此Deployment
及其所有组件.如果省略了--rm
,则可以使用kubectl delete deploy/tmp-shell
手动将其删除. - 如果要脱离外壳并使其具有重新连接的能力,请省略
--rm
.退出外壳后,您将可以重新连接:kubectl attach $pod-name -c $pod-container -i -t
. -
如果您的外壳未启动,请检查您的集群是否资源不足(
kubectl describe nodes
).您可以通过--requests
- This will bring up a whole
Deployment
namedtmp-shell
. This happens any time you usekubectl run
. --rm
ensures thisDeployment
and all of its components are deleted when you exit the shell. If you omitted--rm
, you can delete it manually withkubectl delete deploy/tmp-shell
.- If you want to detach from the shell and leave it running with the ability to re-attach, omit the
--rm
. You will then be able to reattach with:kubectl attach $pod-name -c $pod-container -i -t
after you exit the shell. If your shell does not start, check whether your cluster is out of resources (
kubectl describe nodes
). You can control the resources this deployment is requesting with--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.
(灵感来自 https://gc-taylor.com/blog/2016/10/31/fire-up-an-interactive-bash-pod-within-a-kubernetes-cluster )
这篇关于如何在Kubernetes中从命令行运行容器(如docker run)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文