Hello Everyone, The keto migration fails complaini...
# ory-selfhosting
s
Hello Everyone, The keto migration fails complaining that the keto database does not exist. We want to create database automatically so that there is no manual step when deploying it to any k8s cluster. what is the recommended way to automatically create the database for keto before migration happens? I was planning to supply an init container to keto whose job is to create just the database.
m
Hey @salmon-helicopter-2455 The recommended way to automatically create a database for Ory Keto before migration happens is indeed to use an init container in your Kubernetes deployment. This init container should run a script that creates the necessary database. For example, if you're using PostgreSQL as your database, you could use the official PostgreSQL Docker image to run a script that creates the Keto database. Here's a rough example of what that might look like in your Kubernetes deployment YAML:
Copy code
initContainers:
- name: init-db
  image: postgres:9.6
  command: ['sh', '-c', 'psql -h $DB_HOST -U $DB_USER -c "CREATE DATABASE keto;"']
  env:
  - name: DB_HOST
    valueFrom:
      secretKeyRef:
        name: db-secrets
        key: host
  - name: DB_USER
    valueFrom:
      secretKeyRef:
        name: db-secrets
        key: user
  - name: DB_PASSWORD
    valueFrom:
      secretKeyRef:
        name: db-secrets
        key: password
In this example,
db-secrets
is a Kubernetes Secret that contains your database credentials. The init container uses these credentials to connect to your database and create the Keto database. Please note that this is a simplified example and you might need to adjust it according to your specific setup and requirements. For instance, you might need to handle the case where the database already exists.
s
Thank you Vincent 🙂
👍 1