使用CloudSQL Postgres数据库的GKE集群后台无法部署



我目前正试图在后台部署到使用CloudSQL中的postgres数据库的GKE集群。我已经部署了一个sidecar来访问我的部署中的cloudsql数据库,我有一个部署的docker容器。由于以下错误,后端部署无法部署:

{"level":"info","message":"Performing database migration","plugin":"catalog","service":"backstage","type":"plugin"}
Backend failed to start up KnexTimeoutError: Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?
at Client_PG.acquireConnection (/app/node_modules/knex/lib/client.js:307:26)
at async Runner.ensureConnection (/app/node_modules/knex/lib/execution/runner.js:287:28)
at async Runner.run (/app/node_modules/knex/lib/execution/runner.js:30:19)
at async listCompleted (/app/node_modules/knex/lib/migrations/migrate/migration-list-resolver.js:12:3)
at async Promise.all (index 1)
at async Migrator.latest (/app/node_modules/knex/lib/migrations/migrate/Migrator.js:63:29)
at async applyDatabaseMigrations (/app/node_modules/@backstage/plugin-catalog-backend/dist/index.cjs.js:2020:3)
at async CatalogBuilder.build (/app/node_modules/@backstage/plugin-catalog-backend/dist/index.cjs.js:4095:7)
at async createPlugin$4 (/app/packages/backend/dist/index.cjs.js:84:40)
at async main (/app/packages/backend/dist/index.cjs.js:276:29) {
sql: undefined,
bindings: undefined
}

这是我的部署:


apiVersion: apps/v1
kind: Deployment
metadata:
name: backstage-deployment
namespace: backstage
spec:
replicas: 1
selector:
matchLabels:
app: backstage
template:
metadata:
labels:
app: backstage
spec:
serviceAccountName: backstage-sa
containers:
- name: backstage
image: us-central1-docker.pkg.dev/px-mike-project-hje/backstage/backstage
imagePullPolicy: Always
ports:
- name: backstage
containerPort: 7007
env:
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: pg-db-ref
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: pg-db-ref
key: password
- name: POSTGRES_HOST
valueFrom:
secretKeyRef:
name: pg-db-ref
key: endpoint
- name: cloud-sql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.28.0
command:
- "/cloud_sql_proxy"
- "-ip_address_types=PRIVATE"
- "-log_debug_stdout"
- "-instances=px-mike-project-hje:us-central1:pg-database=tcp:5432"
securityContext:
runAsNonRoot: true
resources:
requests:
memory: "2Gi"
cpu: "1"

这是我的应用程序配置为我的数据库:

database:
client: pg
connection:
host: ${POSTGRES_HOST}
port: 5432
user: ${POSTGRES_USER}
password: ${POSTGRES_PASSWORD}
database: pg-database
ensureExists: false
pluginDivisionMode: schema
knexConfig:
pool:
min: 15
max: 30
acquireTimeoutMillis: 60000
idleTimeoutMillis: 60000
acquireConnectionTimeout: 10000
plugin: 
# catalog:
# connection:
#   database: pg-database
auth:
client: better-sqlite3
connection: ':memory:'

我已经尝试在本地运行docker映像并且成功了。我被卡住了运行部署与cloudsql postgres数据库成功。

First,需要一个云SQL端汽车代理通过gke集群访问数据库。遵循本教程并使用以下链接添加到部署中:https://cloud.google.com/sql/docs/postgres/connect-kubernetes-engine

第二后台使用knex进行数据库管理,因此在cloudsql postgres数据库中使用的数据库将通过后台创建。将应用配置更改为以下内容(可以从部署更改为环境变量):

database:
client: pg
connection:
host: localhost #${POSTGRES_HOST}
port: 5432
user: postgres # ${POSTGRES_USER}
password: password # ${POSTGRES_PASSWORD}

应该删除数据库配置的其余部分。

相关内容

  • 没有找到相关文章