当前位置: 首页 > news >正文

x86架构-k8s设置openebs的hostpath作为默认存储类的部署记录

文章目录

  • 前言
  • 一、openebs是什么?
  • 二、准备步骤
    • 1.下载yaml文件
    • 2.准备一个新的单点k8s用于测试
    • 2.将openebs-operator.yaml中的镜像修改成使用国内加速源的
  • 三、执行yaml
    • 1.openebs-operator.yaml
    • 2.local-hostpath-pvc.yaml和local-hostpath-pod.yaml
  • 四、关于默认存储路径/var/openebs/local/修改的问题
  • 五、设置默认存储类
  • 总结


前言

x86架构上,k8s设置openebs的hostpath作为默认存储类的部署记录
甲方的一个环境,需要将k8s集群缩容由3节点缩小为1节点,因为之前使用的存储方案是rook-ceph,需要找一个替换方案。我就想到了openebs。这里记录一下相关的操作


一、openebs是什么?

OpenEBS turns any storage available to Kubernetes worker nodes into Local or Distributed Kubernetes Persistent Volumes.

官网地址: https://openebs.io/docs/3.3.x/user-guides/installation
在这里插入图片描述
Hostpath地址:https://openebs.io/docs/3.3.x/user-guides/localpv-hostpath

在这里插入图片描述


二、准备步骤

1.下载yaml文件

mkdir -p /data/openebs/
cd /data/openebs/
wget https://openebs.github.io/charts/openebs-operator.yaml
wget https://openebs.github.io/charts/examples/local-hostpath/local-hostpath-pod.yaml
wget https://openebs.github.io/charts/examples/local-hostpath/local-hostpath-pvc.yaml

2.准备一个新的单点k8s用于测试

kubectl get pod -A 
NAMESPACE              NAME                                       READY   STATUS    RESTARTS   AGE
kube-system            calico-kube-controllers-676c86494f-jwfv5   1/1     Running   0          38m
kube-system            calico-node-v5vnq                          1/1     Running   0          38m
kube-system            coredns-757cd945b-5767j                    1/1     Running   0          38m
kube-system            coredns-757cd945b-k6rvk                    1/1     Running   0          38m
kube-system            kube-apiserver-clamav                      1/1     Running   0          38m
kube-system            kube-controller-manager-clamav             1/1     Running   0          38m
kube-system            kube-proxy-d8fq6                           1/1     Running   0          38m
kube-system            kube-scheduler-clamav                      1/1     Running   0          38m
kube-system            nodelocaldns-5wmhs                         1/1     Running   0          38m
kubernetes-dashboard   dashboard-metrics-scraper-9966c679-d877s   1/1     Running   0          36m
kubernetes-dashboard   kubernetes-dashboard-574df6df5f-2r89r      1/1     Running   0          36m

2.将openebs-operator.yaml中的镜像修改成使用国内加速源的

我用的是dockerpull.cn的国内源,一共涉及到下列5个镜像

openebs/node-disk-manager:2.1.0
openebs/node-disk-operator:2.1.0
openebs/node-disk-exporter:2.1.0
openebs/provisioner-localpv:3.4.0
openebs/linux-utils:3.5.0

pull 镜像

docker pull dockerpull.cn/openebs/node-disk-manager:2.1.0
docker pull dockerpull.cn/openebs/node-disk-operator:2.1.0
docker pull dockerpull.cn/openebs/node-disk-exporter:2.1.0
docker pull dockerpull.cn/openebs/provisioner-localpv:3.4.0
docker pull dockerpull.cn/openebs/linux-utils:3.5.0

替换openebs-operator.yaml中的镜像
这里使用的perl命令,没有使用sed命令,左斜杠转义太烦人,不如用#来当分隔符

perl -pi -e  's#openebs/node-disk-manager:2.1.0#dockerpull.cn/openebs/node-disk-manager:2.1.0#g'  openebs-operator.yamlperl -pi -e  's#openebs/node-disk-operator:2.1.0#dockerpull.cn/openebs/node-disk-operator:2.1.0#g'  openebs-operator.yamlperl -pi -e  's#openebs/node-disk-exporter:2.1.0#dockerpull.cn/openebs/node-disk-exporter:2.1.0#g'  openebs-operator.yamlperl -pi -e  's#openebs/provisioner-localpv:3.4.0#dockerpull.cn/openebs/provisioner-localpv:3.4.0#g'  openebs-operator.yamlperl -pi -e  's#openebs/linux-utils:3.5.0#dockerpull.cn/openebs/linux-utils:3.5.0#g'  openebs-operator.yaml

三、执行yaml

1.openebs-operator.yaml

