Kubernetes 101 : An overview of JSON PATH - Advanced "kubectl" commands -
JSON PATH also allow us to get an customized output that fits our needs.
To get the right JASON PATH parameter for our "kubectl" command, we display the information received from the API-server in a JSON format like below:
Then we follow the path down our JSON file to the field we are looking for.
For example for to display the labels of all the elements in the items[] array, we follow the path to the labels as below:
The some goes for the nodes. We start by displaying our output in JSON format using the below command:
Then we navigate down our JSON file the same way we did with the pod's JSON file.
For example to get the names of the nodes, we use the below command:
We use the below command to loop through the entire items[] array:
Organizing our output:
For a better readability we could display our output in columns as we can see below:
Remark - JSON PATH syntax - :
- $ : root of the file
- {} : dictionary
- [] : array
- [*] : all the elements of the array
- [0] : first element of the array.
- [0,1,2] : first,second and third element of the array.
Comments