叢集範本

Azure CycleCloud 會使用範本來定義叢集組態。 根據預設,CycleCloud 中會包含一些範本,而且 GitHub 中提供支援範本的完整清單。 您可以建立新的範本,也可以自訂現有的範本。 例如,您可能想要自訂現有的範本來利用 現成 VM,或者您可能想要新增一個要擴充您自己的網路。

組態標記法

Azure CycleCloud 叢集範本全都有一或多個屬於節點或 nodearray 的 [[[組態]] 區段的選項。 這些區段會指定 CycleCloud 所啟動之節點的相關軟體組態選項。 虛線標記法可用來指定您想要設定的屬性:

[[node scheduler]]
  [[[configuration]]]
  cycle_server.admin.name = poweruser
  cycle_server.admin.pass = super_secret
  cycle_server.http_port = 8080
  cycle_server.https_port = 8443

您也可以使用 prefix 標記法來指定組態區段來儲存輸入。 相同的組態也可以撰寫為:

[[node scheduler]]
  [[[configuration cycle_server]]]
  admin.name = poweruser
  admin.pass = super_secret
  http_port = 8080
  https_port = 8443

如有需要,節點/nodearray 也可以包含多個組態區段:

[[node scheduler]]
  [[[configuration]]]
  run_list = role[sge_scheduler_node]

  [[[configuration cycle_server.admin]]]
  name = poweruser
  pass = super_secret

叢集範本參數

叢集範本可以包含參數,這些參數會改變叢集特定部分的值,而不需要修改範本本身。 這在需要少量差異的許多類似叢集的情況下特別有用,例如部署開發和生產環境。 在叢集範本內指定參數的語法,是在變數前面加上 '$'。 基本範本範例 (具有某些參數的非功能性) 看起來可能像這樣:

# template.txt
[cluster gridengine]

  [[node scheduler]]
  MachineType = $machine_type

    [[[configuration]]]
    gridengine.slots = $slots

此範本會定義兩個參數: $machine_type$slots 。 使用此範本,您可以定義文字檔,其中包含開發與生產環境中參數的值。 參數檔案可以是 JSON 格式或 JAVA 屬性檔案格式:

# dev-params.json
{
  "machine_type": "H16r",
  "slots": 2
}

# prod-params.properties
machine_type = Standard_D4v3
slots = 8

這會建立 JSON 檔案,其中包含 dev 的參數,以及包含生產環境的 .properties 檔案。

注意

參數檔案的檔案名尾碼很重要! 如果使用 JSON,您的檔案必須命名為 foo.json 。 如果使用 JAVA 屬性,您的檔案結尾必須是 .properties 。 名稱不正確的參數檔案無法正確匯入。

您現在可以使用參數檔案匯入範本,以填入遺漏的部分:

cyclecloud import_cluster gridengine-dev -f template.txt -p dev-params.json -c gridengine

cyclecloud import_cluster gridengine-prod -f template.txt -p prod-params.properties -c gridengine

您也可以在叢集範本本身內定義部分或所有參數:

# template.txt
[cluster gridengine]

  [[node scheduler]]
  MachineType = $machine_type

    [[[configuration]]]
    gridengine.slots = $slots

[parameters]
  [[parameter machine_type]]
  DefaultValue = Standard_D4v3

  [[parameter slots]]
  DefaultValue = 2

每個參數的預設值都會定義在範本內, (我們使用 'dev' 值作為預設值) 。

現在,您可以匯入沒有參數檔案的範本,而且會自動使用 'dev' 值。 當建立 'prod' 叢集時,您可以使用 prod-params.properties 檔案覆寫範本檔案本身中指定的值。

注意

參數名稱可以包含任何字母、數位和底線。

範本中的參數參考可以採用下列兩種形式之一:

$param:使用名為 的單一參數值 param

${expr}:在所有 expr 參數的內容中評估,這可讓您計算動態值。 例如:

Attribute = ${(a > b ? a : b) * 100}

這會採用兩個參數中較大的 和 ba 並將它乘以 100。 運算式會根據 ClassAd 語言規格來解譯和評估。

如果參數參考本身存在,則會使用 參數的值,其支援非字串類型,例如布林值、整數和巢狀結構,例如清單。 不過,如果參考內嵌在其他文字中,則會轉換其值並包含在字串中。 例如,假設 param 定義為 456 ,並在兩個位置中參考:

  • Attribute1 = $param
  • Attribute2 = 123$param

的值 Attribute1 會是數位 456 ,但 的值 Attribute2 會是字串 "123456" 。 請注意, ${param} 與 相同 $param ,可讓您在更複雜的情況下內嵌參數參考:

  • Attribute3 = 123$param789
  • Attribute4 = 123${param}789

Attribute3 會尋找名為 param789 的參數,但 Attribute4 會使用 的值 param 來取得 "123456789"

電腦類型

Azure CycleCloud 透過 屬性支援多個電腦類型 MachineType 。 它會嘗試依列出的順序取得容量。

叢集 Init 規格

Azure CycleCloud Web 應用程式可讓使用者在建立新叢集時選取 cluster-init 專案規格。 專案規格是在叢集範本內設定:

[parameter ClusterInitSpecs]
Label = Cluster-Init
Description = Cluster init specs to apply to nodes
ParameterType = Cloud.ClusterInitSpecs

[cluster demo]

  [[node defaults]]
  AdditionalClusterInitSpecs = $ClusterInitSpecs

      [[[cluster-init myproject:myspec:1.0.0]]]

將此參數新增至叢集範本之後,使用者就可以使用檔案選擇器,在建立新的叢集時選取適當的專案規格。

現成虛擬機器

若要降低工作負載的成本,您可以設定 Interruptible = true 。 這會將您的實例標示為 Spot,並在可用時使用剩餘容量。 請務必注意,這些實例不一定可用,而且可以隨時先占,這表示它們不一定適合您的工作負載。

根據預設,將 設定 Interruptible 為 true 會使用設定為 -1 的現成實例,這表示不會根據價格收回實例。 執行個體的價格會是現成品的目前價格或標準執行個體的價格 (取兩者中較小者),只要有可用的容量和配額即可。 如果您想要設定自訂價格上限,請使用 MaxPrice 所需節點或 nodearray 上的 屬性。

[cluster demo]

  [[nodearray execute]]
  Interruptible = true
  MaxPrice = 0.2

查閱資料表

您可以有一個參數參考另一個參數,並使用查閱表格計算特定值。 例如,假設您有要使用的映射參數,在此情況下有兩個選項:

[[parameter MachineImage]]
    Label = Image
    DefaultValue = image-1000
    Description = Ubuntu 22.04
    Config.Plugin = pico.control.AutoCompleteDropdown
    [[[list Config.Entries]]]
        Name = image-1000
        Label = Ubuntu 20.04
    [[[list Config.Entries]]]
        Name = image-2000
            Label = Ubuntu 22.04

您也可以取得所選映射的 OS 版本,並使用它來進行其他組態,方法是將值設為值的查閱表格:

[[parameter AmiLookup]]
  ParameterType = hidden
  [[[record DefaultValue]]]
      image-1000 = Ubuntu 20.04
      image-2000 = Ubuntu 22.04

請注意,這會隱藏,使其不會出現在 UI 中。

您可以在叢集定義中的任何位置取得用於所選映射的 OS 版本:

[[node node]]
[[[configuration]]]
version = ${AmiLookup[MachineImage]}

GUI 整合

在叢集範本中定義參數,可讓其中一個參數利用 Azure CycleCloud GUI。 例如,定義參數時,可以使用下列屬性來協助建立 GUI:

# template.txt
[cluster gridengine]

  [[node scheduler]]
  MachineType = $machine_type

    [[[configuration]]]
    gridengine.slots = $slots

[parameters]
  [[parameter machine_type]]
  DefaultValue = Standard_D4v3
  Label = Machine Type
  Description = MachineType to use for the Grid Engine scheduler node
  ParameterType = Cloud.MachineType

  [[parameter slots]]
  DefaultValue = 2
  Description = The number of slots for Grid Engine to report for the node

「標籤」和「描述」屬性包含在 GUI 中,以及選擇性的 「ParameterType」 屬性。 「ParameterType」 允許顯示自訂 UI 元素。 在上述範例中,「Cloud.MachineType」 值會顯示包含所有可用電腦類型的下拉式清單。 其他 ParameterType 值如下:

參數類型 Description
Cloud.MachineType 顯示包含所有可用電腦類型的下拉式清單。
Cloud.Credentials 顯示包含所有可用認證的下拉式清單。
Cloud.Region 顯示包含所有可用區域的下拉式清單。

Chef 伺服器支援

Azure CycleCloud 支援 ChefServer

建立檔案 chefserver.json 並新增您的認證。 ValidationKey 會對應至 chef 伺服器的 validation.pem 檔案。 如果您已從 「chef-validator」 的預設值變更它,您也必須證明 validation_client_name

{
"AdType" : "Cloud.Locker",
"ValidationKey" : "YOURVALIDATION.PEMHERE",
"ValidationClientName" : "chef-validator",
"Credentials" : "default",
"Location" : "https://mychefserver",
"ChefRepoType" : "chefserver",
"LockerType" : "chefrepo",
"Name" : "chefrepo",
"AccountId" : "default",
"Shared" : false
}

接下來,將檔案放在 目錄中 /opt/cycle_server/config/data 。 它會自動匯入。

範本中的自訂使用者映射

Azure CycleCloud 支援範本中的自訂映射。 使用 直接 ImageId) 指定映射識別碼 (資源識別碼,或將映射新增至映射登錄。 當映射位於登錄中時,請使用 ImageImageName 在您的節點上參考它。 它會出現在叢集建立頁面的 [映射] 下拉 式清單中。

映射登錄中的映射是由一筆 Package 記錄所組成,可識別邏輯映射的內容,以及一或多個對應 Artifact 記錄,以指定適當雲端提供者中的實際映射識別碼。 例如,已安裝 R 的自訂映射可能包含此套件記錄:

AdType = "Package"
Name = "r_execute"
Version = "2.1.1"
PackageType = "image"
Label = "R"

新增該記錄之後,您可以藉由在叢集範本中包含 Image = RImageName = r_execute 來指定該映射。

如果此映射存在於 useast 中識別碼為 /subscriptions/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/images/MyCustomImage 的單一虛擬機器,則必須儲存下列成品:

AdType = "Artifact"
Package = "r_execute"
Version = "2.1.1"
Name = "az/useast"
Provider = "az"
ImageId = "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/images/MyCustomImage"

您必須在成品上指定 Provider

您可以視需要為指定的映射套件新增許多成品,但您必須在您想要的每個雲端提供者帳戶、區域、專案) 等 (一個位置中包含使用該映射所需的所有成品。 成品的名稱並不重要,不同之處在于它對於指定套件和版本的所有成品必須是唯一的。 通常建議使用提供者和提供者特定 (詳細資料的組合,例如區域) 。 CycleCloud 會自動挑選正確的成品來比對提供者和任何提供者特定的詳細資料,但它會使用 Provider 屬性 (和 Region 等) ,而不是剖析 Name。

如果您新增多個具有相同名稱的映射套件,它們必須有不同的版本號碼。 啟動實例時,CycleCloud 會自動挑選具有最高版本號碼的映射,方法是將版本號碼視為虛線字串,並將每個元件比較為數位。 若要覆寫此值,請在節點上指定 ImageVersion ,例如常值 (例如 1.2) 或萬用字元 () 1.x