使用 MicroK8s 和 OpenEBS 扩展 Kubernetes 存储

2022-05-14 09:51:53 浏览数 (1)

OpenEBS 由 CloudByte 研发,这是一家专业做容器化存储的公司,OpenEBS 是其一款开源产品,CloudByte 将其在企业级容器存储的经验付诸到该项目中。这个项目的愿景也很简单,就是让需要持久化存储的工作负载中的存储服务能够直接集成在环境中,存储服务可以自动管理,将存储的细节隐藏起来,就像存储系统是另一套基础架构一样。

在 MicroK8s 上,通过启用OpenEBS 附加组件,以支持集群存储。OpenEBS 使用 iSCSI 进行集群,这在单个主机上不是必需的,但必须先启用该服务,然后才能启用 OpenEBS: sudo systemctl enable iscsid.service

现在您可以启用 OpenEBS:

microk8s enable openebs

最新的1.24 还有 https://ubuntu.com/blog/kubernetes-storage-microk8s-mayastor

--------------------------------------------------------------------------------------------------------------------------------

ubuntu@VM-1-2-ubuntu:~$ sudo systemctl enable iscsid.service

Synchronizing state of iscsid.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable iscsid

ubuntu@VM-1-2-ubuntu:~$ helm repo update

W0513 09:51:37.708144   62648 loader.go:221] Config not found: /etc/kubernetes/admin.conf

Hang tight while we grab the latest from your chart repositories...

...Successfully got an update from the "openebs" chart repository

Update Complete. ?Happy Helming!?

ubuntu@VM-1-2-ubuntu:~$ microk8s enable openebs

Addon dns is already enabled.

Addon helm3 is already enabled.

WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /var/snap/microk8s/3052/credentials/client.config

"openebs" already exists with the same configuration, skipping

WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /var/snap/microk8s/3052/credentials/client.config

Hang tight while we grab the latest from your chart repositories...

...Successfully got an update from the "openebs" chart repository

Update Complete. ?Happy Helming!?

WARNING: Kubernetes configuration file is group-readable. This is insecure. Location: /var/snap/microk8s/3052/credentials/client.config

NAME: openebs

LAST DEPLOYED: Fri May 13 09:51:58 2022

NAMESPACE: openebs

STATUS: deployed

REVISION: 1

TEST SUITE: None

NOTES:

Successfully installed OpenEBS.

Check the status by running: kubectl get pods -n openebs

The default values will install NDM and enable OpenEBS hostpath and device

storage engines along with their default StorageClasses. Use `kubectl get sc`

to see the list of installed OpenEBS StorageClasses.

**Note**: If you are upgrading from the older helm chart that was using cStor

and Jiva (non-csi) volumes, you will have to run the following command to include

the older provisioners:

helm upgrade openebs openebs/openebs

        --namespace openebs

        --set legacy.enabled=true

        --reuse-values

For other engines, you will need to perform a few more additional steps to

enable the engine, configure the engines (e.g. creating pools) and create

StorageClasses.

For example, cStor can be enabled using commands like:

helm upgrade openebs openebs/openebs

        --namespace openebs

        --set cstor.enabled=true

        --reuse-values

For more information,

- view the online documentation at https://openebs.io/ or

- connect with an active community on Kubernetes slack #openebs channel.

OpenEBS is installed

-----------------------

When using OpenEBS with a single node MicroK8s, it is recommended to use the openebs-hostpath StorageClass

An example of creating a PersistentVolumeClaim utilizing the openebs-hostpath StorageClass

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

  name: local-hostpath-pvc

spec:

  storageClassName: openebs-hostpath

  accessModes:

    - ReadWriteOnce

  resources:

    requests:

      storage: 5G

-----------------------

If you are planning to use OpenEBS with multi nodes, you can use the openebs-jiva-csi-default StorageClass.

An example of creating a PersistentVolumeClaim utilizing the openebs-jiva-csi-default StorageClass

kind: PersistentVolumeClaim

apiVersion: v1

metadata:

  name: jiva-volume-claim

spec:

  storageClassName: openebs-jiva-csi-default

  accessModes:

    - ReadWriteOnce

  resources:

    requests:

      storage: 5G

ubuntu@VM-1-2-ubuntu:~$ sudo microk8s kubectl get sc

NAME                       PROVISIONER           RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE

openebs-jiva-csi-default   jiva.csi.openebs.io   Delete          Immediate              true                   15m

openebs-device             openebs.io/local      Delete          WaitForFirstConsumer   false                  15m

openebs-hostpath           openebs.io/local      Delete          WaitForFirstConsumer   false                  15m

默认的OpenEBS回收策略与K8所使用的相同。“删除”是动态配置的PersistentVolume的默认回收策略。它们在某种意义上是相关的,如果一个人删除了相应的PersistentVolumeClaim,则动态配置的卷将被自动删除。对于cStor卷,则数据随之删除。对于jiva(0.8.0版及更高版本),清理作业将执行数据删除工作。

参考文章:

  • https://weiliang-ms.github.io/wl-awesome/2.容器/k8s/storage/OpenEBS.html
  • https://zero-to-jupyterhub.readthedocs.io/en/latest/kubernetes/other-infrastructure/step-zero-microk8s.html
  • https://gist.github.com/tdewin/46d0c5e81481fe91f5c84184cb21e949

0 人点赞