Question
Use JSON Path query to retrieve the osImages of all nodes and store it in a file allNodes_osImage_45CVB34Ji.txt at /root location.
Note: the osImages are under the nodeInfo section, under status of each node
Answer
First, get the output of all nodes in JSON format:
kubectl get nodes -o json
After reviewwing the JSON, create a JSON path request:
kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}'
Now, redirect output to the file:
kubectl get nodes -o jsonpath='{.items[*].status.nodeInfo.osImage}' > /root/allNodes_osImage_45CVB34Ji.txt
Verify:
cat /root/allNodes_osImage_45CVB34Ji.txt