[LAB]

week-07/labs/lab-04-node-lifecycle-and-upgrade/starter/output-formatting-drills.md

week-07/labs/lab-04-node-lifecycle-and-upgrade/starter/output-formatting-drills.md

Course Contents 8 weeks ยท 45 labs

Output Formatting Speed Drills

Target pace: 2-3 minutes per drill (25 minutes total).
Run these after Lab 4 Part 1, when your kind-ops cluster and ops-lab workload are running.
For each drill: write your command first, run it, and note one quick verification before opening the answer.

After these drills, complete the graded checkpoint in starter/jsonpath-check.txt and validate with:

bash starter/validate-jsonpath-check.sh ./jsonpath-check.txt
  1. List all nodes sorted by creation timestamp.
Answer command
kubectl get nodes --sort-by=.metadata.creationTimestamp
  1. Show only node names and kubelet versions.
Answer command
kubectl get nodes -o custom-columns=NAME:.metadata.name,VERSION:.status.nodeInfo.kubeletVersion
  1. Get all pod names in ops-lab as a space-separated list.
Answer command
kubectl get pods -n ops-lab -o jsonpath='{.items[*].metadata.name}'
  1. Show each pod and the node it runs on in ops-lab.
Answer command
kubectl get pods -n ops-lab -o custom-columns=POD:.metadata.name,NODE:.spec.nodeName
  1. List pods with restart counts (ascending output; descending is a follow-up challenge).
Answer command
kubectl get pods -A -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.status.containerStatuses[0].restartCount}{"\n"}{end}'
  1. Get the internal IP of all nodes.
Answer command
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'
  1. Find which node has the most allocatable CPU (start with a custom-columns view).
Answer command
kubectl get nodes -o custom-columns=NAME:.metadata.name,CPU:.status.allocatable.cpu
  1. Get the image used by each container in ops-lab.
Answer command
kubectl get pods -n ops-lab -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.containers[*].image}{"\n"}{end}'
  1. List PVs sorted by capacity.
Answer command
kubectl get pv --sort-by=.spec.capacity.storage
  1. Get service names and ClusterIPs in ops-lab.
Answer command
kubectl get svc -n ops-lab -o jsonpath='{range .items[*]}{.metadata.name}{"\t"}{.spec.clusterIP}{"\n"}{end}'