<p>I have just installed the chart of postgresql and now I need a kubectl script to create the role and the database. In psql I use this script:</p>
<pre><code>psql -U postgres -d postgres &lt;&lt;EOF
CREATE ROLE aaa WITH LOGIN PASSWORD 'bbb';
CREATE DATABASE ccc OWNER aaa;
EOF
</code></pre>
<p>But how can I do this with kubectl?</p>

xRobot
<p>You can use kubectl exec to run this command within the postgres container:</p>
<p>The flag <code>-i</code> opens a terminal in the container so you can see the command output.</p>
<pre><code>kubectl exec -i postgres-pod -- psql -d postgres -U postgres  &lt;&lt;EOF
CREATE ROLE aaa WITH LOGIN PASSWORD 'bbb';
CREATE DATABASE ccc OWNER aaa;
EOF
</code></pre>
