跳到內容
AggregaAggregaAggregaAggrega
選擇語言: 繁體中文
本頁為機器翻譯。閱讀英文原文。

進階模式

本頁說明一個概念,也就是 Manifest 與 FeatureRecipe 作為決定建置在元件自己的 Recipe 之外還寫出什麼的地方,而不是可執行的工作區。每個實例的 Recipe 覆寫會在你建置的工作區中展示 Manifest 的那一半;請用下列命令把它寫入你自己的資料夾:

Terminal window
aggrega draft --example per-instance-recipe-override

接著它會印出要執行的下一批命令:

Terminal window
cd per-instance-recipe-override
aggrega pull --release release.yaml # writes release.lock, which the build reads
aggrega build --release release.yaml

一個實例,它自己的 Recipe

Manifest 的 type 層會把元件型別的每個實例繫結到一個 Recipe。它的 name 層會依實例在 Aggregate 中的名稱,把單一實例繫結到另一個,而在那裡被指名的實例採用它,同時該型別的每個其他實例仍保持 type 繫結。取自範例的 manifest.yaml:

spec:
mappings:
components:
type:
example/compute/greeter:1.0.0: compose/greeter-blue:1.0.0
name:
greeter-special: compose/greeter-green:1.0.0

最具體的項目勝出:

  1. 實例名稱的 name 項目;
  2. 以實例的版本指名型別的 type 項目,例如 example/compute/greeter:1.0.0;
  3. 未帶版本而指名型別的 type 項目;
  4. 完全沒有項目時,建置會中止,並指名未對應的實例。

Manifest 是一般的 YAML,因此它重複的值可以用錨點寫一次,再以別名參照。

帶有自己資源的 Feature

FeatureRecipe 可以在元件自己的資源旁渲染資源,來自由 source: 所指名、並由它的 valuesMapping 餵入的自有 chart,而不是更改元件的 Recipe 所渲染的內容。標準程式庫的 core/public-ingress 在 Kubernetes 上就是以這種方式由 helm/public-ingress 實現,它為所附加的元件渲染 Ingress。

元件所服務的請求路徑是應用程式本身的一部分,因此 Feature 在 values 中取得它;主機名稱是環境給元件的名稱,因此它在 infra 中,與描述叢集的設定放在一起。在一個代理程式、一個路由器,與兩個上游模型中,開發者在 Aggregate 中附加它,並寫下路徑:

features:
published:
type: core/public-ingress
values:
path: /

而 Release 為同一個附加項目給出它的主機,並確認目標叢集中有入口控制器在執行,沒有它建置就會中止,取自 release.yaml,已省略其註解:

published:
infra:
host: assistant.example.internal
control_plane_present: true

FeatureRecipe 以 .context.rendered_name(宿主元件依其提供者所回報的名稱)命名它渲染的資源,因此 Ingress 指向元件自己的 Recipe 所渲染的 Service。寫在 Aggregate 的 values 中的 host,或寫在 Release 的 infra 中的 path,會被拒絕並指名該欄位:每個支柱都是封閉的,而該欄位屬於另一個。在不同環境之間有所不同的路徑,是 Aggregate 宣告、並由每個 Release 滿足的參數。