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:
psql -U postgres -d postgres <<EOF
CREATE ROLE aaa WITH LOGIN PASSWORD 'bbb';
CREATE DATABASE ccc OWNER aaa;
EOF
But how can I do this with kubectl?
You can use kubectl exec to run this command within the postgres container:
The flag -i
opens a terminal in the container so you can see the command output.
kubectl exec -i postgres-pod -- psql -d postgres -U postgres <<EOF
CREATE ROLE aaa WITH LOGIN PASSWORD 'bbb';
CREATE DATABASE ccc OWNER aaa;
EOF