[英]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?
是否可以像執行到exec
容器或在 pod 內運行的容器一樣exec
到 K8s pod?
編輯 -
這個問題不是關於exec
進入 pod 中的容器。 這是關於 pod 本身的。 可能是不可能的,但這就是問題所在。 所以停止將其標記為重復 - 我們可以在 K8S 的 POD 中執行到容器中嗎?
Pod 是一組容器,是一個邏輯概念。 所以你不能真正執行到一個 pod 中。 您所能做的就是執行到 pod 中的一個容器中。
kubectl exec
命令可能會讓您認為您正在執行 pod,但實際上您執行到容器中。此命令僅在其單個容器 pod 時有效。如果 pod 中有多個容器,即它是多容器 pod,那么您需要使用-c
選項顯式選擇容器。
這是kubectl exec -h
的 output 也提到了容器。
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
容器的職責是創建 linux 命名空間,這些命名空間將在 Pod 的其他容器之間共享。
無法使用kubectl exec
執行到該暫停容器中,但您可以使用docker exec
執行到它。
是的,使用 kubectl exec 命令我們可以 shell 進入正在運行的容器/pod
controlplane $ kubectl run --image=nginx web --restart=Never
pod/web created
controlplane $ kubectl get po
NAME READY STATUS RESTARTS AGE
web 0/1 ContainerCreating 0 4s
controlplane $ kubectl exec -it web -- /bin/bash
root@web:/# ls
bin dev docker-entrypoint.sh home lib64 mnt proc run srv tmp var
boot docker-entrypoint.d etc lib media opt root sbin sys usr
pod 是包裝容器的抽象實體。 當您通過 kubectl exec -it 執行到 pod 時,您實際上是在為您的容器執行包裝器命令。 此外,您無需在 Pod 中執行任何操作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.