Hi <@U04UQ68083H>, I've deployed Kratos in the sam...
# ory-copilot
f
Hi @chilly-king-10285, I've deployed Kratos in the same namespace as my PostgreSQL in k8s. While it can establish a connection, the issue is that when the Kratos pod starts, it doesn't automatically create the identity database. Here is kratos log and postgres logs
Copy code
Starting PostgreSQL **
2023-12-07 14:56:37.602 GMT [1] LOG: pgaudit extension initialized
2023-12-07 14:56:37.610 GMT [1] LOG: starting PostgreSQL 14.4 on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2023-12-07 14:56:37.610 GMT [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2023-12-07 14:56:37.610 GMT [1] LOG: listening on IPv6 address "::", port 5432
2023-12-07 14:56:37.619 GMT [1] LOG: listening on Unix socket "/tmp/.s.PGSQL.5432"
2023-12-07 14:56:37.625 GMT [131] LOG: database system was shut down at 2023-12-07 14:56:37 GMT
2023-12-07 14:56:37.634 GMT [1] LOG: database system is ready to accept connections
2023-12-07 14:56:46.323 GMT [145] FATAL: database "identity" does not exist
2023-12-07 14:56:46.556 GMT [146] FATAL: database "identity" does not exist
2023-12-07 14:56:55.601 GMT [154] FATAL: database "identity" does not exist
2023-12-07 14:56:56.104 GMT [155] FATAL: database "identity" does not exist
2023-12-07 14:57:17.114 GMT [184] FATAL: database "identity" does not exist
Kratos logs:
Copy code
kubectl logs kratos-86f7b57998-fxwwx -c kratos-automigrate -n auth-default  

time=2023-12-07T15:06:57Z level=info msg=No tracer configured - skipping tracing setup audience=application service_name=Ory Kratos service_version=v1.0.0
time=2023-12-07T15:06:57Z level=debug msg=Connecting to SQL Database audience=application connMaxLifetime=0s idlePool=2 pool=4 service_name=Ory Kratos service_version=v1.0.0
time=2023-12-07T15:06:58Z level=warning msg=Unable to ping database, retrying. audience=application error=map[message:failed to connect to `host=postgres user=postgres database=identity`: server error (FATAL: database "identity" does not exist (SQLSTATE 3D000)) stack_trace:
<http://github.com/ory/kratos/persistence/sql.(*Persister).Ping|github.com/ory/kratos/persistence/sql.(*Persister).Ping>
c
A message from kapa.ai
From the logs you've provided, it seems like the PostgreSQL database named "identity" that Kratos is trying to connect to does not exist. In the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/guides/deploy-kratos-example#install-postgresql), it is mentioned that you need to create a database for Kratos. In the example provided, the database is named "kratos". Here is the command used to create the database:
Copy code
bash createdb kratos
If you want to use a database named "identity", you should create it using the command
createdb identity
. After creating the database, you need to update the
dsn
configuration in your
kratos.yml
file to use the newly created database. Here is an example of how to do it:
Copy code
yaml - dsn: memory   + dsn: <postgres://kratos:[email> protected]:5432/identity?sslmode=disable&max_conns=20&max_idle_conns=4
Also, ensure that you have run the SQL migrations as mentioned in the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/guides/docker#running-migrations). This is required for new installations and when upgrading. Here is the command to run the migrations:
Copy code
bash docker -e DSN="{your database URL}" run oryd/kratos:<version> migrate sql -e
Please replace
{your database URL}
with your actual database URL and
<version>
with the version of Kratos you are using.