<p>I am trying to run <code>pg_dump</code> in a Docker container via <code>kubectl</code> and save the output to my local machine.</p>

<p>Here's what I have so far:</p>

<p><code>kubectl exec -it MY_POD_NAME -- pg_dump -h DB_HOST -U USER_NAME SCHEMA_NAME &gt; backup.sql</code></p>

<p>However this just hangs currently. I am fairly certain it's due to the <code>--</code> ignoring the <code>&gt;</code></p>

<p><code>kubectl exec -it MY_POD_NAME -- pg_dump -h DB_HOST -U USER_NAME SCHEMA_NAME</code> outputs to the console as expected.</p>

<p>Use <code>kubectl port-forward POD_NAME 6000:5342</code> to forward your pod port (assumed to be exposed on <code>5432</code>) onto <code>localhost:6000</code>. </p>

<p>And then run <code>pg_dump</code> directly with hostname as <code>localhost</code> and port as <code>6000</code></p>

<p><code>$ pg_dump -h DB_HOST -U USER_NAME SCHEMA_NAME &gt; backup.sql</code></p>
