我们可以在K8S的POD中执行到容器中吗? [英] Can we exec into container in a POD in K8S?

查看:88
本文介绍了我们可以在K8S的POD中执行到容器中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将docker映像放入POD。
我们可以使用 docker exec ...执行到Docker容器中。
同样,有一种方法可以在POD中执行到容器中以检查某些数据吗?

I am putting docker image into POD. We can exec into a Docker container using "docker exec..." Similarly is there a way to exec into container in a POD to check some data ?

推荐答案

有几种方法可以在Pod中进入Kubernetes容器。

There are several ways of how to get inside the Kubernetes container in a Pod.

  • kubectl exec (reference link) creates additional process in the Pod's namespace and connects your console to it's stdin/stdout.

示例:

kubectl exec 123456-7890 date
kubectl exec 123456-7890 -c ruby-container date
kubectl exec 123456-7890 -c ruby-container -i -t -- bash -il
kubectl exec 123456-7890 -i -t -- ls -t /usr




  • 附加kubectl 参考链接)将您的控制台连接到st din / stdout现有容器过程。

    • kubectl attach (reference link) connects your console to stdin/stdout existing container process.
    • 示例:

      kubectl attach 123456-7890
      kubectl attach 123456-7890 -c ruby-container
      kubectl attach 123456-7890 -c ruby-container -i -t
      kubectl attach rs/nginx
      

      您还可以使用 kubectl日志命令。

      示例:

      kubectl logs nginx
      kubectl logs nginx --all-containers=true
      kubectl logs -lapp=nginx --all-containers=true
      kubectl logs -p -c ruby web-1
      kubectl logs -f -c ruby web-1
      

      这些关于StackOverflow的答案为您提供了与您的问题相关的更多信息:

      These answers on StackOverflow give you more information related to your question:

      • kubectl exec into contain of multi container pod
      • Execute bash command in pod with kubectl?
      • Kubectl attach vs kubectl exec?
      • How do you debug python code with kubernetes and skaffold?

      这篇关于我们可以在K8S的POD中执行到容器中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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