Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

kubernetes - 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?

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 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.

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

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...