Kubernetes 上的 MariaDB——合成 helm(StatefulSet),雙槽位認證
單一 MariaDB 資料庫由 helm 提供者的 Workload 合成在 Kubernetes 上渲染——沒有外部 chart。core/datastore/mariadb Component 繫結到 helm/mariadb Recipe,它宣告一個 form: stateful 的 Workload;helm 提供者將它轉譯為 StatefulSet、ClusterIP Service、Headless Service(StatefulSet 的穩定網路身分),以及資料目錄的 volumeClaimTemplate。
這個範例的目的是展示合成 helm 目標上 MariaDB 的 雙槽位認證模型。兩個密碼槽位以不同的機制傳遞,因為 Component 對它們的宣告不同,而 Recipe 依各槽位的要求連接它們。
草擬範例
你可以用下列命令建置這個範例,或是讓你的 AI 助理替你建置。
把範例寫入一個以它命名的新資料夾:
aggrega draft --example mariadb-helm-synth它接著會印出要接著執行的命令。第一個會切換到新資料夾:
cd mariadb-helm-synth建置
aggrega build --release release.yaml --auto-pull目錄從 .aggrega-config.yaml 指名的 hub 登錄庫解析,所以不需要 --catalog 旗標,而 --auto-pull 會在建置期間寫出全新複本所缺少的鎖定檔。四個資訊清單落在 dist/helm/helm/ 之下。
搭配 AI 助理
以 Aggrega 的工具設定好的 AI 助理可以做同樣的事:把這個提示貼給它。
只使用 Aggrega 工具,且不要自行建立任何資料夾。如果工作區資料夾中還沒有 `mariadb-helm-synth` 資料夾,請呼叫一次 `draft` 工具,將 `example` 設為 `mariadb-helm-synth`,且不指定 `dir`:它會把範例寫入新的 `mariadb-helm-synth` 資料夾。接著呼叫 `build` 工具,將 `workspace_root` 設為 `mariadb-helm-synth`、`release` 設為 `release.yaml`、`auto_pull` 設為 true、`write` 設為 true。告訴我建置寫出了哪些檔案;它們位於 `mariadb-helm-synth/dist/` 之下。root_password——黑箱,在 inject 管道上傳遞
root_password 是 黑箱 槽位:Component 的 featuresSchema 宣告 inject: [],所以由 Recipe 控制傳遞,開發者無法規定。Aggregate 附加 core/secret-value,Manifest 將它對應到 env-secret。該 FeatureRecipe 將值以所選的鍵放在元件的 inject 管道上,而 Recipe 將它讀作 .context.inject.env.MARIADB_ROOT_PASSWORD,發出一個一般的容器環境變數:
# db-statefulset.yaml (container env)- name: MARIADB_ROOT_PASSWORD value: dev-root-pw-change-me黑箱槽位從不會從工作負載容器的 attachments: 區塊被參照,也不會為它產生 Kubernetes Secret 資源——值直接透過 inject 管道到達容器。
user_password——透明,以 Secret + secretKeyRef 傳遞
user_password 是 透明 槽位(inject: [env, file])。Aggregate 附加 core/referenced-secret,Manifest 將它對應到 k8s-secret-from-parameter。該 FeatureRecipe 具體化一個 Kubernetes Secret,並將 Secret 的身分發布為 provides {name, key}。Recipe 透過 containers.attachments 參照該槽位,合成器將它渲染為環境變數的 secretKeyRef。產生的 Secret 與容器的參照指名 同一個 資源,因為兩者都讀取 .features.user_password.provides.name——沒有重新推導,也沒有讓兩側達成一致的慣例。發布的名稱會將槽位名稱中的底線正規化為連字號,所以 user_password 成為有效的 Kubernetes 資源名稱 db-user-password。承載它的檔名是另一次推導,讀起來不同:它將元件與槽位名稱加上前綴,作為附件自己的座標,編碼成只允許小寫字母與數字的檔名字母表,所以底線在那裡以跳脫形式而非連字號出現。
[… omitted: the apiVersion and the Secret kind]metadata: name: db-user-password [… omitted: the labels and annotations every rendered document carries]stringData: MARIADB_PASSWORD: "dev-user-pw-change-me"
# db-statefulset.yaml (container env)- name: MARIADB_PASSWORD valueFrom: secretKeyRef: name: db-user-password # == the Secret's metadata.name key: MARIADB_PASSWORD # == the Secret's data key不附加 user_password 也是有效的:Recipe 回退到內嵌的開發預設值(MARIADB_PASSWORD: apppass),且不產生 Secret,所以最小的部署仍可渲染並執行。
操作員的大小設定
release.yaml 依環境滿足操作員大小設定支柱:容器映像檔標籤來自 infra.engine_version(mariadb:11.4),而 volumeClaimTemplate 的請求與儲存類別來自 infra.storage(5Gi、standard)。開發者的 Aggregate 從不攜帶這些欄位。