exec
Execute a command in a container
Execute a command in a container
Command
$ kubectl exec (POD | TYPE/NAME) [-c CONTAINER] [flags] -- COMMAND [args...]
Example I
Current State
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6db489d4b7-qkd5d 1/1 Running 0 20m
Command
kubectl exec nginx-6db489d4b7-qkd5d -- date
Notice that date
is the command that we are executing on the pod.
Output
Mon Sep 21 03:38:53 UTC 2020
Example II
Current State
$ kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx-6db489d4b7-qkd5d 1/1 Running 0 20m
Command
kubectl exec nginx-6db489d4b7-qkd5d -- ls
Notice that ls
is the command that we are executing on the pod.
Output
bin
boot
dev
docker-entrypoint.d
docker-entrypoint.sh
etc
home
lib
lib64
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
Exec Shell
To get a Shell in a Container, use the -t -i
options to get a tty and attach STDIN.
kubectl exec -t -i nginx-78f5d695bd-czm8z bash
root@nginx-78f5d695bd-czm8z:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Specifying the Container
For Pods running multiple Containers, the Container should be specified with -c <container-name>
.
当前内容版权归 kubernetes官网 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 kubernetes官网 .