cd /data/openebs/
kubectl create -f openebs-operator.yaml
# 输出
namespace/openebs created
serviceaccount/openebs-maya-operator created
clusterrole.rbac.authorization.k8s.io/openebs-maya-operator created
clusterrolebinding.rbac.authorization.k8s.io/openebs-maya-operator created
customresourcedefinition.apiextensions.k8s.io/blockdevices.openebs.io created
customresourcedefinition.apiextensions.k8s.io/blockdeviceclaims.openebs.io created
configmap/openebs-ndm-config created
daemonset.apps/openebs-ndm created
deployment.apps/openebs-ndm-operator created
deployment.apps/openebs-ndm-cluster-exporter created
service/openebs-ndm-cluster-exporter-service created
daemonset.apps/openebs-ndm-node-exporter created
service/openebs-ndm-node-exporter-service created
deployment.apps/openebs-localpv-provisioner created
storageclass.storage.k8s.io/openebs-hostpath created
storageclass.storage.k8s.io/openebs-device created

等待pod进入运行状态

kubectl get pod -n openebs
# 输出
NAME                                           READY   STATUS    RESTARTS   AGE
openebs-localpv-provisioner-866f75fd74-hhm98   1/1     Running   0          32s
openebs-ndm-cluster-exporter-c9cdc6864-ml9jd   1/1     Running   0          32s
openebs-ndm-node-exporter-5zpl9                1/1     Running   0          32s
openebs-ndm-operator-6d58d6fdf7-wcb22          1/1     Running   0          32s
openebs-ndm-pdcbm                              1/1     Running   0          32s

查看存储类

kubectl get sc -n default
# 输出
NAME               PROVISIONER        RECLAIMPOLICY   VOLUMEBINDINGMODE      ALLOWVOLUMEEXPANSION   AGE
openebs-device     openebs.io/local   Delete          WaitForFirstConsumer   false                  7m14s
openebs-hostpath   openebs.io/local   Delete          WaitForFirstConsumer   false                  7m14s

2.local-hostpath-pvc.yaml和local-hostpath-pod.yaml

docker pull dockerpull.cn/busybox
perl -pi -e  's#busybox#dockerpull.cn/busybox#g'  local-hostpath-pod.yaml
kubectl create -f local-hostpath-pvc.yaml
kubectl create -f local-hostpath-pod.yaml

查看测试的pv和pod

kubectl get pod -n default
# 输出
NAME                       READY   STATUS    RESTARTS   AGE
hello-local-hostpath-pod   1/1     Running   0          19skubectl get pvc -n default
# 输出
NAME                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
local-hostpath-pvc   Bound    pvc-d2d776a1-656e-49e7-bfff-34ebaa26481a   5G         RWO            openebs-hostpath   5m18s

四、关于默认存储路径/var/openebs/local/修改的问题

默认的存储路径是/var/openebs/local/,在生产环境中最好是配置到一个高性能的有保障的目录下。
准备一个专属目录

mkdir -p /hdd_data/openebs_data/

修改存储类配置

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:name: openebs-hostpath
...- name: BasePath#value: "/var/openebs/local/"value: "/hdd_data/openebs_data/"

创建

kubectl create -f openebs-operator.yaml
kubectl create -f local-hostpath-pvc.yaml
kubectl create -f local-hostpath-pod.yaml
kubectl get pvc
# 输出
NAME                 STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS       AGE
local-hostpath-pvc   Bound    pvc-300671fc-34b1-46dd-bc1c-eaa2feeee754   5G         RWO            openebs-hostpath   4m18s

查看卷是否创建到专属目录

ll /hdd_data/openebs_data/
total 0
drwxrwxrwx 2 root root 23 Apr 29 15:59 pvc-300671fc-34b1-46dd-bc1c-eaa2feeee754

五、设置默认存储类

kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'

总结

简单记录一下使用方式,

相关文章:

  • LeetCode每日一题4.29
  • 省科学技术奖申报答辩PPT设计制作美化
  • 信息检索系统的组成部分和基本架构
  • 4月29日日记
  • jenkins slave节点打包报错Failed to create a temp file on
  • AI国学智慧语录视频,条条视频10W+播放量
  • 数据处理方式 之 对数变换 和Box-Cox变换以及对应逆变换【深度学习】
  • Vue2+Vue3学习笔记
  • 什么是Amazon S3
  • 农村供水智能化远程监控解决方案
  • php学习笔记(全面且适合新手)
  • 接入层架构演变
  • Android ProcessState init
  • 初中九年级学生体测准考证照片采集软件使用说明
  • Keras模型保存、加载介绍
  • JavaScript函数声明大比拼
  • 文献阅读(三)基于干旱强度和恢复时间的生态系统恢复力评估|《Agricultural and Forest Meteorology》
  • 极狐GitLab 如何使用文件导出迁移项目和群组?
  • 前端设置三行文本省略号,失效为什么?
  • 二叉树知识点
  • 广东省副省长刘红兵跨省调任湖南省委常委、宣传部长
  • 香港警务处高级助理处长叶云龙升任警务处副处长(行动)
  • 我的科学观|张峥:AI快速迭代,我们更需学会如何与科技共处
  • 四川苍溪县教育局通报“工作人员辱骂举报学生”:停职检查
  • 楼下电瓶车起火老夫妻逃生时被烧伤,消防解析躲火避烟注意事项
  • 葛兰西的三位一体:重提并复兴欧洲共产主义的平民圣人