# Rancher Elemental * Elemental 是兩個主要項目的組合:Elemental Toolkit 和 Elemental Operator。 - Elemental Toolkit 支援從 OCI container image 安裝和更新作業系統,因此可以透過 container image 安裝作業系統所需套件和設定。 - Elemental Operator 利用 Elemental Toolkit,透過作業系統配置和作業系統管理功能擴展了 Rancher。它整合了 Elemental Toolkit 和 Rancher RKE2/K3s 叢集配置之間的差距,提供從沒有作業系統的主機到完全配置的 Kubernetes 叢集的無縫體驗。 ![image](https://hackmd.io/_uploads/S1urDslWkg.png) ## 安裝 * 在 local 叢集先安裝 CRD ``` $ helm upgrade --create-namespace -n cattle-elemental-system --install elemental-operator-crds oci://registry.suse.com/rancher/elemental-operator-crds-chart ``` * Extensions -> 安裝 Elemental ![image](https://hackmd.io/_uploads/BklGX6Ogkg.png) * 安裝好後 rancher ui 左邊會多出選項,如果沒出現就 refresh 瀏覽器 ![image](https://hackmd.io/_uploads/rklB46dxke.png) * 它會將你重新導向到 local 叢集 Marketplace 安裝 ![image](https://hackmd.io/_uploads/SJZ9Sp_eye.png) ``` $ kubectl -n cattle-elemental-system get all NAME READY STATUS RESTARTS AGE pod/elemental-operator-84464f9f6b-v67k8 1/1 Running 0 46s NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/elemental-operator 1/1 1 1 29s NAME DESIRED CURRENT READY AGE replicaset.apps/elemental-operator-84464f9f6b 1 1 1 46s ``` * 在 local 叢集可以看到 `elemental-operator-crds`、`elemental-operator` 部署在 `cattle-elemental-system` ![image](https://hackmd.io/_uploads/HyRxv6Oxke.png) ## 新增 Machine Registration Endpoint * 選擇 `Create Registration Endpoint` ![image](https://hackmd.io/_uploads/HyVtPTdeJg.png) * 設定 OS 使用者以及固定 ip 等參數,可以使用 cloud init 語法 * 點選 Edit as Yaml 匯入以下 yaml ``` apiVersion: elemental.cattle.io/v1beta1 kind: MachineRegistration metadata: name: elemental-cluster-1 namespace: fleet-default spec: config: cloud-config: users: - name: root passwd: root write_files: - content: | [connection] id=eth0 type=ethernet interface-name=eth0 autoconnect=true [ipv4] method=manual address1=172.20.7.100/16 gateway=172.20.0.254 dns=8.8.8.8; [ipv6] method=ignore path: /etc/NetworkManager/system-connections/eth0.nmconnection permissions: "0600" elemental: install: debug: true device: /dev/sda reboot: true snapshotter: type: loopdevice reset: reboot: true reset-oem: true reset-persistent: true machineName: my-machine machineInventoryLabels: author: andy machineUUID: ${System Information/UUID} manufacturer: ${System Information/Manufacturer} productName: ${System Information/Product Name} serialNumber: ${System Information/Serial Number} ``` ![image](https://hackmd.io/_uploads/BJzekMpUyg.png) ## 新增 OS Version Channels * `ManagedOSVersionChannel` 資源是負責定義作業系統 image 的通道 * OS Version Channels -> 建立 image * 新增 KVM 虛擬化專用 image ![image](https://hackmd.io/_uploads/SyynAlDWJg.png) ![image](https://hackmd.io/_uploads/Syp6CgD-kl.png) `registry.suse.com/rancher/elemental-channel/sl-micro:6.0-kvm` ## 建立 seed image * Registration Endpoint -> 選擇 ISO -> Build Media,在 build 的時候不能離開這個畫面不然會要重新 Build * 使用 kvm 版本的 OS Version Build iso ![image](https://hackmd.io/_uploads/rkimkzaIJe.png) * Build 好後點擊下載 iso ![image](https://hackmd.io/_uploads/rklSkMT81e.png) * 檢視 build 好的 iso pod ``` $ kubectl -n fleet-default get po NAME READY STATUS RESTARTS AGE media-image-reg-elemental-cluster-1-mejspvvk 1/1 Running 0 54s rke2-machineconfig-cleanup-cronjob-28842725-fp2cc 0/1 Completed 0 2d10h rke2-machineconfig-cleanup-cronjob-28844165-jgghw 0/1 Completed 0 34h rke2-machineconfig-cleanup-cronjob-28845605-f7bzz 0/1 Completed 0 10h ``` * 可以看到第一個容器幫你下載拉取,第二個容器幫你建置打包,第三個容器負責讓你下載。 ![image](https://hackmd.io/_uploads/rk9h1faU1g.png) * 找到下載網址 ``` $ kubectl get seedimage -n fleet-default media-image-reg-elemental-cluster-1-mejspvvk -o yaml ...... status: conditions: - lastTransitionTime: "2025-01-09T08:56:08Z" message: resources created successfully reason: ResourcesSuccessfullyCreated status: "True" type: Ready - lastTransitionTime: "2025-01-09T08:56:12Z" message: seed image iso available reason: SeedImageBuildSuccess status: "True" type: SeedImageReady downloadToken: cr7jxzr2rvckdpnhsglpb2ncx5nkwlbh8lcw4hw4rlrsj9ck9xwhl2 downloadURL: https://172.20.7.30/elemental/seedimage/cr7jxzr2rvckdpnhsglpb2ncx5nkwlbh8lcw4hw4rlrsj9ck9xwhl2/elemental-cluster-1-2025-01-09T08:56:08Z.iso ``` * wget 直接下載 iso,需注意自己的 seedimage 名稱 ``` $ wget --no-check-certificate $(kubectl get seedimage -n fleet-default media-image-reg-elemental-cluster-1-mejspvvk -o jsonpath="{.status.downloadURL}") -O elemental.iso ``` ## 在 PVE 上開機 * 選擇透過 Elemental build 好的 iso,選擇 UEFI 開機,以及使用 TPM 功能。 ![image](https://hackmd.io/_uploads/rkBMahnLkl.png) ![image](https://hackmd.io/_uploads/B1D_qlpUJx.png) ## 建立 Elemental rke2 叢集 * 成功開機後,vm 會先跟 rancher 註冊,然後獲取 cloud-init 再去做 vm 初始化,初始化成功後在 rancher `Inventory of Machines` 可以看到可用的機器。 * 所以環境內一定要有 dhcp server 先分配 ip 給 vm,讓他能夠跟 rancher 註冊。 ![image](https://hackmd.io/_uploads/ryXb0epLJx.png) * 點選建立叢集 ![image](https://hackmd.io/_uploads/H1l2Y6WTIJe.png) * 透過 key/value 的方式指定哪一個 vm 建立叢集 ![image](https://hackmd.io/_uploads/Hk3FKlaIyx.png) * RKE2 叢集建立完成 ![image](https://hackmd.io/_uploads/HkyJ5eTIJx.png) ## 建立第二個節點 * 參考上述流程,在建立一個 Machine Registration Endpoint,注意修改自己的 ip 與 machineName ``` apiVersion: elemental.cattle.io/v1beta1 kind: MachineRegistration metadata: name: elemental-cluster-2 namespace: fleet-default spec: config: cloud-config: users: - name: root passwd: root write_files: - content: | [connection] id=eth0 type=ethernet interface-name=eth0 autoconnect=true [ipv4] method=manual address1=192.168.11.119/16 gateway=192.168.11.254 dns=8.8.8.8; [ipv6] method=ignore path: /etc/NetworkManager/system-connections/eth0.nmconnection permissions: "0600" elemental: install: debug: true device: /dev/sda reboot: true snapshotter: type: loopdevice reset: reboot: true reset-oem: true reset-persistent: true machineName: my-machine-2 machineInventoryLabels: author: andy-2 machineUUID: ${System Information/UUID} manufacturer: ${System Information/Manufacturer} productName: ${System Information/Product Name} serialNumber: ${System Information/Serial Number} ``` ![image](https://hackmd.io/_uploads/B1AdwNUJle.png) * 產生 iso 後開機,在 Inventory of Machines 就可以看到第二台機器註冊成功 ![image](https://hackmd.io/_uploads/SJr1_EIJlx.png) ## 參考 https://warnerchen.github.io/2024/11/20/Rancher-Elemental-%E4%BD%BF%E7%94%A8%E9%9A%8F%E8%AE%B0/ https://elemental.docs.rancher.com/quickstart-ui https://documentation.suse.com/suse-edge/3.0/html/edge/components-eib.html https://github.com/suse-edge/edge-image-builder/blob/release-1.0/docs/building-images.md https://blog.csdn.net/weixin_46510209/article/details/138254606 https://github.com/rancher/yip?tab=readme-ov-file#stagesstageidstepnhostname