是否可以像执行docker容器或运行在Pod内的容器一样执行K8s pod? [英] Is it possible to exec in to a K8s pod the same way we exec in to a docker containers or containers running inside of a pod?

查看:382
本文介绍了是否可以像执行docker容器或运行在Pod内的容器一样执行K8s pod?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以像我们exec一样将exec放入K8s吊舱中,使其进入docker容器或在吊舱内部运行的容器中?p

Is it possible to exec in to a K8s pod the same way we exec into docker containers or containers running inside of a pod?p

编辑-
这个问题不是关于exec放入容器中的容器的问题.这是关于吊舱本身的.可能是不可能的,但这就是问题所在.因此,请停止使用-将其重复执行来标记为重复项在K8S的POD中?

Edit -
This question not about execing into a container in a pod. This is about the pod itself. Might be it's not possible but that is what the question is about. So stop marking it duplicate with - Can we exec into container in a POD in K8S?

推荐答案

Pod是一组容器,是一个逻辑概念.因此,您无法真正执行到Pod中.您所要做的就是将exec执行到容器中的一个容器中.

Pod is a group of containers and is a logical concept. So you can not really exec into a pod. All you can do is exec into one of the containers in the pod.

kubectl exec命令可能会让您认为您正在执行到容器中,但实际上是执行到容器中.此命令仅在单个容器容器中有效.如果容器中有多个容器,即多个容器pod,然后您需要使用-c选项显式选择一个容器.

kubectl exec command might make you think that you are execingy into a pod but you actually exec into the container.This command works only if its a single container pod.If there are multiple container in the pod i.e it's a multi container pod then you need to choose a container explicitly using -c option.

这是kubectl exec -h的输出,其中也提到了容器.

Here is the output of kubectl exec -h which mentions about containers too.

Execute a command in a container.

Examples:
  # Get output from running 'date' command from pod mypod, using the first container by default
  kubectl exec mypod -- date
  
  # Get output from running 'date' command in ruby-container from pod mypod
  kubectl exec mypod -c ruby-container -- date
  
  # Switch to raw terminal mode, sends stdin to 'bash' in ruby-container from pod mypod
  # and sends stdout/stderr from 'bash' back to the client
  kubectl exec mypod -c ruby-container -i -t -- bash -il

在创建Pod的任何其他实际容器之前先创建一个pause容器.pause容器的责任是创建将在Pod的其他容器之间共享的linux名称空间.

A pause container gets created before any other actual container of the pod gets created.Responsibility of the pause container is to create the linux namespaces which will be shared among the other containers of the pod.

无法使用kubectl exec执行到该暂停容器中,但是您可以使用docker exec执行到该暂停容器中.

There is no way to exec into that pause container using kubectl exec but you can exec into it using docker exec.

这篇关于是否可以像执行docker容器或运行在Pod内的容器一样执行K8s pod?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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