· TIL  · 2 min read

[TIL] kubectl debug로 Distroless 컨테이너 디버깅하기

이미지에 쉘이 없는 Distroless 컨테이너를 kubectl debug ephemeral container로 디버깅하는 방법.

이미지에 쉘이 없는 Distroless 컨테이너를 kubectl debug ephemeral container로 디버깅하는 방법.

문제

Distroless 이미지로 빌드된 Pod에는 /bin/sh가 없어서 kubectl exec가 불가능합니다.

$ kubectl exec -it my-pod -- /bin/sh
OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/sh": stat /bin/sh: no such file or directory

해결: kubectl debug

Kubernetes 1.25+ 에서 Ephemeral Container를 활용합니다:

# 디버그 컨테이너를 Pod에 주입
kubectl debug -it my-pod --image=busybox:latest --target=my-container

# nicolaka/netshoot으로 네트워크 디버깅
kubectl debug -it my-pod --image=nicolaka/netshoot --target=my-container

# 노드 레벨 디버깅
kubectl debug node/my-node -it --image=ubuntu

핵심 포인트

  • --target: 프로세스 네임스페이스를 공유할 컨테이너 지정
  • Ephemeral Container는 Pod 재시작 없이 추가됨
  • nicolaka/netshoot: curl, dig, tcpdump 등 네트워크 도구 포함
  • 디버그 완료 후 Pod 삭제하면 Ephemeral Container도 함께 삭제됨

언제 쓰나?

  • Distroless, scratch 기반 프로덕션 이미지 디버깅
  • CrashLoopBackOff 상태 Pod 조사
  • 노드 레벨 문제 (디스크, 네트워크) 진단
Back to Blog

Related Posts

View All Posts »