PostgreSQL + Kubernetes: Role doesn't exist
Solution 1:
You have an error in your Secret
. If you base64-decode these values:
data:
# todoappdb
db_name: dG9kb2FwcGRiCg==
# todo_db_user
username: dG9kb19kYl91c2VyCg==
# password
password: cGFzc3dvcmQK
You will find that they all include a terminal \n
character:
$ kubectl get secret database-secret -o json > secret.json
$ jq '.data.username|@base64d' secret.json
"todo_db_user\n"
$ jq '.data.password|@base64d' secret.json
"password\n"
$ jq '.data.db_name|@base64d' secret.json
"todoappdb\n"
I suspect this is because you generate the values by running something like:
$ echo password | base64
But of course, the echo
command emits a trailing newline (\n
).
There are two ways of solving this:
-
Use
stringData
instead ofdata
in yourSecret
so you can just write the unencoded values:apiVersion: v1 kind: Secret type: Opaque metadata: name: database-secret stringData: db_name: todoappdb username: todo_db_user password: password
-
Instruct
echo
to not emit a trailing newline:$ echo -n todo_db_user | base64
(Or use something like
printf
which doesn't emit a newline by default).
I would opt for the first option (using stringData
) because it's much simpler.