JSON PATH

  1. Identify the kubectl command
  2. Familiarize with JSON output
  3. Form the JSON PATH query
  4. Use the JSON PATH query with kubectl command

kubectl get pods -o=jsonpath='{.items[0].spec.containers[0].image}'

kubectl get nodes -o=jsonpath='{.items[*].metadata.name]}{.items[*].status.capacity.cpu}'

kubectl get nodes -o=jsonpath='{.items[*].metadata.name]} {"\n"} {.items[*].status.capacity.cpu}'

'{range .items[*]}
   {.metadata.name} {"\t"} {.status.capacity.cpu} {"\n"}
{end}'

kubectl get nodes -o=custom-columns=<COLUMN NAME>:<JSON PATH>

kubectl get nodes -o=custom-columns=NODE:.metadata.name,CPU:.status.capacity.cpu

kubectl get nodes --sort-by=.metadata.name

kubectl get nodes --sort-by=.status.capacity.cpu


  • open/json-path.txt
  • 마지막으로 수정됨: 2021/10/26 08:06
  • 저자 127.0.0.1