內容來源於官方 Longhorn 1.1.2
英文技術手冊。
系列
安裝
Longhorn
可以通過多種方式安裝在 Kubernetes
叢集上:
Rancher catalog app
kubectl
Helm
安裝要求
安裝 Longhorn
的 Kubernetes
叢集中的每個節點都必須滿足以下要求:
- 與
Kubernetes
相容的容器執行時(Docker v1.13+
、containerd v1.3.7+
等) - Kubernetes v1.16+.
- 推薦 Kubernetes v1.17+
open-iscsi
已安裝,並且iscsid
守護程式正在所有節點上執行。這是必要的,因為Longhorn
依賴主機上的iscsiadm
為Kubernetes
提供持久卷。RWX support
要求每個節點都安裝NFSv4 client
。- 主機檔案系統支援
file extents
功能來儲存資料。目前我們支援:ext4
XFS
curl
,findmnt
,grep
,awk
,blkid
,lsblk
必須安裝。- Mount propagation 必須啟用。
Longhorn workloads
必須能夠以 root
身份執行才能正確部署和操作 Longhorn
。
作業系統(OS
)/發行版(Distro
)特定配置
- Google Kubernetes Engine (GKE)
Longhorn
需要一些額外的設定才能正常執行。 - K3s clusters 需要一些額外的設定。
- RKE clusters with CoreOS 需要
csi-on-rke-and-coreos
使用 Environment Check Script
我們編寫了一個指令碼來幫助您收集有關這些因素的足夠資訊。
注意在執行 env check
指令碼之前,可能需要在本地安裝 jq
。
執行指令碼:
curl -sSfL https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/scripts/environment_check.sh | bash
結果示例:
daemonset.apps/longhorn-environment-check created
waiting for pods to become ready (0/3)
all pods ready (3/3)
MountPropagation is enabled!
cleaning up...
daemonset.apps "longhorn-environment-check" deleted
clean up complete
Pod 安全策略
從 v1.0.2
開始,Longhorn
附帶了預設的 Pod
安全策略,該策略將為 Longhorn
提供必要的許可權以使其能夠正常執行。
Longhorn
無需特殊配置即可在啟用了 Pod
安全策略的叢集上正常工作。
注意 Mount Propagation
如果您的 Kubernetes
叢集是由 Rancher v2.0.7+
或更高版本提供的,則預設啟用 MountPropagation
功能。
如果 MountPropagation
被禁用,Base Image
功能將被禁用。
安裝 open-iscsi
用於安裝 open-iscsi
的命令因 Linux 發行版而異。
對於 GKE
,我們建議使用 Ubuntu
作為 guest OS image
,因為它已經包含 open-iscsi
。
您可能需要編輯 cluster security group(叢集安全組)
以允許 SSH
訪問。
對於 SUSE
和 openSUSE
,請使用以下命令:
zypper install open-iscsi
對於 Debian
和 Ubuntu
,請使用以下命令:
apt-get install open-iscsi
對於帶有 EKS Kubernetes Worker AMI with AmazonLinux2 image
的 RHEL
、CentOS
和 EKS
,請使用以下命令:
yum install iscsi-initiator-utils
我們還提供了一個 iscsi
安裝程式,使使用者可以更輕鬆地自動安裝 open-iscsi
:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/deploy/prerequisite/longhorn-iscsi-installation.yaml
部署完成後,執行以下命令來檢查安裝程式的 pod
狀態:
kubectl get pod | grep longhorn-iscsi-installation
longhorn-iscsi-installation-49hd7 1/1 Running 0 21m
longhorn-iscsi-installation-pzb7r 1/1 Running 0 39m
也可以通過以下命令檢視日誌,檢視安裝結果:
kubectl logs longhorn-iscsi-installation-pzb7r -c iscsi-installation
...
Installed:
iscsi-initiator-utils.x86_64 0:6.2.0.874-7.amzn2
Dependency Installed:
iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-7.amzn2
Complete!
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
iscsi install successfully
安裝 NFSv4 client
用於安裝 NFSv4 client
的命令因 Linux
發行版而異。
對於 Debian
和 Ubuntu
,請使用以下命令:
apt-get install nfs-common
對於帶有 EKS Kubernetes Worker AMI with AmazonLinux2 image
的 RHEL
、CentOS
和 EKS
,請使用以下命令:
yum install nfs-utils
我們還提供了一個 nfs
安裝程式,使使用者可以更輕鬆地自動安裝 nfs-client
:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/deploy/prerequisite/longhorn-nfs-installation.yaml
部署完成後,執行以下命令來檢查安裝程式的 pod
狀態:
kubectl get pod | grep longhorn-nfs-installation
NAME READY STATUS RESTARTS AGE
longhorn-nfs-installation-t2v9v 1/1 Running 0 143m
longhorn-nfs-installation-7nphm 1/1 Running 0 143m
也可以通過以下命令檢視日誌,檢視安裝結果:
kubectl logs longhorn-nfs-installation-t2v9v -c nfs-installation
...
nfs install successfully
檢查 Kubernetes 版本
使用以下命令檢查您的 Kubernetes
伺服器版本
kubectl version
結果:
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.3", GitCommit:"1e11e4a2108024935ecfcb2912226cedeafd99df", GitTreeState:"clean", BuildDate:"2020-10-14T12:50:19Z", GoVersion:"go1.15.2", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"17", GitVersion:"v1.17.4", GitCommit:"8d8aa39598534325ad77120c120a22b3a990b5ea", GitTreeState:"clean", BuildDate:"2020-03-12T20:55:23Z", GoVersion:"go1.13.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version
應該是 v1.16
或更高版本。
作為 Rancher Catalog App 安裝
通過 Rancher catalog
安裝 Longhorn
的好處之一是 Rancher
為 Longhorn UI
提供身份驗證。
如果有新版本的 Longhorn
可用,您將在 Catalog Apps
螢幕上看到 Upgrade Available
標誌。
您可以單擊 Upgrade
按鈕升級 Longhorn manager
。
安裝
- 可選:我們建議為
Longhorn
建立一個新專案,例如Storage
。 - 導航到您將安裝
Longhorn
的cluster
和project
。
- 導航到
Catalog Apps
螢幕。
- 在
catalog
中找到Longhorn
專案並單擊它。
- 可選:自定義預設設定。
- 單擊 Launch。
Longhorn
將安裝在longhorn-system
名稱空間中。
現在Longhorn
已經安裝好了。
- 單擊
index.html
連結導航到Longhorn
儀表板。
成功安裝 Longhorn
後,您可以通過導航到 Catalog Apps
螢幕來訪問 Longhorn UI
。
使用 Kubectl 安裝
安裝 Longhorn
使用以下命令在任何 Kubernetes 叢集上安裝 Longhorn:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/deploy/longhorn.yaml
監視安裝進度的一種方法是觀察在
longhorn-system
名稱空間中建立的pod
:kubectl get pods \
--namespace longhorn-system \
--watch
檢查部署是否成功:
$ kubectl -n longhorn-system get pod
NAME READY STATUS RESTARTS AGE
csi-attacher-6fdc77c485-8wlpg 1/1 Running 0 9d
csi-attacher-6fdc77c485-psqlr 1/1 Running 0 9d
csi-attacher-6fdc77c485-wkn69 1/1 Running 0 9d
csi-provisioner-78f7db7d6d-rj9pr 1/1 Running 0 9d
csi-provisioner-78f7db7d6d-sgm6w 1/1 Running 0 9d
csi-provisioner-78f7db7d6d-vnjww 1/1 Running 0 9d
engine-image-ei-6e2b0e32-2p9nk 1/1 Running 0 9d
engine-image-ei-6e2b0e32-s8ggt 1/1 Running 0 9d
engine-image-ei-6e2b0e32-wgkj5 1/1 Running 0 9d
longhorn-csi-plugin-g8r4b 2/2 Running 0 9d
longhorn-csi-plugin-kbxrl 2/2 Running 0 9d
longhorn-csi-plugin-wv6sb 2/2 Running 0 9d
longhorn-driver-deployer-788984b49c-zzk7b 1/1 Running 0 9d
longhorn-manager-nr5rs 1/1 Running 0 9d
longhorn-manager-rd4k5 1/1 Running 0 9d
longhorn-manager-snb9t 1/1 Running 0 9d
longhorn-ui-67b9b6887f-n7x9q 1/1 Running 0 9d
要啟用對
Longhorn UI
的訪問,您需要設定一個Ingress controller
。 預設情況下不啟用對Longhorn UI
的身份驗證。
已部署資源列表
以下專案將部署到 Kubernetes
:
Namespace: longhorn-system
所有 Longhorn bits
都將作用於這個名稱空間。
ServiceAccount: longhorn-service-account
Service account
是在 longhorn-system
名稱空間中建立的。
ClusterRole: longhorn-role
此角色將有權訪問:
- In apiextension.k8s.io (All verbs)
- customresourcedefinitions
- In core (All verbs)
- pods
- /logs
- events
- persistentVolumes
- persistentVolumeClaims
- /status
- nodes
- proxy/nodes
- secrets
- services
- endpoints
- configMaps
- pods
- In core
- namespaces (get, list)
- In apps (All Verbs)
- daemonsets
- statefulSets
- deployments
- In batch (All Verbs)
- jobs
- cronjobs
- In storage.k8s.io (All verbs)
- storageclasses
- volumeattachments
- csinodes
- csidrivers
- In coordination.k8s.io
- leases
ClusterRoleBinding: longhorn-bind
這將 longhorn-role
連線到 longhorn-system
名稱空間中的 longhorn-service-account
。
CustomResourceDefinitions
將安裝以下 CustomResourceDefinitions
- In longhorn.io
- engines
- replicas
- settings
- volumes
- engineimages
- nodes
- instancemanagers
Kubernetes API 物件
- 一個具有預設設定
config map
longhorn-manager
DaemonSetlonghorn-backend
service 在內部將longhorn-manager DaemonSet
暴露給Kubernetes
longhorn-ui
Deploymentlonghorn-frontend
service 在內部將longhorn-ui
暴露給Kubernetes
longhorn-driver-deployer
部署 CSI driverlonghorn StorageClass
使用 Helm 安裝
安裝 Helm 的注意事項
有關安裝 Helm
的幫助,請參閱官方文件。
如果您使用的是 3.0
版之前的 Helm
版本,則需要使用基於角色的訪問控制 (RBAC) 在 Kubernetes 叢集中安裝 Tiller。
安裝 Longhorn
新增
Longhorn Helm
儲存庫:helm repo add longhorn https://charts.longhorn.io
從儲存庫中獲取最新
charts
:helm repo update
在
longhorn-system
名稱空間中安裝Longhorn
。
要使用Helm 2
安裝Longhorn
,請使用以下命令:helm install longhorn/longhorn --name longhorn --namespace longhorn-system
要使用
Helm 3
安裝Longhorn
,請使用以下命令:kubectl create namespace longhorn-system
helm install longhorn longhorn/longhorn --namespace longhorn-system
要確認部署成功,請執行:
kubectl -n longhorn-system get pod
結果應如下所示:
NAME READY STATUS RESTARTS AGE
compatible-csi-attacher-d9fb48bcf-2rzmb 1/1 Running 0 8m58s
csi-attacher-78bf9b9898-grn2c 1/1 Running 0 32s
csi-attacher-78bf9b9898-lfzvq 1/1 Running 0 8m59s
csi-attacher-78bf9b9898-r64sv 1/1 Running 0 33s
csi-provisioner-8599d5bf97-c8r79 1/1 Running 0 33s
csi-provisioner-8599d5bf97-fc5pz 1/1 Running 0 33s
csi-provisioner-8599d5bf97-p9psl 1/1 Running 0 8m59s
csi-resizer-586665f745-b7p6h 1/1 Running 0 8m59s
csi-resizer-586665f745-kgdxs 1/1 Running 0 33s
csi-resizer-586665f745-vsvvq 1/1 Running 0 33s
engine-image-ei-e10d6bf5-pv2s6 1/1 Running 0 9m30s
instance-manager-e-379373af 1/1 Running 0 8m41s
instance-manager-r-101f13ba 1/1 Running 0 8m40s
longhorn-csi-plugin-7v2dc 4/4 Running 0 8m59s
longhorn-driver-deployer-775897bdf6-k4sfd 1/1 Running 0 10m
longhorn-manager-79xgj 1/1 Running 0 9m50s
longhorn-ui-9fbb5445-httqf 0/1 Running 0 33s
要啟用對
Longhorn UI
的訪問,您需要設定一個Ingress controller
。預設情況下不啟用對Longhorn UI
的身份驗證。
訪問 UI
訪問和身份驗證的先決條件
這些說明假定已安裝 Longhorn
。
如果您安裝了 Longhorn YAML
清單,則需要設定 Ingress controller
以允許外部流量進入叢集,並且預設情況下不會啟用身份驗證。
這適用於 Helm
和 kubectl
安裝。
如果 Longhorn
安裝為 Rancher catalog app
,Rancher
會自動為您建立一個具有訪問控制(rancher-proxy
)的 Ingress controller
。
訪問 Longhorn UI
在您的 Kubernetes
叢集中安裝 Longhorn
後,您可以訪問 UI dashboard
。
獲取
Longhorn
的對外service IP
:kubectl -n longhorn-system get svc
對於
Longhorn v0.8.0
,輸出應如下所示,並且使用longhorn-frontend
的CLUSTER-IP
訪問Longhorn UI
:NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
longhorn-backend ClusterIP 10.20.248.250 <none> 9500/TCP 58m
longhorn-frontend ClusterIP 10.20.245.110 <none> 80/TCP 58m在上面的例子中,
IP
是10.20.245.110
。對於
Longhorn v0.8.0+
,UI service
型別從LoadBalancer
更改為ClusterIP
。在瀏覽器中導航到
longhorn-frontend
的IP
。Longhorn UI
如下所示:
使用基本身份驗證 (nginx) 建立 Ingress
如果您使用 kubectl
或 Helm
在 Kubernetes
叢集上安裝 Longhorn
,則需要建立一個 Ingress
以允許外部流量到達 Longhorn UI
。
預設情況下,kubectl
和 Helm
安裝未啟用身份驗證。在這些步驟中,您將學習如何使用 nginx ingress controller
的 annotations
建立具有基本身份驗證的 Ingress
。
- 建立一個基本的認證檔案
auth
。生成的檔案命名為auth
很重要(實際上 -secret
有一個 keydata.auth
),否則Ingress
返回503
。$ USER=<USERNAME_HERE>; PASSWORD=<PASSWORD_HERE>; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> auth
- 建立一個
secret
:$ kubectl -n longhorn-system create secret generic basic-auth --from-file=auth
- 建立一個 Ingress 清單
longhorn-ingress.yml
:apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# prevent the controller from redirecting (308) to HTTPS
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: longhorn-frontend
port:
number: 80
- 建立 Ingress:
$ kubectl -n longhorn-system apply -f longhorn-ingress.yml
e.g.:
$ USER=foo; PASSWORD=bar; echo "${USER}:$(openssl passwd -stdin -apr1 <<< ${PASSWORD})" >> auth
$ cat auth
foo:$apr1$FnyKCYKb$6IP2C45fZxMcoLwkOwf7k0
$ kubectl -n longhorn-system create secret generic basic-auth --from-file=auth
secret/basic-auth created
$ kubectl -n longhorn-system get secret basic-auth -o yaml
apiVersion: v1
data:
auth: Zm9vOiRhcHIxJEZueUtDWUtiJDZJUDJDNDVmWnhNY29Md2tPd2Y3azAK
kind: Secret
metadata:
creationTimestamp: "2020-05-29T10:10:16Z"
name: basic-auth
namespace: longhorn-system
resourceVersion: "2168509"
selfLink: /api/v1/namespaces/longhorn-system/secrets/basic-auth
uid: 9f66233f-b12f-4204-9c9d-5bcaca794bb7
type: Opaque
$ echo "
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: longhorn-ingress
namespace: longhorn-system
annotations:
# type of authentication
nginx.ingress.kubernetes.io/auth-type: basic
# prevent the controller from redirecting (308) to HTTPS
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
# name of the secret that contains the user/password definitions
nginx.ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropriate context why the authentication is required
nginx.ingress.kubernetes.io/auth-realm: 'Authentication Required '
spec:
rules:
- http:
paths:
- pathType: Prefix
path: "/"
backend:
service:
name: longhorn-frontend
port:
number: 80
" | kubectl -n longhorn-system create -f -
ingress.networking.k8s.io/longhorn-ingress created
$ kubectl -n longhorn-system get ingress
NAME HOSTS ADDRESS PORTS AGE
longhorn-ingress * 45.79.165.114,66.228.45.37,97.107.142.125 80 2m7s
$ curl -v http://97.107.142.125/
* Trying 97.107.142.125...
* TCP_NODELAY set
* Connected to 97.107.142.125 (97.107.142.125) port 80 (#0)
> GET / HTTP/1.1
> Host: 97.107.142.125
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Server: openresty/1.15.8.1
< Date: Fri, 29 May 2020 11:47:33 GMT
< Content-Type: text/html
< Content-Length: 185
< Connection: keep-alive
< WWW-Authenticate: Basic realm="Authentication Required"
<
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>openresty/1.15.8.1</center>
</body>
</html>
* Connection #0 to host 97.107.142.125 left intact
* Closing connection 0
$ curl -v http://97.107.142.125/ -u foo:bar
* Trying 97.107.142.125...
* TCP_NODELAY set
* Connected to 97.107.142.125 (97.107.142.125) port 80 (#0)
* Server auth using Basic with user 'foo'
> GET / HTTP/1.1
> Host: 97.107.142.125
> Authorization: Basic Zm9vOmJhcg==
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 29 May 2020 11:51:27 GMT
< Content-Type: text/html
< Content-Length: 1118
< Last-Modified: Thu, 28 May 2020 00:39:41 GMT
< ETag: "5ecf084d-3fd"
< Cache-Control: max-age=0
<
<!DOCTYPE html>
<html lang="en">
......
AWS EKS Kubernetes
叢集的附加步驟
您將需要建立一個 ELB
(彈性負載均衡器)以將 nginx Ingress controller
公開到 Internet
。可能需要支付額外費用。
根據 nginx ingress controller documentation 建立必須的資源。
按照 ingress-nginx/deploy/#aws 步驟建立
ELB
。
References
https://kubernetes.github.io/ingress-nginx/
升級
在這裡,我們介紹瞭如何從所有以前的版本升級到最新的 Longhorn
。
升級 Longhorn
升級過程通常有兩個步驟:首先將 Longhorn manager
升級到最新版本,然後使用最新的 Longhorn manager
手動將 Longhorn engine
升級到最新版本。
1. 升級 Longhorn manager
- 要從
v1.1.x
升級,請參閱longhorn-manager
。
2. 手動升級 Longhorn Engine
Longhorn Manager
升級後,Longhorn Engine
也需要使用 Longhorn UI
進行升級。
3. 自動升級 Longhorn Engine
從 Longhorn v1.1.1
開始,我們提供了一個選項來幫助您自動升級引擎。
Note:
Longhorn v1.1.0
和v1.1.1
中提供的例項管理器映象v1_20201216
中存在一個錯誤,
該錯誤可能導致具有數百個卷的大叢集中的死鎖(deadlock
)。
在longhorn/issues/2697檢視更多詳細資訊。
Longhorn v1.1.2
附帶一個新的例項管理器映象v1_20210621
,它修復了死鎖,
但卷的引擎(engine
)/副本(replica
)程序不會從舊的例項管理器遷移到新的例項管理器,
直到下一次分離(detached
)/附加(attached
)卷。Longhorn
這樣做是因為我們不想中斷卷的資料平面。如果您在舊例項管理器中遇到死鎖,請按照issues/2697#issuecomment-879374809的恢復步驟操作
升級 Longhorn Manager
從 v1.1.x
升級
我們只支援從 v1.1.x
升級到 v1.1.2
。 其他版本請先升級到 v1.1.x
。
支援從 v1.1.x
到 v1.1.2
的 Engine
實時升級。
對於 Longhorn
作為 Rancher app
安裝時的 airgap
升級,您需要修改映象名稱並刪除 registry URL
部分。
例如,Longhorn
images 部分中的映象 registry.example.com/longhorn/longhorn-manager:v1.1.2
更改為 longhorn/longhorn-manager:v1.1.2
。
準備升級
如果 Longhorn
是使用 Helm Chart
安裝的,或者是作為 Rancher catalog app
安裝的,
請檢查以確保預設 StorageClass
中的引數未更改。更改預設 StorageClass
的引數可能會導致 chart
升級失敗。
如果要重新配置 StorageClass
中的引數,可以複製預設 StorageClass
的配置以建立另一個 StorageClass
。
The current default StorageClass has the following parameters:
parameters:
numberOfReplicas: <user specified replica count, 3 by default>
staleReplicaTimeout: "30"
fromBackup: ""
baseImage: ""
升級
先決條件: 始終在升級前備份卷。如果出現任何問題,您可以使用備份恢復卷。
要使用 kubectl 升級,請執行以下命令:
kubectl apply -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/deploy/longhorn.yaml
要使用 Helm 升級,請執行以下命令:
helm upgrade longhorn ./longhorn/chart
在 Rancher 2.1
或更新版本管理的 Kubernetes
叢集上,升級 catalog app
longhorn-system
的步驟與安裝步驟類似。
然後等待所有 pod
開始執行並且 Longhorn UI
工作。 例如:
$ kubectl -n longhorn-system get pod
NAME READY STATUS RESTARTS AGE
csi-attacher-78bf9b9898-mb7jt 1/1 Running 1 3m11s
csi-attacher-78bf9b9898-n2224 1/1 Running 1 3m11s
csi-attacher-78bf9b9898-rhv6m 1/1 Running 1 3m11s
csi-provisioner-8599d5bf97-dr5n4 1/1 Running 1 2m58s
csi-provisioner-8599d5bf97-drzn9 1/1 Running 1 2m58s
csi-provisioner-8599d5bf97-rz5fj 1/1 Running 1 2m58s
csi-resizer-586665f745-5bkcm 1/1 Running 0 2m49s
csi-resizer-586665f745-vgqx8 1/1 Running 0 2m49s
csi-resizer-586665f745-wdvdg 1/1 Running 0 2m49s
engine-image-ei-62c02f63-bjfkp 1/1 Running 0 14m
engine-image-ei-62c02f63-nk2jr 1/1 Running 0 14m
engine-image-ei-62c02f63-pjtgg 1/1 Running 0 14m
engine-image-ei-ac045a0d-9bbb8 1/1 Running 0 3m46s
engine-image-ei-ac045a0d-cqvv2 1/1 Running 0 3m46s
engine-image-ei-ac045a0d-wzmhv 1/1 Running 0 3m46s
instance-manager-e-4deb2a16 1/1 Running 0 3m23s
instance-manager-e-5526b121 1/1 Running 0 3m28s
instance-manager-e-eff765b6 1/1 Running 0 2m59s
instance-manager-r-3b70b0db 1/1 Running 0 3m27s
instance-manager-r-4f7d629a 1/1 Running 0 3m22s
instance-manager-r-bbcf4f17 1/1 Running 0 2m58s
longhorn-csi-plugin-bkgjj 2/2 Running 0 2m39s
longhorn-csi-plugin-tjhhq 2/2 Running 0 2m39s
longhorn-csi-plugin-zslp6 2/2 Running 0 2m39s
longhorn-driver-deployer-75b6bf4d6d-d4hcv 1/1 Running 0 3m57s
longhorn-manager-4j77v 1/1 Running 0 3m53s
longhorn-manager-cwm5z 1/1 Running 0 3m50s
longhorn-manager-w7scb 1/1 Running 0 3m50s
longhorn-ui-8fcd9fdd-qpknp 1/1 Running 0 3m56s
升級後
為避免現有卷崩潰,以及從已棄用的設定 Guaranteed Engine CPU
切換
到 the new instance manager CPU reservation mechanism(預留機制)
,
Longhorn
將在升級期間根據已棄用的設定值從每個節點自動設定 Engine Manager CPU Request
和 Replica Manager CPU Request
。
然後,新的全域性例項管理器 CPU
設定 Guaranteed Engine Manager CPU
和 Guaranteed Replica Manager CPU
將不會生效。
您可能需要檢查新機制和設定說明,以檢視是否需要進行任何調整。
故障排除
Error: "longhorn" is invalid: provisioner: Forbidden: updates to provisioner are forbidden.
這意味著對預設
storageClass
進行了一些修改,您需要在升級前清理舊的。要清理已棄用的
StorageClass
,請執行以下命令:kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/examples/storageclass.yaml
手動升級 Longhorn Engine
在本節中,您將學習如何從 Longhorn UI
手動升級 Longhorn Engine
。
先決條件
在升級 Longhorn engine
映象之前,請務必進行備份。
在升級 Longhorn engine
之前升級 Longhorn manager
。
Note:
Longhorn v1.1.0
和v1.1.1
中提供的例項管理器映象v1_20201216
中存在一個錯誤,
該錯誤可能導致具有數百個卷的大叢集中的死鎖(deadlock
)。
在longhorn/issues/2697檢視更多詳細資訊。
Longhorn v1.1.2
附帶一個新的例項管理器映象v1_20210621
,它修復了死鎖,
但卷的引擎/副本(engine/replica
)程序不會從舊的例項管理器遷移到新的例項管理器,
直到下一次分離/附加(detached/attached
)卷。Longhorn
這樣做是因為我們不想中斷卷的資料平面。為了減少引擎/副本(
engine/replica
)程序仍在舊例項管理器中時發生死鎖的機會,您應該小批量升級卷的引擎,例如,一次升級2
或3
個卷。
離線升級
如果無法進行實時升級,或者卷處於降級狀態,請執行以下步驟:
- 按照
相關 workloads 的 detach procedure
進行。 - 使用批量選擇選擇所有卷。單擊批量操作按鈕 Upgrade Engine,在列表中選擇可用的
engine
映象。這是此版本管理器附帶的預設引擎。 - 恢復所有
workloads
。任何不屬於Kubernetes workload
的卷都必須從Longhorn UI
附加。
實時升級
從 v1.1.x
升級到 v1.1.2
支援實時升級。
iSCSI
前端不支援實時升級。
實時升級應該只對健康的捲進行。
- 選擇要升級的卷。
- 單擊下拉選單中的
Upgrade Engine
。 - 選擇要升級到的
engine
映象。- 通常它是列表中唯一的
engine
映象,因為UI
從列表中排除當前映象。
- 通常它是列表中唯一的
- 單擊
OK
。
在實時升級期間,使用者會暫時看到雙倍數量的副本(replicas
)。
升級完成後,使用者應該看到與之前相同數量的副本(replicas
),並且應該更新卷的 Engine Image
欄位。
請注意,實時升級後,Rancher
或 Kubernetes
仍會顯示 engine
的舊版本映象和副本(replicas
)的新版本。這是預期的。
如果您在 Volume Detail
頁面中看到新版本的映象列為卷映象,則升級成功。
清理舊映象
完成所有映象的升級後,從 Longhorn UI
中選擇 Settings/Engine Image
。現在您應該能夠刪除非預設映象。
自動升級 Longhorn Engine
從 Longhorn v1.1.1
開始,我們提供了一個選項,可以幫助您在升級 Longhorn manager
後自動將 Longhorn
卷升級到新的預設引擎版本。
此功能減少了升級 Longhorn
時必須做的手動工作量。有一些相關的概念 此功能如下所示:
1. 每個節點限制設定的併發自動引擎升級
這是一個設定,用於控制在升級 Longhorn manager
後,Longhorn
如何自動將卷的引擎升級到新的預設引擎映象。
此設定的值指定允許每個節點同時升級到預設引擎映象的最大引擎數量。如果該值為 0
,則 Longhorn
不會自動將卷的引擎升級到預設版本。
該值越大,引擎升級過程完成得越快。
但是,為該設定提供更大的值會在引擎升級過程中消耗更多節點的 CPU 和記憶體。
我們建議將該值設定為 3
,以便為錯誤留出一些空間,但不要因升級失敗過多而使系統不堪重負。
2. Longhorn 在不同體積條件下的行為。
在以下情況下,假設 concurrent automatic engine upgrade per node limit(併發自動引擎升級每節點限制)
設定大於 0
。
附加捲
如果卷處於附加狀態並且健康,
Longhorn
會自動將卷的引擎實時升級到新的預設引擎映象。分離卷
Longhorn
自動對分離的捲進行離線升級。容災卷
Longhorn
不會自動將disaster recovery volumes
升級到新的預設引擎映象,因為它會觸發災難恢復卷的完全恢復。
完全恢復可能會影響系統中其他正在執行的Longhorn
卷的效能。因此,Longhorn
由您決定何時是手動升級災難恢復卷引擎的好時機(例如,當系統空閒時或在維護期間)。但是,當您啟用容災卷時,它會被啟用然後分離。此時,
Longhorn
會自動對捲進行離線升級,類似於分離卷的情況。
3. 如果升級失敗會怎樣?
如果卷升級引擎失敗,卷 spec
中的引擎映象將保持與卷狀態中的引擎映象不同。Longhorn
將不斷重試升級,直到成功。
如果每個節點無法升級的卷太多(即超過 concurrent automatic engine upgrade per node limit(每個節點的併發自動引擎升級限制)
設定),Longhorn
將停止升級該節點上的卷。
解除安裝 Longhorn
在本節中,您將學習如何解除安裝 Longhorn
。
- 先決條件
- 從 Rancher UI 解除安裝 Longhorn
- 使用 Helm 解除安裝 Longhorn
- 使用 kubectl 解除安裝 Longhorn
- 故障排除
先決條件
為了防止對 Kubernetes
叢集造成損壞,
我們建議刪除所有使用 Longhorn
卷(PersistentVolume
、PersistentVolumeClaim
、StorageClass
、Deployment
、StatefulSet
、DaemonSet
等)的 Kubernetes
工作負載。
從 Rancher UI 解除安裝 Longhorn
從 Rancher UI,導航到 Catalog Apps
選項卡並刪除 Longhorn app
。
使用 Helm 解除安裝 Longhorn
執行此命令:
helm uninstall longhorn -n longhorn-system
使用 kubectl 解除安裝 Longhorn
建立解除安裝
job
以從系統中清除CRDs
並等待成功:kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/uninstall/uninstall.yaml
kubectl get job/longhorn-uninstall -n default -w
示例輸出:
$ kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/uninstall/uninstall.yaml
serviceaccount/longhorn-uninstall-service-account created
clusterrole.rbac.authorization.k8s.io/longhorn-uninstall-role created
clusterrolebinding.rbac.authorization.k8s.io/longhorn-uninstall-bind created
job.batch/longhorn-uninstall created $ kubectl get job/longhorn-uninstall -n default -w
NAME COMPLETIONS DURATION AGE
longhorn-uninstall 0/1 3s 3s
longhorn-uninstall 1/1 20s 20s
^C
刪除剩餘的元件:
kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/deploy/longhorn.yaml
kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v1.1.2/uninstall/uninstall.yaml
Tip: 如果您先嚐試
kubectl delete -f https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/deploy/longhorn.yaml
並卡在那裡,請按Ctrl C
然後執行kubectl create -f https://raw.githubusercontent.com/longhorn/longhorn/v{{< current-version >}}/uninstall/uninstall.yaml
也可以幫你移除Longhorn
。最後,不要忘記清理剩餘的元件。
故障排除
我從 Rancher UI 中刪除了 Longhorn 應用程式,而不是按照解除安裝程式進行操作
重新部署(相同版本)Longhorn App。按照上面的解除安裝程式進行操作。
CRDs 的問題
如果您的 CRD
例項或 CRD
本身由於某種原因無法刪除,請執行以下命令進行清理。注意:這將清除所有 Longhorn
狀態!
# Delete CRD finalizers, instances and definitions
for crd in $(kubectl get crd -o jsonpath={.items[*].metadata.name} | tr ' ' '\n' | grep longhorn.rancher.io); do
kubectl -n ${NAMESPACE} get $crd -o yaml | sed "s/\- longhorn.rancher.io//g" | kubectl apply -f -
kubectl -n ${NAMESPACE} delete $crd --all
kubectl delete crd/$crd
done
卷可以從 UI 附加/分離,但 Kubernetes Pod/StatefulSet 等不能使用它
檢查卷外掛目錄是否設定正確。除非使用者明確設定,否則會自動檢測到它。注意:FlexVolume
外掛自 Longhorn v0.8.0
起已棄用,不應再使用。
預設情況下,Kubernetes
使用 /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
,如官方文件所述。
一些供應商出於各種原因選擇更改目錄。例如,GKE
使用 /home/kubernetes/flexvolume
代替。
使用者可以通過在主機上執行 ps aux|grep kubelet
並檢查 --volume-plugin-dir
引數來找到正確的目錄。
如果沒有,將使用預設的 /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
。