gpt4 book ai didi

kubernetes - "Failed to connect to database": Keycloak Operator external database Config not working

转载 作者:行者123 更新时间:2023-12-04 07:16:02 25 4
gpt4 key购买 nike

我查了这个 How to use用于使用外部数据库连接的 Keycloak 运算符(operator)自定义资源。我使用 Google 平台的 CloudSQL 作为外部数据库源。
我的配置是

  • keycloak-idm
  • apiVersion: keycloak.org/v1alpha1
    kind: Keycloak
    metadata:
    name: kiwigrid-keycloak-idm
    spec:
    instances: 3
    externalAccess:
    enabled: false
    externalDatabase:
    enabled: true
  • 外部数据库存储 secret
  • apiVersion: v1
    kind: Secret
    metadata:
    name: keycloak-db-secret
    namespace: kiwios-application
    type: Opaque
    stringData:
    POSTGRES_DATABASE: keycloak-storage
    POSTGRES_EXTERNAL_ADDRESS: pgsqlproxy.infra
    POSTGRES_EXTERNAL_PORT: "5432"
    POSTGRES_HOST: keycloak-postgresql
    POSTGRES_USERNAME: keycloak-user
    POSTGRES_PASSWORD: S1ly3AValJYBNR-fsptLYdT74
    POSTGRES_SUPERUSER: "true"

  • 存储数据库
  • apiVersion: sql.cnrm.cloud.google.com/v1beta1
    kind: SQLDatabase
    metadata:
    name: keycloak-storage
    namespace: kiwios-application
    annotations:
    cnrm.cloud.google.com/deletion-policy: "abandon"
    spec:
    charset: UTF8
    collation: en_US.UTF8
    instanceRef:
    name: keycloak-storage-instance-pg
    namespace: infra
  • 存储用户
  • apiVersion: sql.cnrm.cloud.google.com/v1beta1
    kind: SQLUser
    metadata:
    name: keycloak-user
    namespace: kiwios-application
    annotations:
    cnrm.cloud.google.com/deletion-policy: "abandon"
    spec:
    instanceRef:
    name: keycloak-storage-instance-pg
    namespace: infra
    password:
    valueFrom:
    secretKeyRef:
    name: keycloak-db-secret
    key: POSTGRES_PASSWORD
    以及 Kubernetes 控制台中显示的错误
    error
    它不工作。任何人都请帮我弄清楚我做错了什么。
    更新:我深入研究了 k9s 控制台。根据 keycloak-operator功能,它为数据库连接创建一个外部名称。
    这是这里 keycloak-postgresql检查下面的图像
    keycloak-postgresql works keycloak-operator中没有错误显示安慰。只有 keycloak-idm无法使用此外部名称建立连接。它显示以下错误。
    error

    最佳答案

    这就是我用于 keycloak 设置的内容,如果您已经阅读了他在更新部分提到的 secret 问题的问题

    apiVersion: v1
    kind: Service
    metadata:
    name: keycloak
    labels:
    app: keycloak
    spec:
    ports:
    - name: http
    port: 8080
    targetPort: 8080
    selector:
    app: keycloak
    type: ClusterIP
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: keycloak
    namespace: default
    labels:
    app: keycloak
    spec:
    replicas: 1
    selector:
    matchLabels:
    app: keycloak
    template:
    metadata:
    labels:
    app: keycloak
    spec:
    containers:
    - name: keycloak
    image: quay.io/keycloak/keycloak:10.0.0
    env:
    - name: KEYCLOAK_USER
    value: "admin"
    - name: KEYCLOAK_PASSWORD
    value: "admin"
    - name: PROXY_ADDRESS_FORWARDING
    value: "true"
    - name: DB_VENDOR
    value: POSTGRES
    - name: DB_ADDR
    value: postgres
    - name: DB_DATABASE
    value: keycloak
    - name: DB_USER
    value: root
    - name: DB_PASSWORD
    value: password
    - name : KEYCLOAK_HTTP_PORT
    value : "80"
    - name: KEYCLOAK_HTTPS_PORT
    value: "443"
    - name : KEYCLOAK_HOSTNAME
    value : keycloak.harshmanvar.tk #replace with ingress URL
    ports:
    - name: http
    containerPort: 8080
    - name: https
    containerPort: 8443
    readinessProbe:
    httpGet:
    path: /auth/realms/master
    port: 8080
    您可以尝试将 ENV 变量更改为您正在使用的 key 。
    示例文件: https://github.com/harsh4870/Keycloack-postgres-kubernetes-deployment
    Keycloak 支持的环境变量: https://github.com/keycloak/keycloak-containers/blob/master/server/README.md#environment-variables

    关于kubernetes - "Failed to connect to database": Keycloak Operator external database Config not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68753971/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com