k8s本地存储使用方式

第一种方式:

部署 openebs
1、让 master 参与调度,去掉污点
kubectl taint nodes master node-role.kubernetes.io/master:NoSchedule-

2、创建一个 namespace
kubectl create ns openebs

3、安装 openebs
kubectl apply -f https://openebs.github.io/charts/openebs-operator-1.10.0.yaml

或者使用 Helm
helm install --namespace openebs --name openebs stable/openebs --version 1.10.0

4、将 openebs-hostpath 设置为 默认的 StorageClass
kubectl patch storageclass openebs-hostpath -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
kubectl get sc

使用方式:

修改 storageClass
persistence:
storageClass: openebs-hostpath

第二种方式:

部署longhorn存储
longhorn推荐单独挂盘作为存储使用,这里作为测试直接使用本地存储目录/data/longhorn,默认为/var/lib/longhorn。
注意,kubesphere有几个组件申请的pv大小为20G,确保节点空间充足,否则可能出现pv能够绑定成功但没有满足条件的节点可调度的情况。如果仅仅测试环境,可以提前修改cluster-configuration.yaml缩减pv大小。


安装具有3数据副本的longhorn至少需要3个节点,这里去除master节点污点使其可调度pod:
kubectl taint nodes --all node-role.kubernetes.io/master-

1.k8s-master1安装helm
version=v3.3.1
curl -LO https://repo.huaweicloud.com/helm/${version}/helm-${version}-linux-amd64.tar.gz
tar -zxvf helm-${version}-linux-amd64.tar.gz
mv linux-amd64/helm /usr/local/bin/helm && rm -rf linux-amd64


helm脚本安装:
Helm现在具有一个安装程序脚本,该脚本将自动获取最新版本的Helm并将[其本地安装]
可以获取该脚本,然后在本地执行它。它有充分的文档记录,因此您可以在运行它之前通读它并了解它在做什么。
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh

#查看配置信息
[root@i-pcwovafu bin]# helm env
HELM_NAMESPACE="default"
HELM_KUBECONTEXT=""
HELM_BIN="helm"
HELM_DEBUG="false"
HELM_PLUGINS="/root/.local/share/helm/plugins"
HELM_REGISTRY_CONFIG="/root/.config/helm/registry.json"
HELM_REPOSITORY_CACHE="/root/.cache/helm/repository"
HELM_REPOSITORY_CONFIG="/root/.config/helm/repositories.yaml"

#添加公用的仓库
helm repo add stable http://mirror.azure.cn/kubernetes/charts
helm repo add aliyun https://kubernetes.oss-cn-hangzhou.aliyuncs.com/charts
helm repo update

#指定对应的k8s集群
这一步非常关键,它是helm与k8s通讯的保证,这一步就是把k8s环境变量KUBECONFIG进行配置
注:v3版本不再需要Tiller,而是通过ApiServer与k8s交互,可以设置环境变量KUBECONFIG来指定存有ApiServre的地址与token的配置文件地址,默认为~/.kube/config
export KUBECONFIG=/root/.kube/config #可以写到/etc/profile里


2.所有节点安装longhorn依赖
yum install -y iscsi-initiator-utils
systemctl enable --now iscsid


3.添加longhorn chart,如果网络较差可以longhorn github release下载chart源码
helm repo add longhorn https://charts.longhorn.io
helm repo update


4.部署longhorn,支持离线部署,需要提前推送镜像到私有仓库longhornio下
kubectl create namespace longhorn-system

helm install longhorn
--namespace longhorn-system
--set defaultSettings.defaultDataPath="/data/longhorn/"
--set defaultSettings.defaultReplicaCount=3
--set service.ui.type=NodePort
--set service.ui.nodePort=30890
#--set privateRegistry.registryUrl=10.39.140.196:8081
longhorn/longhorn


5.确认longhorn运行正常
[root@jenkins longhorn]# kubectl -n longhorn-system get pods

6.确认默认的storageclass已就绪
# kubectl get sc
NAME          PROVISIONER    RECLAIMPOLICY    VOLUMEBINDINGMODE    ALLOWVOLUMEEXPANSION      AGE
longhorn (default)   driver.longhorn.io   Delete          Immediate                                    true                                              14h

原文地址:https://www.cnblogs.com/xiaoyaojinzhazhadehangcheng/p/14119665.html