I want to find nodeport of specific namespace with jsonpath :smile: I actually f . . .

Alireza Nasri:
I want to find nodeport of specific namespace with jsonpath :smile: I actually forgot the syntax.
Would you please someone help me?

unnivkn:
controlplane $ k get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 23m
nginx NodePort 10.104.232.216 <none> 80:31728/TCP 18m
nginx-svc2 NodePort 10.110.225.194 <none> 81:31512/TCP 5s
controlplane $

controlplane $ k -n default get svc nginx -o jsonpath=’{.spec.ports[].nodePort}’
31728
controlplane $
or
controlplane $ k -n default get svc -o jsonpath=’{.items[*].spec.ports[].nodePort}’
31728 31512
controlplane $

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 $