# Learning and Practicing Harvester <style> .indent-title-1{ margin-left: 1em; } .indent-title-2{ margin-left: 2em; } .indent-title-3{ margin-left: 3em; } </style> ## Preface <div class="indent-title-1"> 本篇文章會主要會介紹以下主題 : 1. Harvester 的架構 2. 如何安裝 Harvester,並將額外的節點加入 Harveter Cluster 3. 將 Harvester 與 Rancher 整合,做出 Nested Kubernetes Clusters 以及 Node Pool 可以透過點擊以下目錄,選擇想看的內容,跳轉至特定章節 :::warning :::spoiler {state="open"} 目錄 [TOC] ::: </div> ## Harvester Architecture <div class="indent-title-1"> ![image](https://hackmd.io/_uploads/SySzSf0qT.png) Harvester 架構由以下開源技術組成: 1. Linux 作業系統 : Elemental for SLE-Micro 5.3 是 Harvester 的核心,它是一個不可變的 Linux 發行版,旨在盡可能消除 Kubernetes 叢集中的作業系統維護工作。 2. 建構於 Kubernetes(RKE2) 之上 : Kubernetes 已成為所有形式因素中最主要的基礎架構語言,而 Harvester 就是一個在引擎蓋下裝有 Kubernetes 的 HCI 解決方案。 3. 利用 Kubevirt 進行虛擬化管理 : Kubevirt 在 Kubernetes 的基礎上使用 KVM 提供虛擬化管理。 4. 利用 Longhorn 進行儲存管理 : Longhorn 提供分散式區塊儲存。 </div> ## Harvester Features <div class="indent-title-1"> Harvester 是一個 enterprise-ready、易於使用的基礎架構平台,它利用本地直接連接的 Storage,而不是複雜的外部 SAN。 它利用 Kubernetes API 作為跨 Container 和 虛擬機器 workloads 的統一自動化語言。 Harvester 的一些主要功能包括 : 1. 易於上手 : 由於 Harvester 是以可啟動裝置鏡像的形式提供的,因此您可以使用 ISO 映像直接將其安裝到裸機伺服器上,也可以使用 iPXE 腳本自動安裝。 2. 虛擬機器生命週期管理 : 輕鬆建立、編輯、複製和刪除虛擬機,包括 SSH 金鑰注入、Cloud Init 以及圖形化界面 (VNC) 和 serial port (22 port) 控制台。 3. 虛擬機器即時遷移 : 零停機時間將虛擬機器遷移到不同的主機或節點。 4. 虛擬機器備份、快照和還原 : 從 NFS、S3 伺服器或 NAS 設備備份虛擬機器。 使用備份好的虛擬硬碟檔還原故障的虛擬機,或在不同的叢集上建立新的虛擬機。 5. 儲存管理 : Harvester 支援分散式區塊的儲存和 tiering (分層)。 Volumes 代表 storage;你可以輕鬆建立、編輯、複製或匯出磁碟區。 6. 網路管理 : 支援使用虛擬 IP(VIP)和多個網路介面卡(NIC)。 如果虛擬機器需要連接外部網絡,可建立 VLAN 或 untagged (無標記) 網路。 7. 與 Rancher 整合 : 透過 Rancher 的虛擬化管理頁面直接存取 Rancher 中的 Harvester,並與 Kubernetes 叢集一起管理 VM workloads (虛擬機器工作負載),實現 Node Pool 的功能。 </div> ## PreRequest ### Hardware and Network Requirements <div class="indent-title-1"> ![image](https://hackmd.io/_uploads/SkCXYmAqp.png) > 詳細資訊,請以下參考 Harvester 官網 Docs : > [Hardware and Network Requirements](https://docs.harvesterhci.io/v1.2/install/requirements/) </div> ## Install Single-Node Harvester Clusters with USB ### 1. 下載 ISO 並透過 Rufus 將 USB 做成可開機裝置 <div class="indent-title-1"> 1.1. 下載 ISO <div class="indent-title-1"> 可以使用 ISO 鏡像直接將 Harvester 安裝到裸機伺服器上,若要取得 ISO 映像,請從 [Harvester releases 頁面](https://github.com/harvester/harvester/releases)下載 💿 `harvester-v1.x.x-amd64.iso`。 ```! $ wget --show-progress https://releases.rancher.com/harvester/v1.2.1/harvester-v1.2.1-amd64.iso ``` 螢幕輸出 : ``` --2024-02-16 10:59:20-- https://releases.rancher.com/harvester/v1.2.1/harvester-v1.2.1-amd64.iso Resolving releases.rancher.com (releases.rancher.com)... 13.35.35.42, 13.35.35.123, 13.35.35.33, ... Connecting to releases.rancher.com (releases.rancher.com)|13.35.35.42|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 5497749504 (5.1G) [application/octet-stream] Saving to: ‘harvester-v1.2.1-amd64.iso’ harvester-v1.2.1-amd64.iso 100%[===========================================================>] 5.12G 35.8MB/s in 4m 14s 2024-02-16 11:03:34 (20.6 MB/s) - ‘harvester-v1.2.1-amd64.iso’ saved [5497749504/5497749504] ``` </div> </div> <div class="indent-title-1"> 1.2. 開啟 Rufus,將乾淨的 USB 碟插入電腦,Rufus 會自動偵測 USB。 從 "裝置 "下拉式選單中選擇要使用的 USB 裝置,在 "啟動選擇 "中選擇 "選擇",然後找到要燒錄到 USB 上的 Harvester 安裝 ISO 映像。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SJq32Ynsa.png) </div> </div> ### 2. 安裝步驟 <div class="indent-title-1"> 2.1. 使用 USB 開機,並透過選擇 Harvester Installer 選項啟動伺服器。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rJiMSL2iT.png) > 使用預設選項,直接按 Enter 按鍵。 </div> </div> <div class="indent-title-1"> 2.2. 選擇建立一個新的 Harvester Cluster <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/S17TBIhsa.png) > 使用預設選項,直接按 Enter 按鍵。 </div> </div> <div class="indent-title-1"> 2.3. 選擇要安裝的 Harvester 系統碟和要儲存虛擬機器資料的資料碟。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HyvFI83sT.png) > 按 Tab 鍵可展開下拉式選單,按 Enter 鍵儲存設定值。 </div> </div> <div class="indent-title-1"> 2.4. 設定主機的 Hostname <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rkByPU2sT.png) > 輸入 `h1` </div> </div> <div class="indent-title-1"> 2.5. 設定管理網路 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJ9RDLhs6.png) > 網路卡的部分,按 Tab 展開下拉式選單,按空白鍵選擇網路卡,確定之後按 Enter 鍵 > IPv4 Address 欄位,輸入 : `172.20.0.34/24` > Gateway 欄位,輸入 : `172.20.0.254` </div> </div> <div class="indent-title-1"> 2.6. 設定 DNS Server <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkK3uLnip.png) > DNS Server 欄位 : `172.20.0.254` </div> </div> <div class="indent-title-1"> 2.7. 設定 VIP <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/B1im_wnsp.png) > 按 Tab 展開下拉式選單,按向下方向鍵選擇 `Static`,確認後按 Enter 鍵。 > VIP 欄位 : `172.20.0.36` </div> </div> <div class="indent-title-1"> 2.8. 設定 Cluster Token <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryxCdvno6.png) > Cluster token 欄位 : `lab` > Cluster token 用於將其他節點新增至 Harvester 叢集。 </div> </div> <div class="indent-title-1"> 2.9. 設定使用者密碼 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkGStD3ja.png) > 預設的使用者是 `rancher`。 </div> </div> <div class="indent-title-1"> 2.10. 設定 NTP Server <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HJBFYv3jT.png) > NTP Server 欄位 : `time.google.com`。 </div> </div> <div class="indent-title-1"> 2.11. 設定 HTTP Proxy Server ( 此步驟不一定要設定,取決於當下的環境 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HyJ-qDhsT.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.12. 匯入 SSH Keys ( 此步驟不一定要設定 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rkjwqPnia.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.13. 設定 Harvester 設定檔自訂主機 ( 此步驟不一定要設定 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJbMjwhjp.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.14. 查看並確認安裝選項 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryFujwhja.png) > 確認安裝選項沒問題後,按 Enter 鍵,Harvester 將會安裝到主機上。 </div> </div> <div class="indent-title-1"> 2.15. 安裝完成後,節點將重新啟動,以下是啟動完成畫面 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/B13ey_nip.png) > 重新啟動後,Harvester 控制台會顯示管理 URL 和狀態。網路介面的預設 URL 是 `https://your-virtual-ip`。 可以使用 F12 按鍵從 Harvester 控制台切換到 Shell,然後鍵入 exit 返回 Harvester 控制台。 </div> </div> <div class="indent-title-1"> 2.16. 第一次登入的時候,系統會提示您設定預設管理員使用者的密碼。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HJPjyunsa.png) > 使用者預設是 `admin` </div> </div> ## Update Harvester Configuration After Installation ### DNS servers 1. SSH 連線至 Harvester Node <div class="indent-title-2"> ```! $ ssh rancher@172.20.0.36 ``` </div> 2. 備份基本的 cloud-init 檔案 `/oem/90_custom.yaml` <div class="indent-title-2"> ```! $ sudo cp /oem/90_custom.yaml /oem/install/90_custom.yaml.$(date --iso-8601=minutes) ``` </div> 3. 修改 `/oem/90_custom.yaml` 檔案,並且更新以下 Yaml 檔中路徑的值 `stages.initramfs[0].commands` <div class="indent-title-2"> ```! $ sudo vim /oem/90_custom.yaml ``` 修改範例內容如下 : <pre> name: Harvester Configuration stages: initramfs: - commands: - modprobe kvm - modprobe vhost_net - sed -i 's/^NETCONFIG_DNS_STATIC_SERVERS.*/NETCONFIG_DNS_STATIC_SERVERS="<font color=red>172.20.0.37</font>"/' /etc/sysconfig/network/config </pre> > 將原本的 `172.20.0.254` 改成 `172.20.0.37` </div> 4. 重新開機 <div class="indent-title-2"> ```! $ sudo reboot ``` </div> 5. 確認 DNS Server 修改正確 <div class="indent-title-2"> ```! $ cat /etc/resolv.conf | grep -v '#' ``` 螢幕輸出如下 : ``` nameserver 172.20.0.37 ``` </div> ## 設定 Storage Class 1. 預設的 StorageClass 他的 Replicas 會被設為 3 ,但因為只有單一台 Node,所以要額外新增一個 StorageClass 並將 Replicas 設為 1,否則 VM 會無法建立。 2. 點選左側選單 Advanced -> Storage Classes -> Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rJRn6Onop.png) </div> 3. 輸入以下資訊 : <div class="indent-title-2"> * Name: `new-sc` * Number of Replicas 設為 `1` 確認資訊輸入正確後,點選 Create ![image](https://hackmd.io/_uploads/rk0qR_nsT.png) </div> 4. 設成 Default <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkYfkKnoT.png) </div> ## 透過 URL 下載 Cloud Images 1. 左側選單選擇 Images -> Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/H1Jaud2oT.png) </div> 2. 透過 URL 下載 OpenSUSE Leap 15.5 的 Cloud Images <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BkxNtdnop.png) > URL 如下 : > `https://download.opensuse.org/repositories/Cloud:/Images:/Leap_15.5/images/openSUSE-Leap-15.5.x86_64-NoCloud.qcow2` </div> 3. 確認下載完成 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SJkPjdhi6.png) </div> ## 新增 Cloud Config Templates ### User Data 1. 點選左側選單 Cloud Config Templates -> Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/S1lWeK2ia.png) </div> 2. 輸入以下資訊 : <div class="indent-title-2"> * Name: `opensuse` ```yaml= #cloud-config package_update: true packages: - qemu-guest-agent write_files: - path: /etc/sysctl.conf permissions: 0644 owner: root content: | net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1 runcmd: - - systemctl - enable - '--now' - qemu-guest-agent.service - yast dns edit nameserver1=172.20.0.37 - timedatectl set-timezone Asia/Taipei - systemctl restart network - sysctl -p ssh_pwauth: true ssh_authorized_keys: - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC2Km26Z03nqLOmoHgd4F1MEApHF2Vdib8sk86SwaxVAqaFXliaC/a6VRFBiQRuog8zYsjg51HMzmXc9zPaUMEbJ7mD23AfqOv+DoQc8KjYhr2bWPz33fqYBAz76XpDi6R8g8XEfWekUi+YV28O3QJOfNT6W8PNPfYVCvXmhVe0QIB9w5wyMUvwOdlpBdcCke6w1Wwg0OSBulJBT+p2qJ1HZBiIUsb7KYLyiwPfmiYakFo+L90DfXJhzuFMYUtOa7zw+zjWy9BDTF6xXlHKhvv4yylPsLl5DfA/aSztpzMTMsrXefGJjCcaAQMueikGRORZ7KDb2QJvj0U2iYw/GFivv3cOpgAxRzIo6pDROpfJAc8Xt59gQeDsRzF3JSY6gXJ+/xgEWSIMffKnF3VRk20zb/m+jWuCnKzj9GH9ribAJ5yWSA7zeWexSd0ZACvvb+ydW9RgnlecdUXarohWXbvH2CK3euxCjFVuMsaKqJvF2c2XfiIm8ZtgzF3WpRhbFOc= rancher@rancher users: - default - name: rancher gecos: rancher groups: users lock_passwd: false sudo: ALL=(ALL) NOPASSWD:ALL plain_text_passwd: 'rancher' shell: /bin/bash ``` > - `package_update`,會先更新系統的套件 > - `packages`,代表要安裝的套件 > - `write_files`,針對特定檔案寫入特定內容,這邊的範例是關 ipv6 > - `runcmd`,系統開機以後要執行的命令,這邊有設定啟動 qemu-guest-agent 服務,並設為開機自動啟動,還有設定 DNS Server 的位置,還有設定時區,特別設定 DNS Server 的原因是因為要可以跟 Rancher 溝通 > - `ssh_authorized_keys`,讓跳板機可以免密碼登入使用這個 Cloud init config 做出來的 VM > - `users`,新增使用者,並設定使用者的群組、sudo 權限和密碼。 確認資訊輸入正確後,點選 Create ![image](https://hackmd.io/_uploads/ByChxtnja.png) </div> ### Network Data #### Static ```yaml= network: version: 1 config: - type: physical name: eth0 subnets: - type: static address: 172.20.0.43/24 gateway: 172.20.0.253 - type: nameserver address: - 172.20.0.40 ``` #### DHCP ```yaml= network: version: 1 config: - type: physical name: eth0 subnets: - type: dhcp ``` ## 建立 VM Network 1. 點選左側選單 Networks -> VM Networks -> Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryzy3Fajp.png) </div> 2. 編輯以下設定資訊 <div class="indent-title-1"> - Name: `vlan` - Vlan ID: `100` - Cluster Netwrok: `mgmt` <div class="indent-title-2"> 確認沒問題後,點選 Create ![image](https://hackmd.io/_uploads/HJzJ6F6o6.png) </div> </div> 3. 確認是否建立成功 <div class="indent-title-2"> State 和 Route Connectivity 的狀態都要顯示 Active ![image](https://hackmd.io/_uploads/Hkm2ptTja.png) </div> ## 將其他節點加入 Harvester 叢集 ### 1. 將燒有 Harvester ISO 的 USB 可開機裝置插入伺服器,並使用 USB 開機。 ### 2. 安裝步驟 <div class="indent-title-1"> 2.1. 使用 USB 開機,並透過選擇 Harvester Installer 選項啟動伺服器。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rJiMSL2iT.png) > 使用預設選項,直接按 Enter 按鍵。 </div> </div> <div class="indent-title-1"> 2.2. 選擇加入一個已經存在的 Harvester Cluster <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/Sk1v9Khip.png) > 選擇 `Join an existing Harvester cluster` 後,按 Enter 按鍵。 </div> </div> <div class="indent-title-1"> 2.3. 選擇要安裝的 Harvester 系統碟和要儲存虛擬機器資料的資料碟。 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJwppt2sT.png) > 按 Tab 鍵可展開下拉式選單,按 Enter 鍵儲存設定值。 </div> </div> <div class="indent-title-1"> 2.4. 設定主機的 Hostname <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/Hypj6F2jT.png) > 輸入 `h2` </div> </div> <div class="indent-title-1"> 2.5. 設定網路 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ByffCY2j6.png) > 網路卡的部分,按 Tab 展開下拉式選單,按空白鍵選擇網路卡,確定之後按 Enter 鍵 > IPv4 Address 欄位,輸入 : `172.20.0.35/24` > Gateway 欄位,輸入 : `172.20.0.254` </div> </div> <div class="indent-title-1"> 2.6. 設定 DNS Server <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkCXCtnsp.png) > DNS Server 欄位 : `172.20.0.37` </div> </div> <div class="indent-title-1"> 2.7. 設定 管理 IP Address <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SymvRY2op.png) > Management address 欄位 : `172.20.0.36` </div> </div> <div class="indent-title-1"> 2.8. 設定 Cluster Token <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryxCdvno6.png) > Cluster token 欄位 : `lab` > Cluster token 用於將其他節點新增至 Harvester 叢集。 </div> </div> <div class="indent-title-1"> 2.9. 設定使用者密碼 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkGStD3ja.png) > 預設的使用者是 `rancher`。 </div> </div> <div class="indent-title-1"> 2.10. 設定 NTP Server <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryY4ec3ia.png) > NTP Server 欄位 : `time.google.com`。 </div> </div> <div class="indent-title-1"> 2.11. 設定 HTTP Proxy Server ( 此步驟不一定要設定,取決於當下的環境 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HyJ-qDhsT.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.12. 匯入 SSH Keys ( 此步驟不一定要設定 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rkjwqPnia.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.13. 設定 Harvester 設定檔自訂主機 ( 此步驟不一定要設定 ) <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJbMjwhjp.png) > 如果不設定就空白,直接按 Enter 鍵。 </div> </div> <div class="indent-title-1"> 2.14. 查看並確認安裝選項 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/S1_Ue9ho6.png) > 確認安裝選項沒問題後,按 Enter 鍵,Harvester 將會安裝到主機上。 </div> </div> <div class="indent-title-1"> 2.15. 安裝完成後,節點將重新啟動,以下是啟動完成畫面 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/HJVvH5nop.png) </div> </div> <div class="indent-title-1"> 2.16. 打開 Harvester 網站,檢查 Node 是否變 2 台 <div class="indent-title-2"> 點選左側選單 Hosts ![image](https://hackmd.io/_uploads/S112rcniT.png) > 使用者預設是 `admin` </div> </div> ## 與 Rancher 整合 ### PreRequest <div class="indent-title-1"> Harvester v1.2.1 肚子裡面的 Rancher 無法啟動虛擬化管理,所以需額外再安裝並啟動 Rancher Server 2.7.9,或是在 Harvester 啟動 [rancher-vcluster](https://docs.harvesterhci.io/v1.2/advanced/addons/rancher-vcluster) (正在開發的功能)。 > Rancher 的安裝請參考我的另一篇筆記 [RKE2 & Rancher Prime Installation](https://hackmd.io/@QI-AN/RKE2-Rancher-Prime-Installation) </div> ### Rancher 啟動 Virtualization management 1. 打開虛擬化管理介面 <div class="indent-title-2"> 點選左側選單 Virtualization Management ![image](https://hackmd.io/_uploads/ryT5uc2jT.png) </div> 2. Import Harvester Cluster <div class="indent-title-2"> 點選 Import Existing ![image](https://hackmd.io/_uploads/Skog953oT.png) </div> 3. 填入叢集資訊 <div class="indent-title-2"> - Cluster Name: `harvester` ![image](https://hackmd.io/_uploads/S1nw553j6.png) </div> 4. 填入叢集資訊 <div class="indent-title-2"> - Cluster Name: `harvester` ![image](https://hackmd.io/_uploads/S1nw553j6.png) </div> 5. 複製讓 Harvester 與 Rancher 註冊的 URL <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/Hkugjc3o6.png) </div> 6. 回到 Harvester 的網站,與 Rancher 註冊 (1/2) <div class="indent-title-2"> 點選左側選單 Settings -> 找到 cluster-registration-url -> 點選 Edit Setting ![image](https://hackmd.io/_uploads/B1j3T9hjT.png) </div> 7. 回到 Harvester 的網站,與 Rancher 註冊 (2/2) <div class="indent-title-2"> 將註冊 URL 貼上 -> 點選 Save ![image](https://hackmd.io/_uploads/SkIOAchj6.png) </div> 8. 到 Rancher UI 確認 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SkrS1j2sp.png) </div> ### Creating an K3s Kubernetes Cluster 1. 在 Home Page 點選 Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/SJc2yi2j6.png) </div> 2. Node Driver 選擇 Harvester <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJuJgo3op.png) </div> 3. 建立 Cloud Credential <div class="indent-title-2"> - Credential Name: `harvester` - Imported Harvester Cluster 選擇 harvester - 點選 Continue ![image](https://hackmd.io/_uploads/HkRIwo3ip.png) </div> 4. 編輯 Machine Pools <div class="indent-title-1"> <div class="indent-title-1"> :::info VM 必須要能透過 DNS Server 解析 Rancher 的 FQDN,否則 K3S 將無法建立。 ::: </div> - Cluster Name: `bobo` - CPU: `4` - Memory: `8` - Namespace: `default` - SSH User: `Opensuse` - Volumes: - Image Volume: `openSUSE-Leap-15.5.x86_64-NoCloud.qcow2` - Disk: `100` <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJ5aIFasa.png) </div> - Networks: - Network Name: `default/vlan (vlanId=100)` - 點選 `Show Advanced` 按鈕 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/H1Jzx5TjT.png) </div> - User Data: - User Data Template: `opensuse` <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/BJwCJ9Tsp.png) </div> </div> 5. 編輯 Cluster Configuration <div class="indent-title-1"> - 選擇 Kubernetes 版本 : k3s v1.26.13+k3s2 - 點選 Create <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/rJKV-qpjp.png) </div> </div> 6. 檢查 K3S 是否建立成功 <div class="indent-title-2"> 點選 Provisioning Log ![image](https://hackmd.io/_uploads/S1ARl6pj6.png) > 要 Troubleshooting 的話,可以 ssh 連線到 VM 中,看以下兩個檔案 : > - `/var/log/cloud-init.log`。 > - `/var/log/cloud-init-output.log`,這檔案裡面紀錄 cloud init 命令執行的結果,包含透過 Rancher 安裝 K3S 的過程都會記在這個檔案中。 </div> ### K3s node Scale up to 2 1. Scale up node <div class="indent-title-2"> 點選 Machine Pools -> + ![image](https://hackmd.io/_uploads/BJdI7ppoa.png) </div> 2. 檢查是否符合預期 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/ryfIV6Ti6.png) </div> ### K3s node Scale down to 1 1. Scale down node <div class="indent-title-2"> 點選 Machine Pools -> - ![image](https://hackmd.io/_uploads/SyS1BT6sp.png) </div> 2. 檢查是否符合預期 <div class="indent-title-2"> ![image](https://hackmd.io/_uploads/S1gCBapsa.png) </div> ## Add Additional Disks 1. 再新增一顆硬碟後,要先 Format 成 ext4 檔案系統再重新開機, Harvester 才認的到 1. Go to the **Hosts** page. 1. On the node you want to modify, click **⋮** > **Edit Config**. 1. Select the **Storage** tab and click **Add Disk**. 1. Select an additional raw block device to add as an additional data volume. 1. The `Force Formatted` option is required if the block device has never been force-formatted. 1. Last, you can click **⋮** > **Edit Config** again to check the newly added disk. ## Resize Disk (虛擬化環境) 1. 先在虛擬化那層擴硬碟空間 2. SSH 連線進那台 node,並切換成 root 使用者 3. Resize Partitaion 大小 <div class="indent-title-2"> ``` # 確認 /var/lib/harvester/defaultdisk 在哪顆硬碟 $ df -h /var/lib/harvester/defaultdisk Filesystem Size Used Avail Use% Mounted on /dev/sda6 330G 30G 283G 10% /var/lib/harvester/defaultdisk $ fdisk /dev/sda Command (m for help): p Disk /dev/sda: 712 GiB, 764504178688 bytes, 1493172224 sectors Disk model: QEMU HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: C1C6588D-E0EB-42EB-A68B-3676181AED1E Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 106495 102400 50M Linux filesystem /dev/sda3 106496 16883711 16777216 8G Linux filesystem /dev/sda4 16883712 48340991 31457280 15G Linux filesystem /dev/sda5 48340992 369205247 320864256 153G Linux filesystem /dev/sda6 369205248 1073739775 704534528 335.9G Linux filesystem Command (m for help): d Partition number (1-6, default 6): Partition 6 has been deleted. Command (m for help): n Partition number (6-128, default 6): First sector (369205248-1493172190, default 369205248): Last sector, +/-sectors or +/-size{K,M,G,T,P} (369205248-1493172190, default 1493172190): Created a new partition 6 of type 'Linux filesystem' and of size 535.9 GiB. Partition #6 contains a ext4 signature. Do you want to remove the signature? [Y]es/[N]o: N Command (m for help): p Disk /dev/sda: 712 GiB, 764504178688 bytes, 1493172224 sectors Disk model: QEMU HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: gpt Disk identifier: C1C6588D-E0EB-42EB-A68B-3676181AED1E Device Start End Sectors Size Type /dev/sda1 2048 4095 2048 1M BIOS boot /dev/sda2 4096 106495 102400 50M Linux filesystem /dev/sda3 106496 16883711 16777216 8G Linux filesystem /dev/sda4 16883712 48340991 31457280 15G Linux filesystem /dev/sda5 48340992 369205247 320864256 153G Linux filesystem /dev/sda6 369205248 1493172190 1123966943 535.9G Linux filesystem Command (m for help): w The partition table has been altered. Syncing disks. ``` </div> 4. 執行以下命令 Resize Longhorn 的 Filesystem <div class="indent-title-2"> ```! $ resize2fs -p /dev/sda6 $ df -h /var/lib/harvester/defaultdisk Filesystem Size Used Avail Use% Mounted on /dev/sda6 527G 30G 472G 6% /var/lib/harvester/defaultdisk ``` </div> 4. 再進 Longhorn UI 看就會發現空間擴出來了 ## Stop VM with cli ```bash! # 1. SSH into harvester node $ ssh rancher@x.x.x.x # 2. Get VVirtual Machine Instance $ kubectl get vmi NAME AGE PHASE IP NODENAME READY harbor 12m Running hh False hehe 6m41s Running 10.52.0.180 hh True k3-pool1-2d0bd15b-4fv96 14h Running 172.20.0.42 hh True rancher 14h Running 172.20.0.41 hh True # 3. Stop VM $ virtctl stop harbor VM harbor was scheduled to stop ``` ## 參考文章 - [Hardware and Network Requirements - Harvester Docs](https://docs.harvesterhci.io/v1.2/install/requirements) - [USB Installation - Harvester Docs](https://docs.harvesterhci.io/v1.2/install/usb-install)