更新时间:2023-01-15 22:32:06
最简单的方法是:
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
Deployment
named tmp-shell
. This happens any time you use kubectl run
.--rm
ensures this Deployment
and all of its components are deleted when you exit the shell. If you omitted --rm
, you can delete it manually with kubectl delete deploy/tmp-shell
. --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 )