Hello everyone, I've deployed Kratos in the same n...
# talk-kratos
f
Hello everyone, 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>
a
You need to create the database manually when using a DB connection. If you are just testing, you can use the DSN memory
b
Kratos can create all the necessary tables, if you use the
migrate
command. See here for a configuration using docker compose: https://github.com/ory/kratos/blob/master/quickstart.yml#L3-L18
f
@bland-eye-99092 Here is my values.yaml .Do i need to change autoMigrate to true ?
Copy code
kratos:
  fullnameOverride: 'kratos'
  image:
    repository: 'oryd/kratos'
    tag: 'v1.0.0' # Don't forget to update init container below
  deployment:
    annotations:
      rollme: '{{ randAlphaNum 5 | quote }}'
    extraVolumes:
      - name: oic-config
        configMap:
          name: kratos-oic-config
    extraVolumeMounts:
      - name: oic-config
        mountPath: /etc/config/kratos/oic-configuration
        readOnly: true
    livenessProbe:
      initialDelaySeconds: 5
      periodSeconds: 10
      failureThreshold: 5
    readinessProbe:
      initialDelaySeconds: 5
      periodSeconds: 10
      failureThreshold: 5
    startupProbe:
      failureThreshold: 60
      successThreshold: 1
      periodSeconds: 1
      timeoutSeconds: 1

  kratos:
    autoMigrate: false
    development: false
    emailTemplates:
      recovery:
        valid:
          subject: Recover access to your account
          body: |-
            Hi, please recover access to your account by clicking the following link:
            <a href="{{ .RecoveryURL }}">{{ .RecoveryURL }}</a>
          plainBody: |-
            Hi, please recover access to your account by clicking the following link: {{ .RecoveryURL }}
        invalid:
          subject: Account access attempted
          body: |-
            Hi, you (or someone else) entered this email address when trying to recover access to an account.
            However, this email address is not on our database of registered users and therefore the attempt has failed. If this was you, check if you signed up using a different address. If this was not you, please ignore this email.
          plainBody: |-
            Hi, you (or someone else) entered this email address when trying to recover access to an account.
      verification:
        valid:
          subject: Please verify your email address
          body: |-
            Hi, please verify your account by clicking the following link:
            <a href="{{ .VerificationURL }}">{{ .VerificationURL }}</a>
          plainBody: |-
            Hi, please verify your account by clicking the following link: {{ .VerificationURL }}
        invalid:
          subject: Please verify your email address
          body: |-
            Hi, you (or someone else) entered this email address when trying to recover access to an account.
            However, this email address is not on our database of registered users and therefore the attempt has failed. If this was you, check if you signed up using a different address. If this was not you, please ignore this email.
          plainBody: |-
            Hi, you (or someone else) entered this email address when trying to recover access to an account.
    config:
@bland-eye-99092 I have to run each time
kratos migrate sql
How do i run this automatically
b
I have to run each time
kratos migrate sql
How do i run this automatically
You could use a job for that
f
@bland-eye-99092 I have this script on my which create an extra init container to do that but it does not work :
extraInitContainers:  |
- name:  automigrate-init
image: oryd/kratos:v0.10.1
command: ["kratos"]
args: ["migrate", "sql", "-e", "--yes"]
env:
- name: DSN
valueFrom:
secretKeyRef:
key: dsn
name: kratos
b
Sorry, I can’t help with Kubernetes specific issues, but one thing: your still using kratos v0.10. That is a year old. We’ve fixed a bunch of issues since then.
a
@flat-rose-25983 Have you thought about using the Helm chart? It includes the migration automatically
f
@astonishing-morning-18498 Can you share the helm chart please ?
a