CloudInit CRD
自 v1.3.0 版本起提供
您可以使用 CloudInit CRD 透過手動方式或 GitOps 解決方案來設定 Harvester 作業系統設定。
背景
Harvester 作業系統使用 elemental-toolkit,它具有一種獨特形式的 cloud-init 支援。
在 Harvester 安裝過程中設定的參數會寫入 /oem 目錄中的 elemental cloud-init 檔案。由於 Harvester 作業系統是不可變的 (immutable),cloud-init 檔案確保了節點特定的設定在每次重新啟動時都會被套用。
Harvester CloudInit CRD 透過 Kubernetes CRD 揭露 (exposes) 了 cloud-init 檔案。這允許您在安裝後修改節點特定設定,而無需執行將根檔案系統設為可寫入的額外步驟。
此外,CloudInit CRD 會被持久化並與底層主機同步,因此即使節點重新啟動或升級,直接對 Harvester 作業系統所做的變更也不會遺失。
CloudInit CRD 是叢集範圍 (cluster-scoped) 的資源。請確保您的使用者帳戶具有存取該資源所需的權限(透過 Rancher 角色型存取控制)。
入門指南
以下範例將 SSH 金鑰新增至現有 Harvester 叢集中的所有節點。
apiVersion: node.harvesterhci.io/v1beta1
kind: CloudInit
metadata:
name: my-ssh-keys
spec:
matchSelector:
harvesterhci.io/managed: "true"
filename: 99-my-ssh-keys
contents: |
stages:
network:
- name: "add my ssh keys"
authorized_keys:
rancher:
- ssh-rsa key1
- ssh-rsa key2
paused: false
spec 欄位包含以下內容:
matchSelector (必要):用於識別必須套用變更之節點的標籤選擇器 (Label selector)。harvesterhci.io/managed: "true"是一個 Harvester 專用標籤,您可以用它來選取所有節點。filename (必要):/oem中的檔案名稱。/oem中的 cloud-init 檔案會依字母順序套用。這可用於確保檔案變更在開機期間被正確套用。content (必要):要寫入目標節點的 Elemental cloud-init 資源的內嵌內容。paused (選用):用於暫停CloudInitCRD 的調和 (reconciliation)。Harvester 控制器會監控由CloudInitCRD 管理的 Elemental cloud-init 檔案。除非 CRD 處於暫停狀態,否則直接對這些檔案所做的變更會立即被調和回定義的狀態。
物件建立後,您可以登入目標節點來驗證結果。
在以下範例中,建立了一個名為 /oem/99-my-ssh-keys.yaml 的檔案,隨後由 Harvester 控制器進行監控。
harvester-qhgd4:/oem # more 99-my-ssh-keys.yaml
stages:
network:
- name: "add my ssh keys"
authorized_keys:
rancher:
- ssh-rsa key1
- ssh-rsa key2
status 子資源可用於追蹤變更推廣 (rollout) 到底層 Harvester 節點的情況。
在以下範例中,status 值表示變更已套用到叢集中的所有三個節點。
status:
rollouts:
harvester-kfs2c:
conditions:
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: ""
reason: CloudInitApplicable
status: "True"
type: Applicable
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: Local file checksum is the same as the CloudInit checksum
reason: CloudInitChecksumMatch
status: "False"
type: OutOfSync
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: 99-my-ssh-keys.yaml is present under /oem
reason: CloudInitPresentOnDisk
status: "True"
type: Present
harvester-qhgd4:
conditions:
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: ""
reason: CloudInitApplicable
status: "True"
type: Applicable
- lastTransitionTime: "2024-08-26T04:00:00Z"
message: Local file checksum is the same as the CloudInit checksum
reason: CloudInitChecksumMatch
status: "False"
type: OutOfSync
- lastTransitionTime: "2024-08-26T04:00:00Z"
message: 99-my-ssh-keys.yaml is present under /oem
reason: CloudInitPresentOnDisk
status: "True"
type: Present
harvester-rmvzg:
conditions:
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: ""
reason: CloudInitApplicable
status: "True"
type: Applicable
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: Local file checksum is the same as the CloudInit checksum
reason: CloudInitChecksumMatch
status: "False"
type: OutOfSync
- lastTransitionTime: "2024-08-26T03:57:33Z"
message: 99-my-ssh-keys.yaml is present under /oem
reason: CloudInitPresentOnDisk
status: "True"
type: Present
一旦套用了 cloud-init 變更,您必須重新啟動節點,以確保 elemental-toolkit 將請求的變更套用到作業系統。
刪除 CloudInit CRD 會導致從底層 Harvester 節點移除相關檔案。與其他 cloud-init 資源一樣,此變更的效果在受影響的節點重新啟動之前不會顯現。
建議您利用 Fleet 和 CloudInit CRD 來管理對 Harvester 作業系統的變更。