Hi , I want to achieve and store nodeport of a service to a variable . how can . . .

Alireza Nasri:
Hi ,
I want to achieve and store nodeport of a service to a variable .

how can I do that with JsonPath?

Diwakar Pandey:
what you want to achieve at the end though?

Alireza Nasri:
get a service nodeport with json path

unnivkn:
controlplane $ k get svc nginx-svc2 --no-headers| awk ‘{print $5}’ | cut -b 4-8
31512
controlplane $ k get svc nginx-svc2 --no-headers| awk ‘{print $5}’ | cut -b 4-8 >f1.txt
controlplane $

controlplane $ cat f1.txt
31512
controlplane $

controlplane $ var=$(cat f1.txt)
controlplane $ echo $var
31512
controlplane $

Diwakar Pandey:
I suggest to use jq

Diwakar Pandey:

k get svc/nginx -o json | jq ".spec.ports[].nodePort"