Kubernetes
kubernetes 의 pod 내 container 목록 조회
정윤재
2023. 5. 29. 02:16
kubectl get pod 로 조회시
root@k8smaster:~# kubectl get pod
NAME READY STATUS RESTARTS AGE
alertmanager-prometheus-kube-prometheus-alertmanager-0 2/2 Running 0 9m41s
와 같이 2개 이상의 container 를 가진 pod 가 있는데 이런 pod 의 container 를 조회 하기 위해선
컨테이너 명을 알아야 한다.
shell> kubectl get pod [pod 명] -o jsonpath={..spec.containers[*].name} | xargs -n1
과 같이 조회 해 주면 된다.
이렇게 조회 후 container log 를 조회 하려면
kubectl logs pod/prometheus-prometheus-kube-prometheus-prometheus-0 -c prometheus
와 같이 pod 명과 container 명을 다 알고 있어야 로그 조회가 가능하다.