Skip to content

Kubectl:exec

컨테이너 안에서 실행하기

Simple usage

컨테이너가 1개일 경우:

kubectl exec -it <pod-name> -- /bin/bash

멀티 컨테이너 Pod인 경우 -c 옵션으로 컨테이너 지정:

kubectl exec -it <pod-name> -c <container-name> -- /bin/bash

네임스페이스 지정이 필요하면 <cocde>-n</code> 추가:

kubectl exec -it <pod-name> -n <namespace> -- /bin/bash

컨테이너 목록 확인하기

kubectl get pod <pod-name> -o jsonpath='{.spec.containers[*].name}'

개행이 필요하다면:

kubectl get pod <pod-name> -o jsonpath='{range .spec.containers[*]}{.name}{"\n"}{end}'

See also