Kubernetes 환경에서 많은 리소스를 효율적으로 조회하려면 특정 정보를 필터링하고 포맷팅해야 함
JSONPath 사용 이유
JSONPath 쿼리
# 모든 노드 이름 출력
kubectl get nodes -o jsonpath='{.items[*].metadata.name}'
# 노드 아키텍처 가져오기
kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.architecture}'
# CPU 개수 가져오기
kubectl get nodes -o jsonpath='{.items[*].status.capacity.cpu}'
JSONPath 포맷팅 및 반복
# 줄바꿈
kubectl get nodes -o jsonpath='{.items[*].metadata.name}\\n{.items[*].status.capacity.cpu}'
# 반복 사용 \\t 탭
kubectl get nodes -o jsonpath='{range .items[*]}{.metadata.name}\\t{.status.capacity.cpu}\\n{end}'
열 이름과 JSONPath를 지정
kubectl get nodes --custom-columns="Node Name:.metadata.name,CPU Count:.status.capacity.cpu"
—sort-by 옵션 사용
노드 이름 기준 정렬
kubectl get nodes --sort-by='.metadata.name'