亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

Kubernetes是云計算發展演進的一次徹底革命性的突破。如今,已經有越來越多的企業逐漸接受并將自己的核心業務系統遷移到Kubernetes平臺。本期智匯華云,華云數據為大家帶來Kubernetes特性——In-Tree to CSI Volume Migration。

背景

In-tree

kubernetes早期通過in-tree的方式來為容器提供存儲,in-tree可以理解為對接外部存儲的plugin的代碼集成在kubernetes中,在k8s的代碼目錄里面我們可以看到大量的關于外部存儲的plugin集成的代碼k8s.io/pkg/volume。可以通過in-tree的代碼與這些外部存儲進行對接,這些plugin提供了volume的create/delete/attach/detach/mount/unmount/recyle以及卷監控等volume的管理。In-tree支持20+種volume plugin,例如比較常用的iscsi/nfs/fc/ceph/azure/aws/gce/glusterfs/openstack等等。

CSI

In-tree的方式對于新增一種volume plugin變得很困難,廠商期望在kubernetes中新支持一種volume plugins需要考慮kubernetes的發布過程,另外第三方存儲的代碼在kubernetes倉庫中對于kubernetes穩定性以及測試和維護帶來了挑戰。所以kubernetes社區提出了CSI規范用于更好的支持其他廠商的外部存儲。

CSI定義了一套接口規范,各個外部廠商可以根據自身存儲開發自身的CSIDriver插件,來完成對于整個卷生命周期的管理。引入對 CSI 驅動的支持,使得 Kubernetes 和存儲后端技術之間的集成工作更易建立和維護,集群管理員可以只選擇集群需要的存儲驅動。

CSI Volume Migration

CSI Volume Migration特性是支持in-tree定義的PVC&PV資源對象對應的功能可以由外部的對應的CSI插件來替代完成,例如之前集群中使用provision=kubernetes.io/cinder創建的pvc以及pv對象卷的生命周期管理可以由Cinder CSI Plugin來完成,而不是之前in-tree來完成。

為什么需要引入CSI Volume Migration

In-tree方式過渡到csi方式對接外部存儲:csi driver越來越普遍以及成熟,可以替代in-tree的方式,對于存儲插件的開發者,減少維護in-tree方式的插件,并最終將這些插件從kubernetes倉庫的代碼中移除。

平滑的過渡:遷移到CSI driver的方式,而不破壞與現有存儲 API 類型的 API 兼容性。由特性來實現將in-tree存儲 API 翻譯成等效的 CSI API,將操作委托給一個替換的 CSI 驅動來完成。之前創建的in-tree的PV/PVC對象可以繼續工作,只是實際的工作由in-tree的邏輯實現替代成CSI來驅動完成。未來計劃將在 Kubernetes v1.26 和 v1.27 之前移除云提供商提供的in-tree存儲插件的代碼。

//CSI migrate各個plugin的最新的進展

怎么使用CSI Volume Migration特性

打開CSIMigration以及CSIMigration{provider}的特性開發(1.17),{provider}是in-tree的cloud provider storage type.

打開InTreePlugin{provider}Unregister,該feature是可注銷參數名稱中 {provider} 部分所指定的in-tree存儲插件。InTreePlugin{provider}Unregister 是一種特性,可以獨立于 CSI 遷移功能來啟用或禁用。當啟用此種特性時,組件將不會把相應的in-tree存儲插件注冊到支持的列表中。如果集群操作員只啟用了這種參數,終端用戶將在使用該插件的 PVC時會遇到錯誤,提示其找不到插件。如果集群操作員不想支持過時的in-tree存儲 API,只支持 CSI,那么他們可能希望啟用這種特性。在k8s 1.21之前這個feature名稱是CSIMigration{provider}Complete,在v1.21版本棄用了CSIMigration{provider}Complete,而是改用InTreePlugin{vendor}Unregister,功能上二者是一致的。

安裝對應的csi driver

以openstack-cinder in-tree為例演示

在kubernetes 1.22版本上需要打開如下三個特性

K8s.io/Kubernetes/pkg/features/kube_features.go

// Enables the in-tree storage to CSI Plugin migration feature.

CSIMigration featuregate.Feature = "CSIMigration"

// Enables the OpenStack Cinder in-tree driver to OpenStack Cinder CSI Driver migration feature.

CSIMigrationOpenStack featuregate.Feature = "CSIMigrationOpenStack"

// Disables the OpenStack Cinder in-tree driver.

InTreePluginOpenStackUnregister featuregate.Feature = "InTreePluginOpenStackUnregister"

安裝cinder-csi-plugin

查看csinodes,存在annotations

之后創建一個in-tree的pvc,查看cinder-csi-plugin日志,是否是由cinder-csi來完成

apiVersion: storage.k8s.io/v1

kind: StorageClass

metadata:

name: csi-sc-cinderplugin

provisioner: kubernetes.io/cinder

---

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: csi-pvc-cinderplugin

spec:

accessModes:

- ReadWriteOnce

resources:

requests:

storage: 1Gi

storageClassName: csi-sc-cinderplugin

---

apiVersion: v1

kind: Pod

metadata:

name: nginx

spec:

nodeSelector:

kubernetes.io/hostname: node4

containers:

- image: nginx

imagePullPolicy: IfNotPresent

name: nginx

ports:

- containerPort: 80

protocol: TCP

volumeMounts:

