当前位置: 首页 > 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"}}}'

总结

简单记录一下使用方式,

http://www.xdnf.cn/news/212527.html

相关文章:

  • 51单片机快速入门之 SPI通信 2025年4月29日09:26:32
  • 如何知道Ubuntu的端口是否被占用,被那个进程占用?如何终止进程
  • PH热榜 | 2025-04-29
  • 通信原理第七版与第六版的区别附pdf
  • Javascript 中作用域的理解?
  • MCP Java SDK 介绍与使用指南
  • Docker的简单使用(不全)
  • Java中的内部类?
  • 在Anolis OS 8上部署Elasticsearch 7.16.1与JDK 11的完整指南
  • C++之AVL树
  • Android Studio for Platform(ASFP)真机调试
  • Qt5与现代OpenGL学习(四)X轴方向旋转60度
  • 《Vue3学习手记7》
  • RVO2(C#版)源码分析
  • 什么是ICSP编程
  • [展示]集成式深度学习对音频降噪的基准测试BenchMark
  • 【图片识别改名】批量读取图片区域文字识别后批量改名,基于Python和腾讯云的实现方案
  • [随笔] 升级uniapp旧项目的vue、pinia、vite、dcloudio依赖包等
  • BG开发者日志429:故事模式的思路
  • Mac 创建QT按钮以及一些操作
  • iVX 可视化调试:重塑 AI 编程规则的变革
  • 【11408学习记录】考研英语语法核心:倒装句考点全解+真题演练
  • 如何用vivado导出pin delay
  • 第33周JavaSpringCloud微服务 多人协作下的调试
  • CSRF(cross-site request forgery)跨域请求访问
  • Reverse-WP记录9
  • 51la统计坏了吗?用悟空统计保障运营决策安全详解
  • 斯坦福课程 MSE 318/CME 338: Large-Scale Numerical Optimization
  • Linux权限拓展
  • Headers池技术在Python爬虫反反爬中的应用