Skip to content

antony@notes:~/rancher$ cat "Longhorn-Introduction.md"

Longhorn Introduction

2023-07-21· rancher ·Longhorn

Preface

本篇文章會介紹,甚麼是 Longhorn,它如何運作,如何安裝,即實作。

可以透過點擊展開以下目錄,選擇想看的內容,跳轉至特定章節

:::warning

:::spoiler 文章目錄

[TOC]

:::

What is Longhorn?

Longhorn 是 Kubernetes 的一個輕量級、可靠且易於使用的分散式區塊儲存系統。

本質上,它將普通硬體和雲端儲存空間轉變為可靠且分散式的塊儲存解決方案,為 Kubernetes 提供 software-defined storage (軟體定義儲存 [SDS])。

在 Kubernetes 環境中使用 Longhorn 的特性和優點

  1. 安裝和操作方便

Longhorn 可以透過一個指令在任何 Kubernetes 叢集上進行安裝。

它提供了圖形使用者介面,創建和連接 volumes、進行快照的管理,以及設置備份。

  1. 輕量化且可靠

Longhorn 的佔用空間很小,不需要任何額外的服務來運行,因此是一個輕量級的解決方案。它通過在叢集中的不同節點之間同步複製 volumes 來確保高可用性。如果一個節點或硬碟故障,Longhorn 會自動重新複製數據到其他節點,保護數據的安全性。

  1. Volumes 的災難復原

Longhorn 支援跨叢集災難恢復 volumes,使得在災難發生時可以快速啟動備援的 volumes。

  1. Incremental Snapshots and Backups

Longhorn 允許您對 volumes 進行增量式快照拍攝,並將其備份到第二個儲存空間。這種方法優化了儲存使用情況,加快了備份和恢復操作的速度。

  1. ReadWriteMany (RWX) Volumes Support

從 Longhorn 1.1.0 版本開始,Longhorn 支援 ReadWriteMany (RWX) volumes,允許多個節點同時讀寫一個 volumes。

  1. Active Monitoring and Alerts

Longhorn 透過與 Prometheus 的整合提供主動監控和警示功能。

  1. Built-In Data Locality and Affinity Features

Longhorn 支援資料本地化,嘗試保持資料和 Application 在同一節點上,以提高性能。

它還支援 volume 和節點的 affinity/anti-affinity 策略,用於進階的 volume 排程。

Longhorn 的運作架構

Longhorn Manager

  • 一個 DaemonSet in Kubernetes
  • Longhorn Manager 在 Kubernetes 叢集的每個節點上運行。
  • 它負責在 Kubernetes 叢集中創建和管理 Volume,並處理來自使用者介面或 Kubernetes 的 volume plugins 的 API 呼叫。

Longhorn Engine

  • 一個 Linux Process
  • Longhorn Engine 是負責讀寫資料到儲存後端。
  • 每個 Longhorn volume 都有對應的 Longhorn Engine。
  • Longhorn Engine 進行快照拍攝、建立備份,並在不同節點之間複製資料以確保高可用性。

Longhorn UI

  • Longhorn 使用者介面(UI)是一個圖形使用者介面,讓使用者能夠管理 Volumes、進行快照拍攝、設置備份,並監控儲存系統的狀態。

Longhorn CSI (Container Storage Interface) Driver

  • CSI Driver 允許 Kubernetes 將 Longhorn 作為其儲存提供者。
  • 它將 Kubernetes 的 Volume 操作轉換為相應的 Longhorn 操作,例如
    • 創建 Volume
    • 將 Volume 附加/分離到節點
    • 以及將 Volume 掛載/卸載到 Pod

Longhorn Instance Manager

  • 有兩種類型的 Instance Manager,
    • 一個用於管理 Longhorn Engine instances,
    • 另一個用於管理 Longhorn Replica instances。
  • 叢集中的每個節點都運行一個 Instance Manager pod,每種類型一個。

Longhorn Replicas

  • 這些是由 Longhorn Engine 在不同節點上同步創建的資料副本,用於實現冗餘和高可用性。

How Longhorn Operates

在 Longhorn 中,當您在 Kubernetes 中創建一個 Persistent Volume Claim(PVC) 時,

  1. Longhorn CSI driver 會將此請求傳達給 Longhorn manager。
  2. Longhorn manager 會提供一個新的 Longhorn Volime 和對應的 Longhorn Engine。

Longhorn Engine 負責存儲 Volume 的實際資料,並管理將資料複製到分布在不同節點上的 Longhorn Replicas。這種複製確保您的資料即使節點發生故障,仍然安全可用。

此外,當您進行快照時,Longhorn Engine 會在不影響運行 Application 的情況下創建資料的某一時間點副本。這些快照可以用於備份,這些備份是增量的,可以存儲在像 AWS S3 或 NFS 伺服器這樣的第二個儲存空間中。