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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM