<p>I am trying to fetch Nodeport from a specific pod using kubectl describe command. I came to know from this <a href="https://stackoverflow.com/questions/37464518/how-to-format-the-output-of-kubectl-describe-to-json">question</a> that -o option doesn't work with describe, hence I am trying with following way but I am not getting required value, can someone correct me.</p>

<pre><code>kubectl -n core describe svc/pg-debug
Name:                     pg-debug
Namespace:                core
Labels:                   &lt;none&gt;
Annotations:              &lt;none&gt;
Selector:                 app=postgresql-default
Type:                     NodePort
IP:                       172.17.17.19
Port:                     &lt;unset&gt;  5432/TCP
TargetPort:               5432/TCP
NodePort:                 &lt;unset&gt;  24918/TCP
Endpoints:                172.16.90.10:5432
Session Affinity:         None
External Traffic Policy:  Cluster
Events:                   &lt;none&gt;
</code></pre>

<p>Following is the command that i am trying to get the value <code>"24918"</code></p>

<pre><code>kubectl -n core describe svc/pg-debug | grep NodePort |awk -F:  '/nodePort/{gsub(/ /,"",$2)}'
</code></pre>

<p>You can use following command to get nodePort from service</p>

<pre><code>kubectl get svc pg-debug -n core -o jsonpath='{.spec.ports[].nodePort}'
</code></pre>

<p>Refs:</p>

<ul>
<li><a href="https://kubernetes.io/docs/reference/kubectl/jsonpath/" rel="noreferrer">https://kubernetes.io/docs/reference/kubectl/jsonpath/</a> </li>
<li><a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="noreferrer">https://kubernetes.io/docs/reference/kubectl/cheatsheet/</a></li>
<li>and see also: <a href="https://github.com/kubernetes/kubectl/issues/25" rel="noreferrer">https://github.com/kubernetes/kubectl/issues/25</a></li>
</ul>
