Kubectl attach vs kubectl exec?

前端 未结 1 407
深忆病人
深忆病人 2021-02-05 00:14

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 co

相关标签:
1条回答
  • 2021-02-05 01:12

    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)

    # 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
    

    This article proposes:

    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: any one you want to create
    • attach: the one currently running (no choice)
    0 讨论(0)
提交回复
热议问题