- mountPath: /var/lib/www/html

name: csi-data-cinderplugin

volumes:

- name: csi-data-cinderplugin

persistentVolumeClaim:

claimName: csi-pvc-cinderplugin

readOnly: false

如何實現CSI Volume Migration

kubernetes 1.22代碼分析主要是針對每個in-tree的插件實現type InTreePlugin interface k8s.io/Kubernetes/staging/src/k8s.io/csi-translation-lib/plugins/in_tree_volume.go

// InTreePlugin handles translations between CSI and in-tree sources in a PV

type InTreePlugin interface {

// TranslateInTreeStorageClassToCSI takes in-tree volume options

// and translates them to a volume options consumable by CSI plugin

TranslateInTreeStorageClassToCSI(sc *storage.StorageClass) (*storage.StorageClass, error)

// TranslateInTreeInlineVolumeToCSI takes a inline volume and will translate

// the in-tree inline volume source to a CSIPersistentVolumeSource

// A PV object containing the CSIPersistentVolumeSource in it's spec is returned

// podNamespace is only needed for azurefile to fetch secret namespace, no need to be set for other plugins.

TranslateInTreeInlineVolumeToCSI(volume *v1.Volume, podNamespace string) (*v1.PersistentVolume, error)

// TranslateInTreePVToCSI takes a persistent volume and will translate

// the in-tree pv source to a CSI Source. The input persistent volume can be modified

TranslateInTreePVToCSI(pv *v1.PersistentVolume) (*v1.PersistentVolume, error)

// TranslateCSIPVToInTree takes a PV with a CSI PersistentVolume Source and will translate

// it to a in-tree Persistent Volume Source for the in-tree volume

// by the `Driver` field in the CSI Source. The input PV object can be modified

TranslateCSIPVToInTree(pv *v1.PersistentVolume) (*v1.PersistentVolume, error)

// CanSupport tests whether the plugin supports a given persistent volume

// specification from the API.

CanSupport(pv *v1.PersistentVolume) bool

// CanSupportInline tests whether the plugin supports a given inline volume

// specification from the API.

CanSupportInline(vol *v1.Volume) bool

// GetInTreePluginName returns the in-tree plugin name this migrates

GetInTreePluginName() string

// GetCSIPluginName returns the name of the CSI plugin that supersedes the in-tree plugin

GetCSIPluginName() string

// RepairVolumeHandle generates a correct volume handle based on node ID information.

RepairVolumeHandle(volumeHandle, nodeID string) (string, error)

}

之后在原有的卷調度以及卷生命周期管理的時候,通過各個plugin提供的TranslateInTreexxx函數轉換成CSI對象,按照CSI對象的操作流程進行操作。如果是支持遷移的卷類型,則原來的流程將會被忽略。下面是volume調度策略node-limit來看CSI mirgrate特性是如何讓用戶無感知的遷移的

Nodevolumelimits調度策略主要是限制單個node上相同類型的卷的數量不能超過一定的數量,可以在CSINode里面定義數量的大小。Nodevolumelimits-plugin代碼的位置在k8s.io/Kubernetes/pkg/scheduler/framework/plugins/nodevolumelimits/csi.go

Filter()

filterAttachableVolumes

pl.getCSIDriverInfo(csiNode, pvc)中

csiSource := pv.Spec.PersistentVolumeSource.CSI

if csiSource == nil {

// We make a fast path for non-CSI volumes that aren't migratable

if !pl.translator.IsPVMigratable(pv) {

return "", ""

}

pluginName, err := pl.translator.GetInTreePluginNameFromSpec(pv, nil)

if err != nil {

klog.V(5).InfoS("Unable to look up plugin name from PV spec", "err", err)

return "", ""

}

if !isCSIMigrationOn(csiNode, pluginName) {

klog.V(5).InfoS("CSI Migration of plugin is not enabled", "plugin", pluginName)

return "", ""

}

csiPV, err := pl.translator.TranslateInTreePVToCSI(pv)

if err != nil {

klog.V(5).InfoS("Unable to translate in-tree volume to CSI", "err", err)

return "", ""

}

if csiPV.Spec.PersistentVolumeSource.CSI == nil {

klog.V(5).InfoS("Unable to get a valid volume source for translated PV", "PV", pvName)

return "", ""

}

csiSource = csiPV.Spec.PersistentVolumeSource.CSI

}

獲取pvc in-intree對應的csi對象。之后Nodevolumelimits-plugin中去判斷node所在的in-tree或者csi對象總的volume的數量有沒有超過limit的限制。

總結

CSIMigration可以使得in-tree的pvc&pv可以由csi來管理,但是卷的管理能力只僅限于in-tree本身具備的一些能力,csi中具有的一些高級的功能,例如snapshot等,是沒有辦法針對in-tree的pvc&pv來進行操作的。

截止k8s 1.24 release,CSIMigration特性處于beta狀態,目前支持migration的in-tree插件有GCE/AWS/AzureDisk/AzureFile/vSphere/Openstack/RBD/Portworx,可以看出將所有in-tree的代碼從kubernetes代碼中剝離出來仍然還有很多工作要做,并且CSIMigration特性引入了很多過渡的代碼。同時思考是否可以通過直接convert將in-tree的pvc、pv對象直接轉化成csi規范的對象,是不是也是一種更好的思路。

分享到:
標簽:特性 Kubernetes 華云 Tree Migration Volume CSI
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定