by using kubectl exec -ti POD_NAME bash
I am able to access the terminal inside the container and execute the command.
I can understand the usability and convenient of the above command. As K8s Operator I use exec regularly.
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?
The use cases for kubectl attach are discussed in kubernetes/issue 23335.
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)
This article proposes:
Again, the main difference is in the process you interact with in the container: