內容來源於官方 Longhorn 1.1.2
英文技術手冊。
系列
- Longhorn 是什麼?
- Longhorn 雲原生容器分散式儲存 - 設計架構和概念
- Longhorn 雲原生容器分散式儲存 - 部署篇
- Longhorn 雲原生容器分散式儲存 - 券和節點
- Longhorn 雲原生容器分散式儲存 - K8S 資源配置示例
- Longhorn 雲原生容器分散式儲存 - 監控(Prometheus)
- Longhorn 雲原生容器分散式儲存 - 備份與恢復
- Longhorn 雲原生容器分散式儲存 - 高可用
- Longhorn 雲原生容器分散式儲存 - 支援 ReadWriteMany (RWX) 工作負載
- Longhorn 雲原生容器分散式儲存 - 定製部署預設設定
- Longhorn雲原生容器分散式儲存 - Air Gap 安裝
目前,您可以使用 Longhorn UI
操作 Longhorn
。同時,您可以使用 Python
訪問 Longhorn API
,如下所示。
-
獲取
Longhorn API
端點與
Longhorn
通訊的一種方式是通過longhorn-frontend
service。如果您在安裝
Longhorn
的同一叢集中執行自動化/指令碼(automation/scripting
)工具,請連線到端點http://longhorn-frontend.longhorn-system/v1
如果您在本地機器上執行自動化/指令碼(
automation/scripting
)工具,請使用kubectl port-forward
將longhorn-frontend
service
轉發到localhost
:kubectl port-forward services/longhorn-frontend 8080:http -n longhorn-system
並連線到端點
http://localhost:8080/v1
-
使用
Python Client
將 longhorn.py 檔案(包含
Python client
)匯入到以下Python
指令碼中,並從API
端點建立一個client
:https://github.com/longhorn/longhorn-tests/blob/master/manager/integration/tests/longhorn.py
import longhorn # If automation/scripting tool is inside the same cluster in which Longhorn is installed longhorn_url = 'http://longhorn-frontend.longhorn-system/v1' # If forwarding `longhorn-frontend` service to localhost longhorn_url = 'http://localhost:8080/v1' client = longhorn.Client(url=longhorn_url) # Volume operations # List all volumes volumes = client.list_volume() # Get volume by NAME/ID testvol1 = client.by_id_volume(id="testvol1") # Attach TESTVOL1 testvol1 = testvol1.attach(hostId="worker-1") # Detach TESTVOL1 testvol1.detach() # Create a snapshot of TESTVOL1 with NAME snapshot1 = testvol1.snapshotCreate(name="snapshot1") # Create a backup from a snapshot NAME testvol1.snapshotBackup(name=snapshot1.name) # Update the number of replicas of TESTVOL1 testvol1.updateReplicaCount(replicaCount=2) # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests # Node operations # List all nodes nodes = client.list_node() # Get node by NAME/ID node1 = client.by_id_node(id="worker-1") # Disable scheduling for NODE1 client.update(node1, allowScheduling=False) # Enable scheduling for NODE1 client.update(node1, allowScheduling=True) # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests # Setting operations # List all settings settings = client.list_setting() # Get setting by NAME/ID backupTargetsetting = client.by_id_setting(id="backup-target") # Update a setting backupTargetsetting = client.update(backupTargetsetting, value="s3://backupbucket@us-east-1/") # Find more examples in Longhorn integration tests https://github.com/longhorn/longhorn-tests/tree/master/manager/integration/tests
公眾號:黑客下午茶