宣言型オートメーションバンドルを使用した一般的なLakebaseプロジェクト設定
このページには、最もよく使用される機能を含む、本番運用対応のLakebase オートスケール プロジェクト向けの完全な宣言型オートメーションバンドルが示されています:
- 保護された本番運用ブランチ
- 高可用性 (HA) 読み取り/書き込みエンドポイントと読み取り可能なセカンダリ
- サービスプリンシパルに対するインライン ワークスペースレベルの
CAN_MANAGEアクセス許可 - Unity Catalog からの継続的な同期テーブル ストリーミング
- Lakebase データベース向け Unity Catalog バインディング
- Lakebaseプロジェクトに接続されたDatabricksアプリ
Lakebase を使用した宣言型オートメーションバンドルのステップバイステップの入門については、宣言型オートメーションバンドルを使用した Lakebase の管理をご覧ください。
前提条件
始める前に、以下のものが必要です。
- Databricks CLI **v1.0.0 以降** バージョンを確認するには、
databricks --versionを実行します。インストールまたはアップグレードするには、「Databricks CLI のインストールまたは更新」を参照してください。 - Lakebaseが有効になっているDatabricksワークスペース
- OAuth マシン間(M2M)認証向けに構成されたサービスプリンシパル。バンドルは、このプリンシパルにプロジェクトへのワークスペース
CAN_MANAGE権限を付与します。OAuth を使用した Databricks へのサービスプリンシパル アクセスの承認 および プロジェクトのアクセス許可の管理 を参照してください。 - 同期ソースとして使用するための、チェンジデータフィード (CDF) が有効化されている Unity Catalog の Delta テーブル。データ同期が必要ない場合は、
postgres_synced_tablesとpostgres_catalogsのブロックを削除してください。
完全なバンドル構成
バンドルは、ワークスペース固有のすべての値に対して変数を使用します。.databricks/bundle/<target>/variables.jsonファイルで設定するか、デプロイ時に--varを使用して渡します。
プロジェクトを作成すると、Databricks は production ブランチおよび primary 読み書き可能なエンドポイントを自動的に作成します。これらの暗黙的に作成されたリソースを構成するには、replace_existing: true を使用して宣言します。
YAML
bundle:
name: lakebase-typical-project
variables:
project_id:
description: 'Lakebase project ID (lowercase, hyphen-delimited)'
default: 'my-lakebase-project'
display_name:
description: 'Human-readable project name shown in the UI'
default: 'My Lakebase project'
pg_version:
description: 'Postgres major version'
default: 17
min_cu:
description: 'Minimum compute units on the default endpoint'
default: 0.5
max_cu:
description: 'Maximum compute units on the default endpoint'
default: 4.0
suspend_timeout:
description: 'Idle time before the default endpoint suspends. Ignored when no_suspension is true.'
default: '300s'
admin_sp_app_id:
description: 'Application ID of the service principal to grant CAN_MANAGE on the project'
default: '<your-sp-application-id>'
source_table:
description: 'Unity Catalog three-part name of the Delta table to sync (catalog.schema.table)'
default: '<catalog>.<schema>.<table>'
primary_key_column:
description: 'Primary key column of the source Delta table'
default: '<pk>'
storage_catalog:
description: 'Unity Catalog catalog where the sync pipeline stores its metadata'
default: '<catalog>'
storage_schema:
description: 'Unity Catalog schema where the sync pipeline stores its metadata'
default: '<schema>'
app_name:
description: 'Databricks App name (must be unique in the workspace)'
default: 'my-lakebase-app'
uc_catalog_id:
description: 'Name to register the Lakebase database in Unity Catalog'
default: 'my_lakebase_uc_catalog'
targets:
prod:
default: true
workspace:
host: https://<your-workspace>.cloud.databricks.com
resources:
# Project — top-level container for branches, endpoints, and databases.
# The permissions block grants workspace-level CAN_MANAGE to the service principal.
postgres_projects:
lakebase_project:
project_id: ${var.project_id}
spec:
pg_version: ${var.pg_version}
display_name: ${var.display_name}
default_endpoint_settings:
autoscaling_limit_min_cu: ${var.min_cu}
autoscaling_limit_max_cu: ${var.max_cu}
suspend_timeout_duration: ${var.suspend_timeout}
permissions:
- service_principal_name: ${var.admin_sp_app_id}
level: CAN_MANAGE
# Configure the implicitly created production branch as protected.
postgres_branches:
production:
branch_id: production
parent: ${resources.postgres_projects.lakebase_project.name}
no_expiry: true
is_protected: true
replace_existing: true
# Configure the implicitly created primary endpoint with HA.
# HA requires no_suspension: true. group.min: 2 adds a standby for automatic failover.
postgres_endpoints:
primary:
endpoint_id: primary
parent: ${resources.postgres_branches.production.name}
endpoint_type: ENDPOINT_TYPE_READ_WRITE
autoscaling_limit_min_cu: ${var.min_cu}
autoscaling_limit_max_cu: ${var.max_cu}
no_suspension: true
group:
min: 2
max: 2
enable_readable_secondaries: true
replace_existing: true
# Sync a Unity Catalog Delta table into the project continuously.
postgres_synced_tables:
orders_sync:
synced_table_id: '${var.storage_catalog}.${var.storage_schema}.orders_synced'
branch: ${resources.postgres_branches.production.name}
postgres_database: databricks_postgres
source_table_full_name: ${var.source_table}
primary_key_columns:
- ${var.primary_key_column}
scheduling_policy: CONTINUOUS
create_database_objects_if_missing: true
new_pipeline_spec:
storage_catalog: ${var.storage_catalog}
storage_schema: ${var.storage_schema}
# Bind the Lakebase database into Unity Catalog so it is queryable as UC data.
postgres_catalogs:
lakebase_uc_catalog:
catalog_id: ${var.uc_catalog_id}
postgres_database: databricks_postgres
branch: ${resources.postgres_branches.production.name}
create_database_if_missing: true
# Databricks App connected to the project.
# Update source_code_path to point to your app source directory.
# The database value references databricks_postgres — the stable ID of the implicit
# database that every Lakebase project creates automatically.
apps:
lakebase_app:
name: ${var.app_name}
description: 'App backed by Lakebase autoscaling'
source_code_path: ./app_src
config:
command:
- flask
- run
- --host=0.0.0.0
- --port=8000
resources:
- name: lakebase-db
postgres:
branch: ${resources.postgres_branches.production.name}
database: ${resources.postgres_branches.production.name}/databases/databricks-postgres
permission: CAN_CONNECT_AND_CREATE
バンドルを適用する
検証およびデプロイ:
Bash
databricks bundle validate -t prod
databricks bundle deploy -t prod
databricks bundle deploy が最初の実行で完了しない場合は、再実行してください。
デプロイされるもの
バンドルによって以下のリソースが作成されます。
- 指定したコンピュートのデフォルトを使用する Lakebase オートスケール プロジェクト。
- 保護された
productionブランチ - HA と読み取り可能なセカンダリを備えたプライマリの読み取り/書き込みエンドポイント
- プロジェクトデータベースに Unity Catalog の Delta テーブルをストリーミングする継続的な同期パイプラインです。
- Lakebaseデータベースによってバックアップされ、UCデータとしてクエリ可能なUnity Catalogカタログです。
- Databricksアプリがプロジェクトデータベースに接続されています。
- 指定したサービスプリンシパルに対するワークスペースの
CAN_MANAGEアクセス許可。
次のステップ
- 高可用性については、HAパターンおよび本番運用でのそれらの使用時期について説明します。
- 「同期テーブルを使用してレイクハウス データを提供する」では、スケジュール オプションとパイプライン管理を扱っています。
- プロジェクトのアクセス許可を管理するには、ワークスペースレベルおよびデータベースレベルのアクセス制御が対象となります。
- カスタム Databricks アプリを Lakebase に接続するでは、Databricks Apps をオートスケールプロジェクトに接続する方法が示されています。
- 宣言型オートメーションバンドル リソースは、宣言型オートメーションバンドルの完全なリソースリファレンスを提供します。