Kubectl附加vs Kubectl执行? [英] Kubectl attach vs kubectl exec?

查看:81
本文介绍了Kubectl附加vs Kubectl执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过使用kubectl exec -ti POD_NAME bash,我可以访问容器内的终端并执行命令.

by using kubectl exec -ti POD_NAME bash I am able to access the terminal inside the container and execute the command.

我可以理解上述命令的可用性和方便性.作为K8s操作员,我经常使用 exec .

I can understand the usability and convenient of the above command. As K8s Operator I use exec regularly.

但是,kubectl attach POD_NAME的用例是什么?

However, What is the use case of kubectl attach POD_NAME?

如何利用? 它的真正目的是什么? 在什么情况或情况下可以使用?

How can it be utilised? What is the real purpose of it? In what situation or circumstance it can be used?

推荐答案

kubernetes/issue 23335 .

它可以附加到容器运行的主进程中,而容器并不总是bash.
与exec相反,它使您可以在容器内执行 any 进程(通常:bash)

It can attach to the main process run by the container, which is not always bash.
As opposed to exec, which allows you to execute any process within the container (often: bash)

# Get output from running pod 123456-7890, using the first container by default
kubectl attach 123456-7890

# Get output from ruby-container from pod 123456-7890
kubectl attach 123456-7890 -c ruby-container

本文建议:

除了交互式执行命令外,您现在还可以附加到任何正在运行的进程.与kubectl logs一样,您将获得stderr和stdout数据,但是通过附加,您还可以将stdin从终端发送到程序.
非常适合进行交互式调试,甚至只是将 ctrl - c 发送到行为异常的应用程序.

In addition to interactive execution of commands, you can now also attach to any running process. Like kubectl logs, you’ll get stderr and stdout data, but with attach, you’ll also be able to send stdin from your terminal to the program.
Awesome for interactive debugging, or even just sending ctrl-c to a misbehaving application.

  $> kubectl attach redis -i


同样,主要区别在于在容器中进行交互的过程:


Again, the main difference is in the process you interact with in the container:

  • exec:您要创建的任何人
  • 附加:当前正在运行的(无选择)

这篇关于Kubectl附加vs Kubectl执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