Day 40/40
JSONPath Tutorial - Advanced Kubectl Commands
Video Link
@piyushsachdeva
Git Repository
My Git Repo
In this section we will deep dive into JSONPath from the beginners perspective and see how you can write advanced kubectl commands using JSONPATH
- Return result in
json
format byapi-server
kubectl get nodes -o json
- Return result in
yaml
format byapi-server
kubectl get nodes -o yaml
- Sample of jsonpath:
root@sinaops:~# kubectl get nodes -o=jsonpath='{.items[*].status.nodeInfo.osImage}{"\n"}'
Ubuntu 24.04.1 LTS Ubuntu 22.04.2 LTS Ubuntu 22.04.4 LTS
- With custom column:
root@sinaops:~# kubectl get nodes -o='custom-columns=OsType:{.status.nodeInfo.osImage},KubeletVersion:{.status.nodeInfo.kubeletVersion}'
OsType KubeletVersion
Ubuntu 24.04.1 LTS v1.30.4
Ubuntu 22.04.2 LTS v1.30.0
Ubuntu 22.04.4 LTS v1.30.4
- With custom column and statement:
root@sinaops:~# kubectl get nodes -o=custom-columns='Host:{.status.addresses[?(@.type=="Hostname")].address},OsType:{.status.nodeInfo.osImage}'
Host OsType
cloudy.net Ubuntu 24.04.1 LTS
jolly-net Ubuntu 22.04.2 LTS
sinaops Ubuntu 22.04.4 LTS
- Sort by an item:
root@sinaops:~# kubectl get nodes
NAME STATUS ROLES AGE VERSION
cloudy.net Ready worker 6d v1.30.4
jolly-net Ready,SchedulingDisabled worker 7d22h v1.30.0
sinaops Ready control-plane 8d v1.30.4
root@sinaops:~# kubectl get nodes --sort-by=.status.nodeInfo.kubeletVersion
NAME STATUS ROLES AGE VERSION
jolly-net Ready,SchedulingDisabled worker 7d22h v1.30.0
cloudy.net Ready worker 6d v1.30.4
sinaops Ready control-plane 8d v1.30.4
Top comments (4)
Congrats on completing your challenge!
awesome! congrats on completing challenge.
Great job buddy on completing the challenge! Well done. We have two more videos :) Feel free to check those as well.
Thank you Sir :)