업무/업무 가이드
K8s 환경에서 실행중인 pod에 접속하기 - kubectl exec
60cod
2023. 9. 11. 11:03
1. pods 확인
kubectl get pods
2. exec 명령어로 접속
kubectl exec -it [pod명] -- /bin/bash
또는
kubectl exec --stdin --tty [pod명] -- /bin/bash
↳ kubectl 명령어 인자와 사용하고자 하는 명령어의 인자를 구분하기 위해서는 이중 대시(--)를 사용할 수 있다.
근데 아래와 같은 에러 발생..
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "/bin/bash": stat /bin/bash: no such file or directory: unknown
command terminated with exit code 126
→ 도커 이미지에 /bin/bash가 설치 안 되어 있을 수 있다.
/bin/sh를 사용해보자.
kubectl exec -it [pod명] -- /bin/sh
3. 빠져나오는 방법
ctrl + p, q
exit으로 나오면 컨테이너가 멈출 수 있음!!!
참고:
https://kubernetes.io/ko/docs/tasks/debug/debug-application/get-shell-running-container/