I want to print the internal IP of all nodes in the same line separated by a space using jq
in k8s. How can I do this?
Using jsonpath I can filter using .addresses[?(@.type=="InternalIP")]
. How to achieve the same with jq
?
You can achieve this using the following command
kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type=="InternalIP")].address}'
Checkout kubectl Cheat sheet for more examples
You could use select and pipe to achieve desired output.
below command shows the internal ip separated by new-line
kubectl get nodes -o json | jq '.items[].status.addresses[] | select(.type=="InternalIP") | .address'
for space separated internal-ips:
kubectl get nodes -o json | jq '.items[].status.addresses[] | select(.type=="InternalIP") | .address' | tr -d '\"' | tr '\n' ' '