10-3 共享存储-----操作-----GlusterFS&Heketi共享存储

共享存储

9-persistent-volume

kubeadm安装的最新k8s 1.16.2版本,由1master+2node组成,网络插件选用的是flannel,默认kubeadm安装的k8s,会给master打上污点,本文为了实现gfs集群功能,先手动去掉了污点。 本文的glusterfs卷模式为复制卷模式。 另外,glusterfskubernetes集群中需要以特权运行,需要在kube-apiserver中添加–allow-privileged=true参数以开启此功能,默认此版本的kubeadm已开启。

[root@k8s-master-01 ~]# kubectl describe nodes k8s-master-01 |grep Taint
Taints:             node-role.kubernetes.io/master:NoSchedule  
[root@k8s-master-01 ~]# kubectl taint node k8s-master-01 node-role.kubernetes.io/master-
node/k8s-master-01 untainted
[root@k8s-master-01 ~]# kubectl describe nodes k8s-master-01 |grep Taint

项目 9-persistent-vloume

一、3台安装GFS

# 安装即可。 不可以启动。否则和docker启动有冲突
yum install centos-release-gluster -y
yum install -y glusterfs glusterfs-server glusterfs-fuse glusterfs-rdma

yum install -y heketi heketi-client

二、查看依赖

ps -ef|grep apiserver|grep allow-privileged=true  #allow-privileged
cat /usr/lib/systemd/system/kubelet.service|grep allow
# 没有则,增加--allow-privileged=true
# vim /usr/lib/systemd/system/kubelet.service # ExecStart=/usr/bin/kubelet --allow-privileged=true

#systemctl daemon-reload
#systemctl restart kubelet
#systemctl stop kubepods.slice   #起动不起来执行

 

gfs集群部署

# w1 w2 w3 都打标签
kubectl label node w1 storagenode=glusterfs
kubectl get nodes --show-labels 
# 创建集群 
kubectl apply -f glusterfs-daemonset.yaml
# 查看部署位置 kubectl get pods -o wide

 

heketi服务部署。 功能:管理和维护 glusterfs使用  格式化磁盘

# 创建service-account,ClusterRole。创建授权,安全  
kubectl apply -f heketi-security.yaml 
# 查看绑定ClusterRoleBinding详细信息 
kubectl get ClusterRoleBinding -A
kubectl get ClusterRoleBinding heketi-clusterrolebinding -o yaml

# 部署 
kubectl apply -f heketi-deployment.yaml 
# 查看部署结果,查看部署位置。
kubectl get pods -o wide 

配置heketi

每台机器上添加一块磁盘。 /dev/vdb  不走任何操作,添加即可。

# 查看heketi容器
docker ps|grep heketi

#登录容器
docker exec -it 7d4b3a9bb457 bash
# 设置环境变量,本机的8080
export HEKETI_CLI_SERVER=http://localhost:8080

# 编辑toplogy.json 并复制到容器中。配置gfs信息。
vi topology.json   # 把内容拷贝到容器中

# 初始化
# heketi-cli topology load --json topology.json   # 执行报错。# 增加 user和 secret
heketi-cli -s $HEKETI_CLI_SERVER --user admin --secret 'My Secret' topology load --json=topology.json 

# 查看集群信息 
heketi-cli -s $HEKETI_CLI_SERVER --user admin --secret 'My Secret' topology info

gluster信息查看

# 查看端口
netstat -ntlp|grep glusterd 
docker ps -a|grep glusterfs docker
exec -it 987e bash # 查看gluster集群信息 gluster peer status
systemctl status glusterd

 

 storage部署创建第二层 

# 查看secrets name 和namespace
kubectl get secrets -A
kubectl apply -f glusterfs-storage-class.yaml 
# 查看部署结果详细信息
kubectl get StorageClass -o yaml
kubectl describe StorageClass 

 

pvc部署创建最上面一层

kubectl apply -f glusterfs-pvc.yaml 
# 查看部署详细信息
kubectl describe pvc glusterfs-pvc 
kubectl get sc

# 查看pvcBound状态,查看pv。 系统生成的
kubectl get pvc,pv 
# 查看pvc详细信息 
kubectl get pvc glusterfs-pvc -o yaml

 

pod 使用pvc

# pod部署使用 pvc目录挂载
kubectl apply -f web-deploy.yaml 
kubectl get pods -o wide

# 进入 web项目容器容器,验证
docker exec -it 987e sh
cd /tt-data
echo "hello aaa" a

# 去另个副本查看。 共享存储同步了

pod使用 gfs+heketi 共享存储搭建完成。 

pv pvc的生命周期

STATUS: Bound      绑定

RECLAIM:Delete    回收机制

把deploy删掉pvc处于什么状态,还能给其他pod继续使用吗?

pvc删掉pv处于什么状态?

参考回收策略测试。

end...

posted @ 2021-04-09 16:07  王竹笙  阅读(202)  评论(0编辑  收藏  举报