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

文章目录


前言

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文件

shell 复制代码
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用于测试

shell 复制代码
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个镜像

shell 复制代码
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 镜像

shell 复制代码
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命令,左斜杠转义太烦人,不如用#来当分隔符

shell 复制代码
perl -pi -e  's#openebs/node-disk-manager:2.1.0#dockerpull.cn/openebs/node-disk-manager:2.1.0#g'  openebs-operator.yaml

perl -pi -e  's#openebs/node-disk-operator:2.1.0#dockerpull.cn/openebs/node-disk-operator:2.1.0#g'  openebs-operator.yaml

perl -pi -e  's#openebs/node-disk-exporter:2.1.0#dockerpull.cn/openebs/node-disk-exporter:2.1.0#g'  openebs-operator.yaml

perl -pi -e  's#openebs/provisioner-localpv:3.4.0#dockerpull.cn/openebs/provisioner-localpv:3.4.0#g'  openebs-operator.yaml

perl -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

shell 复制代码
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进入运行状态

shell 复制代码
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

查看存储类

shell 复制代码
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

shell 复制代码
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

shell 复制代码
kubectl get pod -n default
# 输出
NAME                       READY   STATUS    RESTARTS   AGE
hello-local-hostpath-pod   1/1     Running   0          19s

kubectl 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/,在生产环境中最好是配置到一个高性能的有保障的目录下。

准备一个专属目录

shell 复制代码
mkdir -p /hdd_data/openebs_data/

修改存储类配置

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

创建

shell 复制代码
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

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

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

五、设置默认存储类

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

总结

简单记录一下使用方式,

相关推荐
风屿Wind1 天前
从此,K8S入门0门槛!
云原生·容器·kubernetes
一个向上的运维者1 天前
Kubernetes(k8s)的API Server 组件原理与结合生产实战教程
云原生·容器·kubernetes
海鸥812 天前
在K8S迁移节点kubelet数据存储目录
java·kubernetes·kubelet
阿湯哥2 天前
Kubernetes 核心组件架构详解
容器·架构·kubernetes
东风微鸣2 天前
运维员工离职交接清单
docker·云原生·kubernetes·可观察性
元气满满的热码式2 天前
云原生 | K8S中数据存储之StorageClass
云原生·容器·kubernetes
终端行者2 天前
kubernetes常用命令 k8s指令大全
linux·容器·kubernetes
z35026037062 天前
K8S学习笔记01
笔记·学习·kubernetes
小马爱打代码2 天前
K8S - 从零构建 Docker 镜像与容器
docker·容器·kubernetes