<p>I want to customize the output of:</p>
<pre class="lang-shell prettyprint-override"><code>kubectl get pod . . .
</code></pre>
<p>with <code>--output=go-template</code> instead of <code>--output=yaml</code> or <code>--output=json</code>.</p>
<p>My purpose is to get additional values (e.g., container ports) in addition to the default columns (e.g., NAME, READY, STATUS, etc..,.) with one <code>get</code> command:</p>
<pre class="lang-shell prettyprint-override"><code>kubectl get pods --output=go-template --template=$GO_TEMPLATE

#=&gt;

NAME           READY   STATUS    RESTARTS   AGE     CONTAINER PORTS   . . .
. . .          . . .   . . .     . . .      . . .   . . .             . . .
client-qfr4s   1/1     Running   0          14d     80,443            . . .
. . .          . . .   . . .     . . .      . . .   . . .             . . .
</code></pre>
<p>What is <code>$GO_TEMPLATE</code>?</p>

<p>You can add custom columns to the output of the <code>get</code> command with the <code>--output=custom-columns</code> flag:</p>
<pre class="lang-shell prettyprint-override"><code>kubectl get pods \
--output=custom-columns='NAME:.metadata.name,STATUS:.status.phase,RESTARTS:.status.containerStatuses[].restartCount,CONATAINER_NAME:.spec.containers[*].name,PORT:.spec.containers[*].ports[*],READY:.status.containerStatuses[*].ready'

#=&gt;

NAME                         STATUS    RESTARTS   CONATAINER_NAME   PORT                                            READY
nginx-6bc98f4797-7kv6m       Pending   0          busy,nginx        map[containerPort:8000 protocol:TCP]            false,true
nginx-6bc98f4797-zv4sp       Pending   0          busy,nginx        map[containerPort:8000 protocol:TCP]            false,true
php-apache-5986bb6b9-gllq8   Running   5          php-apache        map[containerPort:80 protocol:TCP]              true
</code></pre>
<p>You can find more details <a href="https://kubernetes.io/docs/reference/kubectl/overview/#custom-columns" rel="nofollow noreferrer">here</a></p>
